100 - The 3n + 1 problem

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

Moderator: Board moderators

abhi
Learning poster
Posts: 94
Joined: Fri Nov 25, 2005 7:29 pm

Post by abhi »

well ok ... i still dont know if u have got AC but anyway this is the problem

Code: Select all


The integers i and j must appear in the output in the same order in which they appeared in the input 

your code doesnt do it because you swap the two integers. it prints i and j in non decreasing order for each case.
sml
New poster
Posts: 15
Joined: Mon Jul 24, 2006 3:34 pm

Post by sml »

abhi wrote:well ok ... i still dont know if u have got AC but anyway this is the problem

Code: Select all


The integers i and j must appear in the output in the same order in which they appeared in the input 

your code doesnt do it because you swap the two integers. it prints i and j in non decreasing order for each case.
Yeah, this caught me, too. Made me learn to read and reread the problems before submitting, but there are still some evil ones out there that assume you're doing very strict management of the input, which is annoying.
newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

Post by newton »

898989 wrote:Salamo Aleko
One of the ways to get ac is to check on range on fly
make a function that get a cycle of a number

Then in main() procees directly on the range.....Then try to solve 371
i do not understand you. plz make it easier to be understood.
jtmh
New poster
Posts: 16
Joined: Sat Jul 15, 2006 8:34 pm
Location: Taiwan

Post by jtmh »

Instead of computing all the cycle lengths in advance, compute one only when necessary.
ksjones
New poster
Posts: 1
Joined: Wed Aug 16, 2006 4:47 pm

100 problem WA

Post by ksjones »

I
kolpobilashi
Learning poster
Posts: 54
Joined: Mon Jan 02, 2006 3:06 am
Location: Dhaka,Bangladesh
Contact:

Post by kolpobilashi »

i think you are "xtremely" new!! when there is a sticky about any problem then creating a new thread is a kind of crime..besides you should read all the previous posts before posting a new one.if you want to find previous posts go to the search option.

and for this problem just look at the top of this volume.there's a huge no. of discussions waiting to help you!!! :)
Sanjana
jacksh
New poster
Posts: 2
Joined: Thu Aug 17, 2006 8:46 am

WHY ?

Post by jacksh »

why it isWA?
#include<iostream>
using namespace std;
long int fun(long int n,long int i)
{
if(n==1)return i;
if(n%2==0)
return fun(n/2,i+1);
else return fun(3*n+1,i+1);
}
int main()
{
long int a,b;
int max=1;

while(cin>>a>>b)
{
if(a>b){
long int temp;
temp=a;
a=b;
b=temp;

}
for(int i=a;i<=b;++i)
{
long int j;
j=fun(i,1);
if(max<j)max=j;
}
cout<<a<<" "<<b<<" "<<max<<endl;
}
return 0;


}
mf
Guru
Posts: 1244
Joined: Mon Feb 28, 2005 4:51 am
Location: Zürich, Switzerland
Contact:

Post by mf »

http://acm.uva.es/p/v1/100.html wrote:The integers i and j must appear in the output in the same order in which they appeared in the input
David Buzatto
New poster
Posts: 4
Joined: Thu Aug 17, 2006 11:32 pm

WA in #100 problem

Post by David Buzatto »

Hi!
I already posted my problem, but i did
Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

There can be a case where n1 > n2. Print them before you swap them.
David Buzatto
New poster
Posts: 4
Joined: Thu Aug 17, 2006 11:32 pm

Post by David Buzatto »

Hi Darko. I tried to do what you said but it didn
Darko
Guru
Posts: 580
Joined: Fri Nov 11, 2005 9:34 am
Location: Calgary, Canada

Post by Darko »

Why do you go from n1+1 to n2? why not from n1?
David Buzatto
New poster
Posts: 4
Joined: Thu Aug 17, 2006 11:32 pm

Post by David Buzatto »

Darko, you were right!
Thanx!
jacksh
New poster
Posts: 2
Joined: Thu Aug 17, 2006 8:46 am

thank you

Post by jacksh »

thank you
trantri
New poster
Posts: 2
Joined: Sun Aug 20, 2006 1:25 pm

What version of Java is supported?

Post by trantri »

Hello everybody,
Do you know what version of Java is supported by the robot? In the problem 100, I use String.split() method and it always complain "Compile error", but when I change to use StringTokenizer class instead, I get "Accepted".

Thank you
Post Reply

Return to “Volume 1 (100-199)”