#include <queue>#include <stack>#include <math.h>#include <stdio.h>#include <stdlib.h>#include <iostream>#include <limits.h>#include <string.h>#include <algorithm>using namespace std;int a[101];int b[101];int n;int findmax(){int m = 0;for(int i=0; i<n; i++)if( a[i] > m )m = a[i];return m;}int findmin(){int m = INT_MAX;for(int i=0; i<n; i++)if( a[i] < m )m = a[i];return m;}int main(){int ans1,ans2,count;while( ~scanf("%d",&n) && n ){for(int i=0; i<n; i++)scanf("%d",&a[i]);count = 0;ans1 = findmax();ans2 = findmin();if( ans1 == ans2 ){printf("0 %dn",a[0]);continue;}while(1){memcpy(b,a,sizeof(a));for(int i=0; i<n; i++){a[i] /= 2;if( i == n-1 ){a[i] += b[0]/2;break;}a[i] += b[i+1]/2;}for(int i=0; i<n; i++){if( a[i] % 2 == 1 )a[i]++;}count++;ans1 = findmax();ans2 = findmin();if( ans1 == ans2 )break;}printf("%d %dn",count,a[0]);}return 0;}
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)