Algo-Trian
This commit is contained in:
26
Algorithm/Greedy/P1031 [NOIP 2002 提高组] 均分纸牌.cpp
Normal file
26
Algorithm/Greedy/P1031 [NOIP 2002 提高组] 均分纸牌.cpp
Normal file
@@ -0,0 +1,26 @@
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
using namespace std;
|
||||
int main(){
|
||||
int n;
|
||||
cin >> n;
|
||||
vector<int> a(n);
|
||||
int sum = 0;
|
||||
for(int i = 0; i < n; i++){
|
||||
cin >> a[i];
|
||||
sum += a[i];
|
||||
}
|
||||
int avg = sum / n;
|
||||
int js = 0;
|
||||
for(int i = 0; i < n - 1; i++){
|
||||
if(a[i] != avg){
|
||||
int tmp = a[i] - avg;
|
||||
a[i] = avg;
|
||||
a[i + 1] += tmp;
|
||||
js++;
|
||||
}
|
||||
}
|
||||
cout << js << endl;
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user