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

纪念我的100题。

Posted by pb03005073 at 2007-01-05 10:59:39 on Problem 1666
#include <iostream>
#include <cstdio>
using namespace std;

int n[10000];

void pass(int num)
{
	int *newn=new int[num];
	for(int i=0;i<num;i++)
	{
		newn[(i+1)%num]=n[(i+1)%num]/2+n[i]/2;
		if(newn[(i+1)%num]%2==1)
			(newn[(i+1)%num])++;
	}
	for(int j=0;j<num;j++)
		n[j]=newn[j];
}

bool judge(int num)
{
	for(int i=1;i<num;i++)
		if(n[i]!=n[0])
			return false;
	return true;
}
void main()
{
	int num;
	while(cin>>num && num!=0)
	{
		for(int i=0;i<num;i++)
			cin>>n[i];
		int count=0;
		while(1)
		{
			pass(num);
			if(judge(num))
			{
				count++;
				break;
			}
			else
				count++;
		}
		cout<<count<<" "<<n[0]<<endl;
	}
}

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