## If you get WA in problem 100, read me before post!

Moderator: Board moderators

Ah.. I think it should be

Code: Select all
`for (int t=hi; t <= hj; t=t+1)`

and "int" is enough..
helloneo
Guru

Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

Well,

I tried it, but it didn't change anything.

Working just with Int does not work, at least not with Visual Studio 6
DarkX2
New poster

Posts: 3
Joined: Wed Feb 28, 2007 9:27 am

DarkX2 wrote:With this new code, I receive the same anwsers as statefull's had tested before -with the exception of the 787843 case, that seems not to finish...

Code: Select all
`#include <stdio.h>using namespace std;int main(){   unsigned long int i, j, n;   while (scanf("%ld %ld",&i,&j)==2)   {      unsigned long int hi, hj;      unsigned long int  max = 0;      if (i > j)      {         hi = j;         hj = i;      }      else      {         hi = i;         hj = j;      }      printf("%ld %ld ",i,j);      for (int t=hi;t<hj;t=t+1)      {         unsigned long int c = 1;         n = t;                  do           {            if (n == 1)            {               max = max +1;            }            else            {               if ( (n % 2) != 0)               {                  n = (3 * n) + 1;               }               else               {                  (n = n / 2);               }               c = c + 1;               if (c > max)               {                  max = max+1;               }            }         }         while (n != 1);               }      printf("%ld\n",max);   }}`

I still get wrong answer. I don't realize doing anything totally different from newtons version posted above that gets Accepted.

Any ideas what's up?

EDIT:

Arrghh, I got it. Long is too small, I thought that Long > Int, but I was wrong...

EDIT2:

Still getting WA...
Is Statefulls Answer for 787843 right? I'm getting 470 as solution...

