305  Joseph
Moderator: Board moderators
Test this
This problem annoyed me much
test the results with yours
answer for input 10=93313;
answer for input 11=459901;
answer for input 12=1358657;
answer for input 13=2504881; //The culprit
test the results with yours
answer for input 10=93313;
answer for input 11=459901;
answer for input 12=1358657;
answer for input 13=2504881; //The culprit
The 2nd laziest person of the world
ok here is the code:
#include<stdio.h>
main()
{
long pre[50],i,ng[1000],n1,nwin,n,j,nk,k,nb,m1,m;
char c,temp[120];
i = 0;
while(1)
{
scanf("%s",temp);
sscanf(temp,"%ld",&ng);
if(ng == 0)
break;
i++;
}
nk = i;
for(k=0;k<nk;k++)
{
n=ng[k] * 2;
for(m=1; ; m++)
{
nb=0;
nwin = 1;
for(j=0;j<n;j++)
pre[j] = j;
n1= n;
i=0;
while(nb < ng[k])
{
i= (i+m1) % n1 ;
if(i<ng[k] && nb < ng[k])
{
nwin = 0;
break;
}
else
nb++;
for(j=i;j<n11;j++)
pre[j] = pre[j+1];
n1;
}
if(nwin)
{
printf("%ld\n",m);
break;
}
}
}
}
#include<stdio.h>
main()
{
long pre[50],i,ng[1000],n1,nwin,n,j,nk,k,nb,m1,m;
char c,temp[120];
i = 0;
while(1)
{
scanf("%s",temp);
sscanf(temp,"%ld",&ng);
if(ng == 0)
break;
i++;
}
nk = i;
for(k=0;k<nk;k++)
{
n=ng[k] * 2;
for(m=1; ; m++)
{
nb=0;
nwin = 1;
for(j=0;j<n;j++)
pre[j] = j;
n1= n;
i=0;
while(nb < ng[k])
{
i= (i+m1) % n1 ;
if(i<ng[k] && nb < ng[k])
{
nwin = 0;
break;
}
else
nb++;
for(j=i;j<n11;j++)
pre[j] = pre[j+1];
n1;
}
if(nwin)
{
printf("%ld\n",m);
break;
}
}
}
}

 New poster
 Posts: 5
 Joined: Sat Sep 28, 2002 3:46 pm
[c]
# include <stdio.h>
long coba(long n)
{ long a=n,b,n2=2*n,nn;
while (1)
{
a++;
b=a;
b=b%n2;
nn=n21;
if (b==0) b=n2;
while (nn>n && b>=n+1 )
{
b;
b+=a;
b%=nn;
if (b==0) b=nn;
nn;
}/*while*/
if (nn<=n && (b>n  b==0))
return a;
}
// return 0;
}
void main()
{
long a,b=0;
long tabel[200];
while (scanf("%ld",&a)!=0)
{
if (a>0 && a<14) tabel[b++]=a;
if (a==0) break;
}
for (a=0;a<b;a++)
tabel[a]=coba(tabel[a]);
printf("\n");
for (a=0;a<b;a++)
printf("%ld\n",tabel[a]);
}[/c]
why i got WA ?
# include <stdio.h>
long coba(long n)
{ long a=n,b,n2=2*n,nn;
while (1)
{
a++;
b=a;
b=b%n2;
nn=n21;
if (b==0) b=n2;
while (nn>n && b>=n+1 )
{
b;
b+=a;
b%=nn;
if (b==0) b=nn;
nn;
}/*while*/
if (nn<=n && (b>n  b==0))
return a;
}
// return 0;
}
void main()
{
long a,b=0;
long tabel[200];
while (scanf("%ld",&a)!=0)
{
if (a>0 && a<14) tabel[b++]=a;
if (a==0) break;
}
for (a=0;a<b;a++)
tabel[a]=coba(tabel[a]);
printf("\n");
for (a=0;a<b;a++)
printf("%ld\n",tabel[a]);
}[/c]
why i got WA ?
305  Joseph
Why I got TLE in 10sec ,not 30sec ?
It is strange.
How can I solve it faster?
Is there any algorithm for this?
It is strange.
How can I solve it faster?
Is there any algorithm for this?

 Experienced poster
 Posts: 169
 Joined: Wed Oct 31, 2001 2:00 am
 Location: Singapore
Faster?
AFAIK, The time limit has been standardised to 10 sec.
There's really no way to solve it faster, what I did is to try every number up to the solution. A point to note is that since the good and bad guys are always together, you can represent them by 2 numbers, in case you're using arrays like what I first did...
There's really no way to solve it faster, what I did is to try every number up to the solution. A point to note is that since the good and bad guys are always together, you can represent them by 2 numbers, in case you're using arrays like what I first did...

 Experienced poster
 Posts: 169
 Joined: Wed Oct 31, 2001 2:00 am
 Location: Singapore
Yes
I tried coding the program, and it ran in <1s. What I found is that you should store your answer first, then output them, as my first program (without precalculation) got TLE as well .
Test this:
Input (a hundred 13s):
13
13
...
13
13
Hopefully you're not superstitious...
Test this:
Input (a hundred 13s):
13
13
...
13
13
Hopefully you're not superstitious...