社区讨论
40求调
P1031[NOIP 2002 提高组] 均分纸牌参与者 2已保存回复 2
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 2 条
- 当前快照
- 1 份
- 快照标识符
- @m6ugm7tq
- 此快照首次捕获于
- 2025/02/07 15:43 去年
- 此快照最后确认于
- 2025/11/04 09:49 4 个月前
思路是从大到小变成平均值
CPP#include<bits/stdc++.h>
#define N 202000
#define M 2020
#define ll long long
using namespace std;
ll n, a[N], step, sum;
bool cmp( ll A, ll B ){
return A > B;
}
bool check(){
for ( int i = 1; i <= n; i++ ){
if ( a[i] != sum ){
return 1;
}
}
return 0;
}
int main(){
cin.tie(0);cout.tie(0);
cin >> n;
for ( int i = 1; i <= n; i++ ){
cin >> a[i];
sum += a[i];
}
sum /= n;
while(check()){
sort ( a + 1, a + n + 1 );
ll t = sum - a[1];
a[n] -= t;
a[1] = sum;
step++;
}
cout << step;
return 0;
}
回复
共 2 条回复,欢迎继续交流。
正在加载回复...