check out for this part .... first of all (t<=hj) is desired .... n then max is not bein choosen correctly..i have modified it and get AC
Code: Select all
`#include <stdio.h>#include<iostream>using namespace std;int main(){    long i, j, n;   while (scanf("%ld %ld",&i,&j)==2)   {      long  hi, hj;      long  max = 0;      if (i > j)      {         hi = j;         hj = i;      }      else      {         hi = i;         hj = j;      }      printf("%ld %ld ",i,j);            for (long t=hi;t<=hj;t=t+1)      {        long  c = 0;         n = t;                          while(n!=1){                 if ( (n % 2) != 0)               {                  n = (3 * n) + 1;                                 }               else               {                  n = n / 2;                                 }                   c++;         }        // cout<<c<<endl;          if (c +1> max)               {                  max=c+1;               }               }      printf("%ld\n",max);   }}`
I am striving to write bug free codes (
animeshnayan
New poster

Posts: 5
Joined: Tue Mar 20, 2007 7:44 am

I'm completely new to programming... I tried the first problem, but I'm still getting WA (I tried it some 20 times now...)

Can someone help me?

Here is my code:

#include <stdio.h>

int main (void)
{
unsigned int num1, num2, i, j, cycle_length, max_cycle;
scanf ("%ld %ld", & num1, & num2);
max_cycle = 1;

if ((num1 < num2) && (num2 < 1000000))
{
for (i = num1; i <= num2; i ++)
{
cycle_length = 1;
j = i;
while (j > 1)
{
if ((j % 2) == 0)
j = j / 2;
else
j = (3 * j) + 1;
cycle_length ++;
}
if (cycle_length > max_cycle)
max_cycle = cycle_length;
}
}

else if ((num1 > num2) && (num1 < 1000000))
{
for (i = num2; i <= num1; i ++)
{
cycle_length = 1;
j = i;
while (j > 1)
{
if ((j % 2) == 0)
j = j / 2;
else
j = (3 * j) + 1;
cycle_length ++;
}
if (cycle_length > max_cycle)
max_cycle = cycle_length;
}
}

printf ("%ld %ld %ld\n", num1, num2, max_cycle);
return (0);
}
NottaBenna
New poster

Posts: 1
Joined: Mon Mar 26, 2007 10:07 pm

NottaBenna wrote:I'm completely new to programming... I tried the first problem, but I'm still getting WA (I tried it some 20 times now...)

Can someone help me?

Here is my code:

...unsigned int num1, num2, i, j, cycle_length, max_cycle;...

you are using ints. Here is some info about how big a number your primitive types hold:

INT_MAX is 32767
UINT_MAX is 65535 (unsigned)

but specifications say i and j could be up to 1000000 (1 million)

LONG_MAX is 2147483647
ULONG_MAX is 4294967295

Try using long or unsigned long.
HyperWireD
New poster

Posts: 1
Joined: Thu Apr 26, 2007 5:37 pm

### problem# 100, gets WA, but don't know why

hi all,

my code for problem #100 is as follows, i am getting a WRONG ANSWER error. But I cannot figure out why.

Code: Select all
`#include<iostream>using namespace std;#define SIZE 1000000int cyc_length[SIZE];inline int calc_length(int n ){       int a,l,s;       if ( n == 1 ) return 1;       if ( cyc_length[n] == -1  ) return cyc_length[n];       s = n;       l = 0;       while ( n != 1 )       {               l++;          a = n%2 ? n*3 +1 : n/2;               if ( a < SIZE )               {                       if ( cyc_length[a] > 0 )                       {                               l = l + cyc_length[a] - 1;                               break;                       }                       cyc_length[a] = -1;               }               n = a;       }       cyc_length[s] = ++l;       return l;}int main(int argc, char* argv[]){       int first, second, temp, current,max_length, length;       for (int i = 0 ; i < SIZE ; )   {      cyc_length[i++] = 0;      cyc_length[i++] = 0;      cyc_length[i++] = 0;      cyc_length[i++] = 0;   }       while (cin>>first>>second)       {               /* printf("%d %d ",first,second); */      cout <<first<<" "<<second<<" ";               if ( first > second )               {                       temp = first;                       first = second;                       second = temp;               }               current = first;               max_length = 1;               while ( current < second )               {                       length = calc_length(current);                       if ( length > max_length )                               max_length = length;                       current++;               };               /*printf("%d\n",max_length);*/               cout<<max_length<<endl;       }       return 0;}`
roshanlen
New poster

Posts: 1
Joined: Fri Apr 27, 2007 10:46 pm

To roshanlen:

May u done some worng...
check it....

input
Code: Select all
`20 209999 99991 9999340 30003000 340500 1011 19999 9998`

output
Code: Select all
`20 20 89999 9999 921 9999 262340 3000 2173000 340 217500 101 1441 1 19999 9998 92`

GOOD LUCK
Rocky

Rocky
Experienced poster

Posts: 124
Joined: Thu Oct 14, 2004 9:05 am

can anybody help me

i always get wa, here is my code:

Code: Select all
`var n,k:array[1..100000] of longint;i,j,max,p,k1,f:longint;function nn(a:longint):integer;beginp:=0;while a<>1 do beginif a mod 2=0 then a:=a div 2 else a:=(3*a)+1;inc(p);end;nn:=p;end;begini:=0;repeatinc(i);read(n[i],k[i]);until eof;k1:=i;for i:=1 to k1 do beginmax:=0;if k[i]<n[i] then beginf:=k[i];k[i]:=n[i];n[i]:=f;end;   if n[i]>0 then begin        for j:=n[i] to k[i] do        if nn(j)>max then max:=nn(j);writeln(n[i],' ',k[i],' ',max+1);end;end;readln;end.`
gates1
New poster

Posts: 7
Joined: Tue May 01, 2007 2:11 pm

Try Rocky's test cases right up there..
helloneo
Guru

Posts: 516
Joined: Mon Jul 04, 2005 6:30 am
Location: Seoul, Korea

rocky's test cases work on my program
gates1
New poster

Posts: 7
Joined: Tue May 01, 2007 2:11 pm

Hey to all of you programming pros out there can someone plz tell me what is wrong with my program I always get Compiler Error for some reason and I have no idea what is wrong with this because it works fine on my computer GRR

#include<iostream>

#define MAXSIZE 100000
using namespace std;

int find_length(int num)
{
if(num==1) return 1;
int n=num;
if(n%2==0) n/=2;
else n=n*3+1;
return find_length(n)+1;
}

int main()
{
long min, max;

while(cin>>min>>max)
{
cout<<min<<" "<<max<<" ";
if(min>max)
{
long a=min; min=max; max=a;
}
long max_length=0;
for(long i=min; i<=max; i++)
{
long n=find_length(i);
if(n>max_length)
max_length=n;
}
cout<<max_length<<endl;

}
return 0;
}

Thanks for helping

btw sometimes it says "received". What does that mean??
Itachi-Forsaken
New poster

Posts: 10
Joined: Mon May 07, 2007 4:45 am

now its ok ...i send it by pm check it!!!

GOOD LUCK
Rocky

Rocky
Experienced poster

Posts: 124
Joined: Thu Oct 14, 2004 9:05 am

Thanks, but it always says received instead of accepted for some reason =S
What is it suppose to mean?

edit: nvm, it works now =D thanks a lot
Itachi-Forsaken
New poster

Posts: 10
Joined: Mon May 07, 2007 4:45 am

every code at first says recieved at first but after refresh and after some time it give it answer....that accepted/wa/ce...etc...
so wait for some time and refresh the judge page yeah..u can check ur statics also after some time..

GOOD LUCK
Rocky

Rocky
Experienced poster

Posts: 124
Joined: Thu Oct 14, 2004 9:05 am

### suggestion to Notta Benna

To Notta Benna

you are taking only one set of input and printing out the answer

you have to take the input sets in a loop till the end of file.
you can read in one set of input , print out the output then again read in next set....
go on till there is no more input
ani_mitr86
New poster

Posts: 20
Joined: Mon May 28, 2007 4:36 pm
Location: India

PreviousNext