hdu1034 Candy Sharing Game

题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1034


#include <stdio.h>
#define MAXN 1000

int arr[MAXN];

int main()
{
	int n,i,temp,ans;
	while(scanf("%d",&n)&&n)
	{
		ans=0;
		for(i=0;i<n;++i)
			scanf("%d",&arr[i]);
		while(1)
		{
			for(i=1;i<n;++i)
			{
				if(arr[i]!=arr[i-1])
					break;
			}
			if(i>=n)
				break;
			ans++;
			temp=arr[n-1]/2;
			for(i=n-1;i>0;--i)
			{
				arr[i]/=2;
				arr[i]+=(arr[i-1]/2);
			}
			arr[0]/=2;
			arr[0]+=temp;
			for(i=0;i<n;++i)
			{
				if(arr[i]&1)//arr[i]奇数
					++arr[i];
			}
		}
	printf("%d %d\n",ans,arr[0]);
	}
	return 0;
}


你可能感兴趣的:(hdu1034 Candy Sharing Game)