Page 65 of 93
Need Help, I'm New..
Posted: Sun Oct 07, 2007 1:31 pm
by ergysr
Hi all,
i just registered and made my first submission(3n+1) on the online judge, but i got WA. I'm quite sure my algorithm is correct, but i think my problem is input & output. Should i input values via input file(what' the name of that file) or values are entered manually? What about the output? A file or just a writeln function? Somebody clarify me please...
Posted: Sun Oct 07, 2007 1:54 pm
by Darko
You read input from standard in and write to standard out.
Posted: Wed Oct 10, 2007 8:35 pm
by ergysr
Darko wrote:You read input from standard in and write to standard out.
Thnx darko, read all test cases and then output results? or just input output, input output?
Posted: Wed Oct 10, 2007 8:42 pm
by Darko
You can output result of each test case after you process it. Or you can do it all at once. It doesn't really matter, what they do is redirect your output to a file and then compare with their results (or run a program to check it).
I am guessing you are using Pascal, so I can't really help you much, but they posted a solution to 100, maybe that can help:
http://online-judge.uva.es/problemset/data/p100.p.html
Posted: Sun Oct 14, 2007 7:10 pm
by ergysr
Darko wrote:You can output result of each test case after you process it. Or you can do it all at once. It doesn't really matter, what they do is redirect your output to a file and then compare with their results (or run a program to check it).
I am guessing you are using Pascal, so I can't really help you much, but they posted a solution to 100, maybe that can help:
http://online-judge.uva.es/problemset/data/p100.p.html
thanks darko, really thanks.
Posted: Thu Oct 18, 2007 7:18 am
by Hatty
Getting wrong answer, I dont know why...
Edit: Code removed. Thanks sapnil, didnt have to use long int though, as the challenge says that all numbers are below 1mil
It works, but I don't know why I get wrong answer...
Code: Select all
hatty@study:~/dev/uva$ ./100
1 10
1 10 20
100 200
100 200 125
201 210
201 210 89
900 1000
900 1000 174
hatty@study:~/dev/uva$
Those are the same inputs and outputs as in the problem.. Help?
TLE help
Posted: Fri Oct 26, 2007 4:05 pm
by sumonSUST
I get TLE plz help me
Thanks
sumon
Posted: Fri Oct 26, 2007 4:07 pm
by sapnil
To sumon
Just change this line:
Thanks
Keep posting
Sapnil
Posted: Fri Oct 26, 2007 4:11 pm
by sumonSUST
To sapnil
Thanks.
I get ACC now
Sumon
Posted: Thu Nov 01, 2007 12:39 pm
by sapnil
To Hatty
Your problem is in taking input.
Make it simple
Code: Select all
while(scanf("%ld %ld",&j,&i)==2)
{
}
>> use long data type
>> remove your code after Acc
Thanks
Keep postingh
sapnil
about ACM 100 WA
Posted: Sun Nov 18, 2007 4:33 pm
by think12381
Dear all
I test some numbers to my code but no error can't be finded!!
Send this code to Online Judge, it always tells me "WA".
May you tell me what WA is happened on my code ???
Thank you!
#include <stdio.h>
long algorithm(long );
void swap(long *,long*);
int main(int argc, char *argv)
{
long i,j,first=0,second=0,temp=0,n=0;
while(scanf("%ld%ld",&i,&j)==2)
{
if((i<=0) || (j<=0) || (i>1000000) || (j>1000000))
{
printf("the two number is error!!\n");
exit(1);
}
if((i==1) && (j==1))
{
temp=1;
}
else
{
if(j<i)
swap(&i,&j);
temp = algorithm(i);
i=i+1;
for(i;i<j;i++)
{
second=algorithm(i);
if(temp<second)
temp=second;
}
}
printf("MAX cycle length is =%d\n",temp);
}
return 0;
}
long algorithm(long n)
{
int time=1;
do
{
if((n%2)==0)
{
n=n/2;
}
else
{
n=n*3+1;
}
time++;
}while(n!=1);
return time;
}
void swap(long *i,long*j)
{
long c;
c=*j;
*j=*i;
*i=c;
}
Posted: Sun Nov 18, 2007 5:11 pm
by mf
You should strictly follow the sample output, as described in the section "The Output" of the problem statement. Essentially, output of your program is compared with a correct output file, and if any single byte doesn't match you get WA.
Printing anything extra, like the message "MAX cycle length is " will definitely result in WA, even if numbers are OK.
Q: java input
Posted: Tue Nov 20, 2007 11:35 pm
by ithenewguyi
can anyone explain how does the java input provided works?
why cant we use Scanner? for some problems, how do we tell if the input is over? do we use Scanner.hasNext() method?
thanks for any "input"

Posted: Wed Nov 21, 2007 9:29 am
by mf
You can use Scanner.
Posted: Wed Nov 21, 2007 6:37 pm
by ithenewguyi
thanks for the reply, and so we could use .hasNext() method to check if the input is finished?
I'm not sure why i get a WA then
for the problem 100, i took care of the i>j or i<j and still...
Code: Select all
/* problem 100
* 3n + 1 problem
*/
import java.util.*;
class Main
{
public static void main(String[] args)
{
Scanner in = new Scanner (System.in);
try {
while (in.hasNext()){
String numbers = in.nextLine();
String[] num = numbers.split(" ");
long num1 = Long.parseLong(num[0]);
long num2 = Long.parseLong(num[1]);
long big;
long small;
if (num1 > num2){
big = num1;
small = num2;
}
else {
big = num2;
small = num1;
}
long temp;
long counter=1;
long biggest=1;
for (long i = small; small <= big; small++)
{
temp = small;
while (temp != 1){
if (temp % 2 == 0){
temp /= 2;
counter++;
}
else{
counter++;
temp = temp * 3 +1;
}
}
if (counter>biggest)
biggest=counter;
counter=1;
}
System.out.println(numbers+" "+biggest);
}
}catch (Exception e){System.exit(0);}
}
}