Run ID | 作者 | 问题 | 语言 | 测评结果 | 分数 | 时间 | 内存 | 代码长度 | 提交时间 |
---|---|---|---|---|---|---|---|---|---|
108905 | 李树强 | 均分纸牌 | C++ | 解答错误 | 0 | 0 MS | 244 KB | 611 | 2023-11-04 11:33:20 |
#include<iostream> using namespace std; const int inf = 1e9; int a[110], b[110], sum = 0, n, ans1 = 0, ans2 = 0; int main(){ cin >> n; for(int i = 0; i < n; i++){ cin >> a[i]; b[i] = a[i]; sum += a[i]; } sum /= n; for(int i = 0; i < n - 1; i++){ if(a[i] + a[i+1] < sum){ ans1 = inf; break; } if(a[i] != sum) ans1++; a[i+1] = sum - a[i]; a[i] = sum; } for(int i = n - 1; i >= 1; i--){ if(b[i] + b[i-1] < sum){ ans2 = inf; break; } if(b[i] != sum) ans2++; b[i-1] = sum - b[i]; b[i] = sum; } cout << min(ans1, ans2); return 0; }