Page 1 of 4
408 Unform Generator WA help........
Posted: Wed Jan 08, 2003 8:48 am
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]
SAMPLE
Posted: Wed Jan 08, 2003 9:17 am
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.
Posted: Sat Jan 11, 2003 4:39 am
by supermin
Try this case:
input:
666 444
The output should be"Bad Choice".
408 - Uniform Generator
Posted: Mon Apr 21, 2003 2:14 pm
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 ;
}
try
Posted: Tue Apr 22, 2003 7:02 am
by shamim
Try the input
1 1
your program gives
0 1 Good Choice
Verify if it is correct.
Re: try
Posted: Tue Apr 22, 2003 7:31 am
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
Posted: Tue Apr 22, 2003 2:15 pm
by deddy one
obviously if the input is
1 1
then the output should be
1 1 Good Choice
408 WA,Why?
Posted: Thu Jul 24, 2003 3:59 pm
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.
[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]
Posted: Thu Jul 24, 2003 6:12 pm
by titid_gede
i dont look all your code, but why did you print "Choise", instead the correct "Choice"?
Posted: Fri Jul 25, 2003 6:11 am
by Rene
Oh,my god.
yes,you are right, i use "Choice",then ACC.
Thank you.

408 very odd infinte loop
Posted: Tue Apr 13, 2004 8:37 pm
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?
Posted: Tue Apr 13, 2004 9:39 pm
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
Posted: Tue Apr 13, 2004 11:25 pm
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.
Posted: Wed Apr 14, 2004 12:30 am
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.
Posted: Wed Apr 14, 2004 8:28 am
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