305 - Joseph

Moderator: Board moderators

FlyDeath
Learning poster
Posts: 73
Joined: Wed Jan 02, 2002 2:00 am
Location: Taiwan
is the ans very big??
when the input be 10,i loop from 1 to 240000 and can't find the answer
i just wanna check if my program is ok
Cloud
New poster
Posts: 10
Joined: Sat Dec 29, 2001 2:00 am
Contact:
hmm, the answer when k = 10 is only 93313
FlyDeath
Learning poster
Posts: 73
Joined: Wed Jan 02, 2002 2:00 am
Location: Taiwan
I fix it with the input 10
is there any ans greater than 1000000??
some other input i run over 1000000 and can't get the answer

<font size=-1>[ This Message was edited by: FlyDeath on 2002-01-07 15:46 ]</font>
Cloud
New poster
Posts: 10
Joined: Sat Dec 29, 2001 2:00 am
Contact:
The biggest answer is less than 3000000
manir
New poster
Posts: 8
Joined: Sat Jul 06, 2002 7:14 am
Contact:

Test this

This problem annoyed me much
test the results with yours

answer for input 13=2504881; //The culprit
The 2nd laziest person of the world
New poster
Posts: 4
Joined: Fri Aug 02, 2002 5:06 pm
i get a wrong answer for this question.the answers fro values 1 to 13 are
2
7
5
30
169
441
1872
7632
1740
93313
459901
1358657
2504881
are these correct?
thanks
htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan
They are right. Maybe there are some bugs in your code.
New poster
Posts: 4
Joined: Fri Aug 02, 2002 5:06 pm
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+m-1) % n1 ;
if(i<ng[k] && nb < ng[k])
{
nwin = 0;
break;
}
else
nb++;
for(j=i;j<n1-1;j++)
pre[j] = pre[j+1];
n1--;
}
if(nwin)
{
printf("%ld\n",m);
break;
}
}
}
}
htl
Experienced poster
Posts: 185
Joined: Fri Jun 28, 2002 12:05 pm
Location: Taipei, Taiwan
You've figured out the right answer. And I think your algorithm isn't wrong. You can just building a table and put your answers in it. All you have to do is just print them.
New poster
Posts: 4
Joined: Fri Aug 02, 2002 5:06 pm
Thanks,
i did that and i got it accepted, but why did my program code got wrong answer. can you help me?
chessmaster
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=n2-1;
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 ?
hank
Experienced poster
Posts: 146
Joined: Mon Feb 04, 2002 2:00 am
Location: VCORE.

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?

junjieliang
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...
hank
Experienced poster
Posts: 146
Joined: Mon Feb 04, 2002 2:00 am
Location: VCORE.
My program only run 29 seconds. I think my program is very fast.
But the time limit is 10sec.

and there are some people only cost 0.00sec on the rank list.

Is it possible?

junjieliang
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...