408 - Uniform Generator

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

Moderator: Board moderators

fzrone
New poster
Posts: 4
Joined: Mon Jan 06, 2003 2:26 pm
Location: Indonesia, Jakarta

408 Unform Generator WA help........

Post by fzrone »

I don't find any wrong here why WA.???? :(

ANYONE CAN HELP ME PLEASE
[c]
#include<stdio.h>

int main(void)
{
long step, mod;

while(scanf("%ld %ld", &step, &mod)==2) {
if(step<1 || mod >100000) break;
printf("%10ld%10ld", step, mod);
if(step>=mod&&step%mod==0&&step>1&&mod>1) printf(" Bad Choice\n\n");
else if(step<mod&&mod%step==0&&step>1&&mod>1) printf(" Bad Choice\n\n");
else printf(" Good Choice\n\n");

}

return 0;

}
/* @end_of_source_code */[/c]

fzrone
New poster
Posts: 4
Joined: Mon Jan 06, 2003 2:26 pm
Location: Indonesia, Jakarta

SAMPLE

Post by fzrone »

..err i forgot..somethink

sample
input
3 5
2 5
13 17
4 4
111 333
999 3
output
3 5 Good Choice

2 5 Good Choice

13 17 Good Choice

4 4 Bad Choice

111 333 Bad Choice

999 3 Bad Choice

note: the output should print the step right-justified in col 1-10 and
the mod right-justiified in col. 11-20 and Good Choice or Bad Choice in col.
25 left-justified and exactly one blank line after each output.

supermin
New poster
Posts: 37
Joined: Sat Oct 12, 2002 9:54 am
Location: (Taiwan)
Contact:

Post by supermin »

Try this case:

input:
666 444

The output should be"Bad Choice".

Almost Human
Learning poster
Posts: 93
Joined: Sun Jan 12, 2003 3:30 pm

408 - Uniform Generator

Post by Almost Human »

anybody has an idea why it is WA ?

Code: Select all

#include <stdio.h>

unsigned char pow ( char y ) ;

int main ( )
{
  long step , mod , i , j , seed ;
  unsigned char flags[12500] ;
  char flag ;

/*  freopen ( "408.in" , "r" , stdin ) ;
  freopen ( "408.out" , "w" , stdout ) ;*/

  while ( scanf ( "%li %li" , &step , &mod ) != EOF )
  {
	 step = step % mod ;

	 for ( i = 0 ; i < 12500 ; i ++ )
		flags[i] = 0 ;

	 for ( flag = 0 , i = 0 , seed = - step ; i < mod ; i ++ )
	 {
		seed = ( seed + step ) % mod ;
		if ( seed == 0 && i > 0 ) { flag = 1 ; break ; }
/*		if ( ( flags[seed/8] >> ( seed % 8 ) ) & 1 ) { flag = 1 ; break ; }

		flags[seed/8] = flags[seed/8] + pow ( seed % 8 ) ;*/
	 }

	 printf ( "%10li %10li    " , step , mod ) ;
	 if ( flag ) printf ( "Bad Choice\n\n" ) ;
	 else printf ( "Good Choice\n\n" ) ;
  }

  return 0 ;
}

unsigned char pow ( char y )
{
  int x = 1 , i ;

  for ( i = 0 ; i < y ; i ++ )
	 x *= 2 ;

  return x ;
}

shamim
A great helper
Posts: 498
Joined: Mon Dec 30, 2002 10:10 am
Location: Bozeman, Montana, USA

try

Post by shamim »

Try the input

1 1

your program gives

0 1 Good Choice

Verify if it is correct.

Almost Human
Learning poster
Posts: 93
Joined: Sun Jan 12, 2003 3:30 pm

Re: try

Post by Almost Human »

shamim wrote:Try the input

1 1

your program gives

0 1 Good Choice

Verify if it is correct.
What is the output should be ? Please Help

deddy one
Experienced poster
Posts: 120
Joined: Tue Nov 12, 2002 7:36 pm

Post by deddy one »

obviously if the input is

1 1

then the output should be

1 1 Good Choice

Rene
New poster
Posts: 13
Joined: Mon May 05, 2003 4:40 am
Location: Shanghai,China

408 WA,Why?

Post by Rene »

