//可dfs,也可直接暴力,暴力的时候遇到了问题,比如 flag刚开始设为false,判断一直为false 则退出,,,但是死循环,然后,初始为true就过了..................
//dfs
/* #include <cstdio> #include<iostream> #include <cstring> #include <algorithm> using namespace std; int n; struct node { int val, index; }a[1000010];//最初的输入 int c[1000010];//c[x]存储在区间 (x-lowbit(x)+1, x)小于等于x的个数 bool cmp(struct node a,struct node b) { return a.val<b.val; } int lowbit(int x) { return x&(-x); } void Update(int x) { while(x<=n) { c[x]++; x += lowbit(x); } } //计算的是当前区间(0, x)比x小的个数 int Sum(int x) { int ans=0; while(x > 0){ ans += c[x]; x -= lowbit(x); } return ans; } int main() { while(~scanf("%d",&n) && n) { memset(c, 0, sizeof(c)); for(int i=1;i<=n;i++){ scanf("%d", &a[i].val); a[i].index = i;//离散化 } sort(a+1, a+1+n, cmp);//val从小到大排序 long long int sum[n+1]={0};//注意用long long,否则会WA int b[n+5]; for(int i=1; i<=n; i++){ b[a[i].index] = i; // cout << a[i].val << " " << a[i].index << " " << b[i] << endl;//因为循环里还未更新完,故有的值为0 } // cout << b[1] << endl; for(int i=1;i<=n;i++){ Update(b[i]); sum[i] += (i-Sum(b[i])); //i-Sum(x)计算的是当前大于x的个数 // cout << a[i].val << " " << sum[i] << " "<< b[i] << " " << Sum(b[i]) << endl; } //a[i].val前面比它小的数 memset(c, 0, sizeof(c)); for(int i=n; i>=1; i--){ Update(b[i]); sum[i] += Sum(b[i]-1);//可能存在=b[i] // cout << "adverse:"<< a[i].val << " " << Sum(b[i]-1) << endl; } long long SUM = 0; for(int i=1; i<=n; i++){ // cout << sum[i] << endl; SUM += sum[i]*(sum[i]+1)/2; } printf("%lld\n", SUM); return 0; } return 0; } */ #include<iostream> #include<cstdio> using namespace std; int a[110],b[110]; int cnt = 0, n; bool flag = true; void dfs() { for(int i=0; i<n; i++){ b[i] = a[i]/2; a[i]/=2; } //传给左边 for(int i=0; i<n; i++){ a[i] += b[(i+1)%n]; } //补发 for(int i=0; i<n; i++){ if(a[i]%2){ a[i] += 1; cnt++; } } for(int i=1; i<n; i++){ if(a[i]!=a[i-1]){ dfs(); } if(i == n-1){ return; } } } int main() { cin >> n; for(int i=0; i<n; i++){ cin >> a[i]; } dfs(); cout << cnt << endl; return 0; } #include<iostream> #include<cstdio> using namespace std; int a[110],b[110]; int main() { int n; cin >> n; for(int i=0; i<n; i++){cin >> a[i];} int cnt = 0; bool flag = true; while(1){ for(int i=1; i<n; i++){ if(a[i]!=a[i-1]){ flag=false; break; } } if(flag) break; for(int i=0; i<n; i++){ b[i] = a[i]/2; a[i]/=2; } //传给左边 for(int i=0; i<n; i++){ a[i] += b[(i+1)%n]; } //补发 for(int i=0; i<n; i++){ if(a[i]%2){ a[i] += 1; cnt++; } } flag = true; } cout << cnt << endl; return 0; }