| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
哪位大侠帮我看看,为什么会超时呢??#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator