Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

my code

Posted by z1160y at 2009-06-03 18:21:12 on Problem 1666
#include <iostream>
using namespace std;
int main()
{
	int n;
	int candy[1000];
	int plus[1000];
	int minus[1000];
	int i;
	while(cin>>n&&n)
	{
		for(i=1;i<=n;i++)  cin>>candy[i];
		int count=0;
		while(++count)
		{
			for(i=1;i<=n;i++)
			{
				minus[i]=candy[i]/2;
				if(i!=n)  plus[i+1]=candy[i]/2;
				else plus[1]=candy[n]/2;
			}
			int z,note=0;
			for(i=1;i<=n;i++)
			{
				candy[i]=candy[i]+plus[i]-minus[i];
				if(candy[i]%2)  candy[i]++;
				if(candy[1]!=candy[i])  note++;
			}
			if(!note)  
			{
				cout<<count<<' '<<candy[1]<<endl;
				break;
			}
		}
	}
	return 0;
}


Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator