| ||||||||||
| 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 | |||||||||
不超时In Reply To:超时和不超时 Posted by:orangelegend at 2008-09-24 21:20:24 #include <stdio.h>
#include <string.h>
#include<windows.h>
struct city
{
int prior,flag,next;
}c[250];
void initcity(int n)
{
int i;
for (i = 0; i < n; i++)
{
c[i].prior = i - 1;
c[i].flag = 0;
c[i].next = i + 1;
}
c[0].prior = n - 1;
c[n - 1].next = 0;
}
void visitcity(int n)
{
c[n].flag = 1;
c[c[n].prior].next = c[n].next;
c[c[n].next].prior = c[n].prior;
}
int main()
{
int m,i,n,j,count;
long t1,t2;
freopen("d:\\test.txt","r",stdin);
t1 = GetTickCount();
while (scanf("%d",&n) != EOF && n != 0)
{
m = 1;
while (1)
{
initcity(n);
i = count = 0;
while (count != n)
{
visitcity(i);
count++;
j = 0;
while(j < m)
{
i = c[i].next;
j++;
}
if (i == 1 && count < n)
break;
}
if (count == n - 1)
break;
m++;
}
printf("%d\n",m);
}
t2 = GetTickCount();
printf("time cost %ld\n",t2 - t1);
return 0;
}
125ms
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator