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

Re:求教1012算法 (提交总是 OTL)

Posted by edtemp at 2008-08-03 14:17:30 on Problem 1012
In Reply To:求教1012算法 (提交总是 OTL) Posted by:gonghuapeng at 2008-08-03 10:51:57
#include<iostream>
using namespace std;


int main()
{
	int k=0;
	int a[14] = {0};
	while( (cin>>k)&&(k!=0) )
	{
		if(a[k])
		{
			cout<<a[k]<<endl;
			continue;
		}	

		for(int m=k+1;;m++)
		{
			int n=2*k,i=0,flag=0;
			while(1)
			{
				i=(i+m-1)%n;
				if(i>=0&&i<k) break;
				else flag++;
				n--;}
			
			if(flag==k) 
			{
				a[flag] = m;
				cout<<m<<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