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

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

Moderator: Board moderators

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

Postby fpnc » Mon May 19, 2003 8:00 pm

Please, read carefully the statement; in particular, do not asume that i < j.

If you have any other question about this problem 100, please use this thread. Thank you.
Best regards,

Fernando N
fpnc
System administrator
 
Posts: 201
Joined: Sun Oct 07, 2001 2:00 am
Location: Valladolid, Spain

Postby raihan » Sat May 31, 2003 9:54 am

I have used the all the options like not to think that 1st one is big but I still have the problem... furthur tips :(
RAIHAN WADUD
CUET
User avatar
raihan
New poster
 
Posts: 2
Joined: Sat May 31, 2003 9:26 am
Location: CUET

Read me before post

Postby Zhao Le » Thu Jun 12, 2003 4:48 am

I think it should use read all input then write all output.

Because i use read one output one, get WA,

then changed got AC.

Who knows why, so I just wanna know.

I have meet this several times, I think is the <BUG>.
Zhao Le
Learning poster
 
Posts: 80
Joined: Mon May 05, 2003 4:09 am
Location: Shanghai,China

Postby Dominik Michniewski » Thu Jun 12, 2003 7:57 am

I don't agree with you, Zhao Le. I always read only actual case(in all problems), compute answer and output it. I got problem 100 in the same way, so I think that's no bug in it . I've got Accepted over 500 problems so I think, that you don't have right ...

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)
Dominik Michniewski
Guru
 
Posts: 828
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland

How could you explain this?

Postby Zhao Le » Thu Jun 12, 2003 11:12 am

Here is my code of #100.

Here is WA.
[cpp]#include <iostream>

using namespace std;

void main()
{
long i,j,n;
while(cin>>i>>j)
{
long max=0;
cout<<i<<" "<<j<<" ";
if(i>j)
{
long tmp=j;
j=i;
i=tmp;
}
for(long t=i;t<=j;t++)
{
long c=1;
n=t;
while(n!=1)
{
c++;
if(n%2==1) n=3*n+1;
else n/=2;
}
if(c>max) max=c;
}
cout<<max<<endl;
}

}[/cpp]

Here is AC.

[cpp]#include <iostream>

using namespace std;

class S
{
public:
int i,j;
int max;
S *next;
};

void main()
{
long i,j,n;
S *head=NULL,*p,*q;
while(cin>>i>>j)
{
long max=0;
p=new S;
if(head==NULL) head=p;
else q->next=p;
p->i=i;
p->j=j;
if(i>j)
{
long tmp=j;
j=i;
i=tmp;
}
for(long t=i;t<=j;t++)
{
long c=1;
n=t;
while(n!=1)
{
c++;
if(n%2==1) n=3*n+1;
else n/=2;
}
if(c>max) max=c;
}
p->max=max;
p->next=NULL;
q=p;
}
for(p=head;p;p=p->next)
{
cout<<p->i<<" "<<p->j<<" "<<p->max<<endl;
}

}[/cpp]

Can you explain to me the problem?

This is my first ACM but is more than 2 weeks did nothing then.

And from 500 AC of it point any flaw to me.

Thanks in advance.
Zhao Le
Learning poster
 
Posts: 80
Joined: Mon May 05, 2003 4:09 am
Location: Shanghai,China

Postby Dominik Michniewski » Thu Jun 12, 2003 12:14 pm

Both of codes looks similar ...
Did you try to compile it both and check if both of them give you the same results in all cases ?? many is small mistake in one of them ?
I don't know - if I will have time, I try to check it ....

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)
Dominik Michniewski
Guru
 
Posts: 828
Joined: Wed May 29, 2002 4:11 pm
Location: Wroclaw, Poland

Postby Zhao Le » Fri Jun 13, 2003 6:06 am

I don't understand.

Please Please Please Please don't make the assert so quickly.

I change the fisrt to the second one and got AC.

So there is nothing wrong in the first I'm sure.

Who can help me?
Zhao Le
Learning poster
 
Posts: 80
Joined: Mon May 05, 2003 4:09 am
Location: Shanghai,China

Postby fpnc » Fri Jun 13, 2003 7:30 am

I've sent the first source code and I got accepted:

http://acm.uva.es/cgi-bin/OnlineJudge?S ... 7:1.00:60::

So check your method of submission (I sent it via Submit-o-matic 7)
Best regards,

Fernando N
fpnc
System administrator
 
Posts: 201
Joined: Sun Oct 07, 2001 2:00 am
Location: Valladolid, Spain

Thanks.

Postby Zhao Le » Fri Jun 13, 2003 2:54 pm

Thanks, fpnc but I don't understand.

I sent it two days ago but I got WA.

And today you sent it got AC.

Am I make mistake, but Thank you indeed.
Zhao Le
Learning poster
 
Posts: 80
Joined: Mon May 05, 2003 4:09 am
Location: Shanghai,China

Postby fpnc » Fri Jun 13, 2003 3:58 pm

I don't know either. You can see my submission got AC (and it was a copy-and-paste submission of your first code).

Anyway, please note down the full submission number when you find this kind of things as we can retrieve your submissions and try to find out what happens.
Best regards,

Fernando N
fpnc
System administrator
 
Posts: 201
Joined: Sun Oct 07, 2001 2:00 am
Location: Valladolid, Spain

To Zhao Le

Postby Nick » Sun Jun 15, 2003 3:20 am

Your first submission is surely wrong because you swap the input numbers
Code: Select all
if (i>j)
      {
         long tmp=j;
         j=i;
         i=tmp;
      }
     