I have tested my code for many inputs,and i have been careful to the output format. But it always gets WA. :( Please help me,Thank you. :D :D :D
[cpp]
#include <iostream.h>
#include <stdio.h>

void main()
{
long int step,mod,i,seed,j;
long int flag;
while (cin >> step >> mod)
{
for (i = 0;i < mod;i++)
{
seed = i;
seed = (seed + step) % mod;
j = 1;
flag = seed;
while (1)
{
seed = (seed + step) % mod;
if (seed == flag) break;
else j++;
}
if (j == mod)
{
printf ("%10ld%10ld %s\n\n",step,mod,"Good Choise");
break;
}
}
if (j != mod) printf ("%10ld%10ld %s\n\n",step,mod,"Bad Choise");
}
}

[/cpp]
Le roi c'est loi,le loi c'est roi

titid_gede
Experienced poster
Posts: 187
Joined: Wed Dec 11, 2002 2:03 pm
Location: Mount Papandayan, Garut

Post by titid_gede »

i dont look all your code, but why did you print "Choise", instead the correct "Choice"?
Kalo mau kaya, buat apa sekolah?

Rene
New poster
Posts: 13
Joined: Mon May 05, 2003 4:40 am
Location: Shanghai,China

Post by Rene »

Oh,my god.
yes,you are right, i use "Choice",then ACC.
Thank you. :lol:
Le roi c'est loi,le loi c'est roi

lotu
New poster
Posts: 2
Joined: Tue Apr 13, 2004 8:30 pm

408 very odd infinte loop

Post by lotu »

Okay pretty much here is the deal when I submit this code it times out. From my testing that is impossiable. Here is the code

[cpp]#include <stdio.h>
#include <iostream.h>
#include <stdlib.h>
void main()
{

long step, mod;
bool goodChoice;
while( cin>> step >> mod )
{

goodChoice = true;
for( long i = 2; i < step; i++)
{
if( step % i == 0 && mod % i == 0)
{
goodChoice = false;
break;

}
}

if( goodChoice )
printf("%10d %9d Good Choice\n",step,mod);
else
printf("%10d %9d Bad Choice\n",step,mod);
}
}[/cpp]

Now more interstinglly if I change
[cpp] if( step % i == 0 && mod % i == 0)[/cpp]
to:
[cpp] if( step % i == 0 || mod % i == 0)[/cpp]
or:
[cpp]if( step % i == 0)[/cpp]
or:
[cpp]if( mod % i == 0)[/cpp]

it dosen't time out any more and finshes in less than a second
Of course the code dosen't output the correct answer then.
So what is wrong?
Last edited by lotu on Tue Apr 13, 2004 11:26 pm, edited 1 time in total.

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

try to test in for loop not step variable, but mod variable ... please assume, that after mod steps values must repeat, so it's not neccessary to compute all values to value of step variable ...

Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

lotu
New poster
Posts: 2
Joined: Tue Apr 13, 2004 8:30 pm

Post by lotu »

[quote="Dominik Michniewski"]try to test in for loop not step variable, but mod variable ... please assume, that after mod steps values must repeat, so it's not neccessary to compute all values to value of step variable ...
/quote]
Huh? I'm sorry but I just can't understand what you are saying. I'm not worried so much about if the code correctlly solves the problem. It's that by makeing what logically should not the program to slow down by a factor of 20. Making two comparisons instead of one should not make a program 20 times slower, is my problem.
Also, I don't have any such problems when I test run it on my computer only when I submit it.

Larry
Guru
Posts: 647
Joined: Wed Jun 26, 2002 10:12 pm
Location: Hong Kong and New York City
Contact:

Post by Larry »

Of course, adding a mod won't slow down a program 20 fold, but the fact is that if you have both conditionals, then the program itself will run for much longer before "break" if reached to break out of the loop.

Dominik Michniewski
Guru
Posts: 834
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland
Contact:

Post by Dominik Michniewski »

To lotu:
My thoughts are:
1. If for any problem you can iterate for many variables, try to use this, which range is smallest
2. in this problem smallest (I think) range has mod variable.
3. I agree with Larry - adding more % operation may slow your program, but you should not get TLE because of that.
4. I made a mistake - my words not exactly say what I want to say :( I want to say, that your for loop should looks like
for(i=0;i<mod;i++) instead of yours loop (with i<step condition).

Best regards
DM
If you really want to get Accepted, try to think about possible, and after that - about impossible ... and you'll get, what you want ....
Born from ashes - restarting counter of problems (800+ solved problems)

Post Reply

Return to “Volume 4 (400-499)”