|
|
|
@ -3,7 +3,6 @@ using namespace std;
|
|
|
|
|
/*
|
|
|
|
|
14
|
|
|
|
|
3 2 2 3 2 2 3 2 2 2 3 3 3 3
|
|
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
const int N = 110;
|
|
|
|
|
int n;
|
|
|
|
@ -16,7 +15,7 @@ struct Node {
|
|
|
|
|
int c;
|
|
|
|
|
int count;
|
|
|
|
|
int st, ed;
|
|
|
|
|
bool const operator<(const &Node t) {
|
|
|
|
|
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;
|
|
|
|
@ -30,24 +29,28 @@ Node find() {
|
|
|
|
|
for (int i = 1; i <= n; i++)
|
|
|
|
|
if (!st[a[i]]) b[a[i]]++; // 个数
|
|
|
|
|
|
|
|
|
|
for (int i = 1; i <= 9; 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;
|
|
|
|
|
}
|
|
|
|
|
q.push_back({i, b[i], start, end});
|
|
|
|
|
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;
|
|
|
|
|
}
|
|
|
|
|
// 记录数字,个数,开始,结束
|
|
|
|
|
q.push_back({i, b[i], start, end});
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
// 按结构体自定义的顺序进行排序
|
|
|
|
|
sort(q.begin(), q.end());
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return q[0];
|
|
|
|
|
// 我们只关心第一个,也就是数量最多的那个
|
|
|
|
|
if (q.size()) return q[0];
|
|
|
|
|
return {0, 0, 0, 0};
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
int main() {
|
|
|
|
@ -56,6 +59,8 @@ int main() {
|
|
|
|
|
for (res = 0;; res++) {
|
|
|
|
|
// 找出没有记录过的数字,并且,它的数量最多,如果存在数量一样多的多个数字,就比较谁的区间大,大的优先,如果无法比较谁的区间大,就数小的优先
|
|
|
|
|
Node x = find();
|
|
|
|
|
// 将x这个数字标识为已处理
|
|
|
|
|
st[x.c] = 1;
|
|
|
|
|
if (x.count == 0) break;
|
|
|
|
|
}
|
|
|
|
|
cout << res << endl;
|
|
|
|
|