the output must have the same sequence as the input was... so you musn't swap them, but instead you can use other variables to store their values temporarily

While in your second code, you've done this by storing the actual value in the linked list, that's why the second got accepted

some other programmers use function with parameter, which does similarly the same idea

regards
Nick
Learning poster
 
Posts: 53
Joined: Sun Jan 12, 2003 4:49 am

To Zhao Le

Postby Nick » Sun Jun 15, 2003 3:32 am

Your first submission is surely wrong because you swap the input numbers
Code: Select all
if (i>j)
      {
         long tmp=j;
         j=i;
         i=tmp;
      }
     


the output must have the same sequence as the input was... so you musn't swap them, but instead you can use other variables to store their values temporarily

While in your second code, you've done this by storing the actual value in the linked list, that's why the second got accepted

some other programmers use function with parameter, which does similarly the same idea

regards
Nick
Learning poster
 
Posts: 53
Joined: Sun Jan 12, 2003 4:49 am

Postby daiwb » Thu Jun 19, 2003 4:47 am

[code]
#include <iostream>

using namespace std;

int main(void){
long i,j,m,temp,total,max;
while(cin>>i>>j){
cout<<i<<" "<<j<<" ";
max=0;
if(i>j){
temp=i;
i=j;
j=temp;
}
for(m=i;m<=j;m++){
temp=m;
total=0;
while(1){
total++;
if(temp%2==0) temp/=2;
else temp=3*temp+1;
if(temp==1){
total++;
break;
}
}
if(total>max) max=total;
}
cout<<max<<endl;
}
return 0;
}
[\code]
I think it's the same,but I got WA.So why.
There Can Be Miracles When You Believe
daiwb
New poster
 
Posts: 3
Joined: Mon Jun 02, 2003 4:14 am
Location: Zhejiang University CS

Postby daiwb » Thu Jun 19, 2003 4:50 am

I havd just changed my code,and got AC.I really made a mistake.
Code: Select all
#include <iostream>

using namespace std;

int main(void){
   long i,j,m,temp,total,max;
   while(cin>>i>>j){
      cout<<i<<" "<<j<<" ";
      max=0;
      if(i>j){
         temp=i;
         i=j;
         j=temp;
      }
      for(m=i;m<=j;m++){
         temp=m;
         total=0;
         while(1){
            if(temp==1){
               total++;
               break;
            }
            total++;
            if(temp%2==0) temp/=2;
            else temp=3*temp+1;   
         }
         if(total>max) max=total;
      }
      cout<<max<<endl;
   }
   return 0;
}
There Can Be Miracles When You Believe
daiwb
New poster
 
Posts: 3
Joined: Mon Jun 02, 2003 4:14 am
Location: Zhejiang University CS

Two equal programs. One AC other WA ??

Postby xbeanx » Thu Jul 31, 2003 8:17 pm

Here are two programs that do exactly the same thing.

This one is accepted...
[java]
import java.io.*;
import java.util.*;

class Main {
public static void main(String[] args) throws IOException {
String in;
while((in = readLine(512)) != null) {
StringTokenizer st = new StringTokenizer(in);
int low = Integer.parseInt(st.nextToken());
int high = Integer.parseInt(st.nextToken());
solve(low, high);
}
}
static void solve(int l, int h) {
int low = Math.min(l, h);
int high = Math.max(l, h);
int solution = 0;
int count;
for(int i = low; i <=high; i++) {
int n = i;
count = 1;
while(n != 1) {
if(n%2 != 0) n = 3*n + 1;
else n = n/2;
count++;
}
if(count > solution) solution = count;
}
System.out.println(l + " " + h + " " + solution);
}
static String readLine(int maxLg) throws IOException {
byte[] lin = new byte[maxLg];
int lg = 0, car = -1;
while(lg < maxLg) {
car = System.in.read();
if(car<0 || car=='\n') break;
lin[lg++] += car;
}
if(car<0 && lg==0) return null;
return new String(lin, 0, lg);
}
}
[/java]

This one is not... (???????????)
[java]
import java.io.*;
import java.util.*;

class Main {
public static void main(String[] args) throws IOException {
String in;
while((in = readLine(512)) != null) {
StringTokenizer st = new StringTokenizer(in);
solve(
Integer.parseInt(st.nextToken()),
Integer.parseInt(st.nextToken())
);
}
}
static void solve(int l, int h) {
int count, solution = 0;
for(int i = Math.min(l,h); i <= Math.max(l,h); i++) {
int n = i;
count = 1;
while(n != 1) {
if(n%2 != 0) n = 3*n + 1;
else n /= 2;
count++;
}
if(count > solution) solution = count;
}
System.out.println(l + " " + h + " " + solution);
}
static String readLine(int maxLg) throws IOException {
byte[] lin = new byte[maxLg];
int lg = 0, car = -1;
while(lg < maxLg) {
car = System.in.read();
if(car<0 || car=='\n') break;
lin[lg++] += car;
}
if(car<0 && lg==0) return null;
return new String(lin, 0, lg);
}
}
[/java]

Anyone know why these two programs, which are practically identical, give different results? (Actually, for a large data set, my programs output two EXACTLY ALIKE outputs. So I don't know what's going on.)
xbeanx
Experienced poster
 
Posts: 114
Joined: Wed Jul 30, 2003 10:30 pm
Location: Newfoundland, Canada (St. John's)

Next

Return to Volume I

Who is online

Users browsing this forum: No registered users and 1 guest