记录编号 |
193379 |
评测结果 |
AAAAW |
题目名称 |
[NOIP 2002]均分纸牌 |
最终得分 |
80 |
用户昵称 |
啊吧啦吧啦吧 |
是否通过 |
未通过 |
代码语言 |
C++ |
运行时间 |
0.001 s |
提交时间 |
2015-10-14 18:00:11 |
内存使用 |
0.32 MiB |
显示代码纯文本
#include <iostream>
#include <queue>
#include <fstream>
using namespace std;
const long long MAXN(101);
long long a[MAXN], l[MAXN] = {0}, r[MAXN] = {0};
queue<long long> q;
ifstream fin("jfzp.in");
ofstream fout("jfzp.out");
#define cin fin
#define cout fout
main()
{
// cout << sizeof(a) / 1024.0 << endl;
long long n, av = 0, ans = 0, x;
cin >> n;
for (long long i = 1; i <= n; ++i){
cin >> a[i];
av += a[i];
}
av /= n;
// cout << av << endl;
for (long long i = 1; i <= n; ++i){
a[i] -= av;
if (a[i] > 0)
q.push(i);
l[i] = l[i - 1] + a[i - 1];
// cout << a[i] << ' ';
}
// cout << endl;
for (long long i = n; i >= 1; --i)
r[i] = r[i + 1] + a[i + 1];
while (! q.empty()){
x = q.front();
q.pop();
if (a[x] > 0){
if (l[x] < 0){
a[x - 1] -= l[x];
if (a[x - 1] > 0)
q.push(x - 1);
l[x] = r[x - 1] = 0;
++ans;
}
if (r[x] < 0){
a[x + 1] -= r[x];
if (a[x + 1] > 0)
q.push(x + 1);
l[x + 1] = r[x] = 0;
++ans;
}
a[x] = 0;
}
}
cout << ans;
// for (; ; );
}