3 solutions
-
3
贪心 算出平均值后 遍历一遍若当前数比平均数大时把多余的数交给下一位若当前的数小于平均数时就向下一位数借(不存在下一位数不借的情况)
#include<bits/stdc++.h> using namespace std; int main() { int n,sum=0,count=0; cin>>n; int i[n+1]; for(int c=0;c<n;c++){ cin>>i[c]; count+=i[c]; } count/=n; for(int c=0;c<n;c++){ if(i[c]<count){ i[c+1]-=count-i[c]; sum++; }else if(i[c]>count){ i[c+1]+=i[c]-count; sum++; } } cout<<sum; }
Information
- ID
- 111
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 4
- Tags
- # Submissions
- 112
- Accepted
- 50
- Uploaded By