|
|
@ -1,68 +1,35 @@
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
#include <bits/stdc++.h>
|
|
|
|
using namespace std;
|
|
|
|
using namespace std;
|
|
|
|
/*
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
|
3 2 2 3 2 2 3 2 2 2 3 3 3 3
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
const int N = 110;
|
|
|
|
const int N = 110;
|
|
|
|
int n;
|
|
|
|
|
|
|
|
int a[N];
|
|
|
|
int a[N];
|
|
|
|
int res; // 执行次数
|
|
|
|
int st[10];
|
|
|
|
int st[10]; // 哪些数字使用过了
|
|
|
|
|
|
|
|
int b[10];
|
|
|
|
|
|
|
|
// 结构体
|
|
|
|
|
|
|
|
struct Node {
|
|
|
|
struct Node {
|
|
|
|
int c;
|
|
|
|
|
|
|
|
int count;
|
|
|
|
|
|
|
|
int st, ed;
|
|
|
|
int st, ed;
|
|
|
|
const bool operator<(const Node &t) const {
|
|
|
|
|
|
|
|
if (count != t.count) return count > t.count;
|
|
|
|
|
|
|
|
if (st < t.st && ed > t.ed) return false;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
};
|
|
|
|
};
|
|
|
|
|
|
|
|
vector<Node> q;
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
|
1 2 3 3 2
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
|
|
|
int n;
|
|
|
|
|
|
|
|
cin >> n;
|
|
|
|
|
|
|
|
for (int i = 1; i <= n; i++) cin >> a[i]; // 密码数组
|
|
|
|
|
|
|
|
|
|
|
|
// 找出未处理的数字中符合条件的那个
|
|
|
|
for (int i = 1; i <= n; i++) {
|
|
|
|
Node find() {
|
|
|
|
if (!st[a[i]]) {
|
|
|
|
memset(b, 0, sizeof b);
|
|
|
|
st[a[i]] = 1;
|
|
|
|
vector<Node> q;
|
|
|
|
for (int j = n; j; j--)
|
|
|
|
for (int i = 1; i <= n; i++)
|
|
|
|
if (a[i] == a[j]) {
|
|
|
|
if (!st[a[i]]) b[a[i]]++; // 个数
|
|
|
|
q.push_back({i, j});
|
|
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= 9; i++) { // 遍历所有数字1~9
|
|
|
|
|
|
|
|
if (b[i] > 0) { // 如果是真实存在的,有效的数字i
|
|
|
|
|
|
|
|
int start, end; // 找出这个数字的起始位置与结束位置
|
|
|
|
|
|
|
|
for (int j = 1; j <= n; j++) // 找开头
|
|
|
|
|
|
|
|
if (a[j] == i) {
|
|
|
|
|
|
|
|
start = j;
|
|
|
|
|
|
|
|
break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
for (int j = n; j >= 1; j--) // 找结尾
|
|
|
|
|
|
|
|
if (a[j] == i) {
|
|
|
|
|
|
|
|
end = j;
|
|
|
|
|
|
|
|
break;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 记录数字,个数,开始,结束
|
|
|
|
|
|
|
|
q.push_back({i, b[i], start, end});
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// 按结构体自定义的顺序进行排序
|
|
|
|
// 从左到右枚举,所以,不再需再进行按左端点排序,现在就是按左端点排序完的
|
|
|
|
sort(q.begin(), q.end());
|
|
|
|
|
|
|
|
// 我们只关心第一个,也就是数量最多的那个
|
|
|
|
for (int i = 0; i < q.size(); i++) cout << q[i].st << " " << q[i].ed << endl;
|
|
|
|
if (q.size()) return q[0];
|
|
|
|
|
|
|
|
return {0, 0, 0, 0};
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
|
|
|
|
cin >> n;
|
|
|
|
|
|
|
|
for (int i = 1; i <= n; i++) cin >> a[i]; // 密码数组
|
|
|
|
|
|
|
|
for (res = 0;; res++) {
|
|
|
|
|
|
|
|
// 找出没有记录过的数字,并且,它的数量最多,如果存在数量一样多的多个数字,就比较谁的区间大,大的优先,如果无法比较谁的区间大,就数小的优先
|
|
|
|
|
|
|
|
Node x = find();
|
|
|
|
|
|
|
|
// 将x这个数字标识为已处理
|
|
|
|
|
|
|
|
st[x.c] = 1;
|
|
|
|
|
|
|
|
if (x.count == 0) break;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
cout << res << endl;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
}
|