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

哪位大侠帮我看看,为什么会超时呢??

Posted by ling2ling2 at 2009-05-13 20:53:43 on Problem 1012
#include<iostream>
using namespace std;
int n,i,j,k,ans;
bool judge(int j)
{
	int all=n*2,w=j%all;
	for(k=1;k<n;k++)
	{
		w=w+j-all;
		all--;
		w=w%all;
		if(w==0)w=all;
	if(w<=n)
		return false;
	}
	return true;
}
int main()
{
	while(scanf("%d",&n)&&n!=0)
		for(i=n+1;;i+=(i%n==0?n+1:1))
			if(judge(i))
			{
				printf("%d\n",i);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