305 - Joseph

All about problems in Volume 3. If there is a thread about your problem, please use it. If not, create one with its number in the subject.

Moderator: Board moderators

FlyDeath
Learning poster
Posts: 73
Joined: Wed Jan 02, 2002 2:00 am
Location: Taiwan

Post by FlyDeath » Sun Jan 06, 2002 5:52 pm

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:

Post by Cloud » Sun Jan 06, 2002 6:34 pm

hmm, the answer when k = 10 is only 93313

FlyDeath
Learning poster
Posts: 73
Joined: Wed Jan 02, 2002 2:00 am
Location: Taiwan

Post by FlyDeath » Mon Jan 07, 2002 4:25 pm

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:

Post by Cloud » Mon Jan 07, 2002 7:10 pm

The biggest answer is less than 3000000

manir
New poster
Posts: 8
Joined: Sat Jul 06, 2002 7:14 am
Location: Bangladesh
Contact:

Test this

Post by manir » Sat Jul 06, 2002 10:08 am

:evil: :evil: This problem annoyed me much
test the results with yours :evil: :evil:
:P :P :P :P :P :P :P :P :P :P :P :P :P

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

Radha
New poster
Posts: 4
Joined: Fri Aug 02, 2002 5:06 pm

Post by Radha » Fri Aug 02, 2002 5:16 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

Post by htl » Sat Aug 03, 2002 9:26 am

They are right. Maybe there are some bugs in your code.

Radha
New poster
Posts: 4
Joined: Fri Aug 02, 2002 5:06 pm

Post by Radha » Sat Aug 03, 2002 10:30 am

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

Post by htl » Sat Aug 03, 2002 10:36 am

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.

Radha
New poster
Posts: 4
Joined: Fri Aug 02, 2002 5:06 pm

Post by Radha » Sat Aug 03, 2002 5:14 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

Post by chessmaster » Thu Oct 03, 2002 9:45 am

[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 ?

User avatar
hank
Experienced poster
Posts: 146
Joined: Mon Feb 04, 2002 2:00 am
Location: VCORE.

305 - Joseph

Post by hank » Fri Oct 18, 2002 6:13 pm

Why I got TLE in 10sec ,not 30sec ?
It is strange.

How can I solve it faster?

Is there any algorithm for this?

:oops: :oops: :oops:

junjieliang
Experienced poster
Posts: 169
Joined: Wed Oct 31, 2001 2:00 am
Location: Singapore

Faster?

Post by junjieliang » Sat Oct 19, 2002 5:04 pm

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...:D

User avatar
hank
Experienced poster
Posts: 146
Joined: Mon Feb 04, 2002 2:00 am
Location: VCORE.

Post by hank » Sun Oct 20, 2002 3:19 pm

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?

:oops: :oops: :cry: :cry: :-?

junjieliang
Experienced poster
Posts: 169
Joined: Wed Oct 31, 2001 2:00 am
Location: Singapore

Yes

Post by junjieliang » Fri Oct 25, 2002 10:49 am

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 :D.

Test this:
Input (a hundred 13s):
13
13
...
13
13

Hopefully you're not superstitious...:D

Post Reply

Return to “Volume 3 (300-399)”