42 lines
948 B
C++
42 lines
948 B
C++
#include <bits/stdc++.h>
|
||
using namespace std;
|
||
// vector<int> a = {2, 2, 2, 2};
|
||
// vector<int> a = {4, 2};
|
||
// vector<int> a = {5, 4, 2};
|
||
vector<int> a = {5, 4, 2, 7, 3, 4, 6, 7};
|
||
// 2 4 4 4 5 6 7 7
|
||
// 2 3 3 3 4 5 6 6
|
||
// 2 2 2 2 3 4 5 5
|
||
// 2 1 1 1 2 3 4 4
|
||
|
||
// 最小mi1,次小 mi2
|
||
// mi2-mi1+1
|
||
|
||
int n = a.size();
|
||
int res;
|
||
|
||
void print() {
|
||
// 输出
|
||
for (int i = 0; i < n; i++) cout << a[i] << " ";
|
||
cout << endl;
|
||
}
|
||
|
||
int main() {
|
||
while (true) {
|
||
// 由小到大排序
|
||
sort(a.begin(), a.end());
|
||
// 贪心策略:让参加考试数目少的去监考
|
||
print();
|
||
// 最小a[0]
|
||
if (a[0] == 0) {
|
||
res += a[n - 1];
|
||
break;
|
||
}
|
||
// 让最少的去监考,让其它人去考试
|
||
for (int i = 1; i < n; i++) a[i]--;
|
||
// 多了一次考试
|
||
res++;
|
||
}
|
||
cout << "res=" << res << endl;
|
||
return 0;
|
||
} |