371 - Ackermann Functions

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

Moderator: Board moderators

sohel
Guru
Posts: 856
Joined: Thu Jan 30, 2003 5:50 am
Location: New York

Post by sohel »

hello-

when printing:
Between x and y, a generates the longest sequence of b values.

you have to make sure x <= y.

so for input:
20 1

output should be:
Between 1 and 20, 18 generates the longest sequence of 20 values.

and not:
Between 20 and 1, 18 generates the longest sequence of 20 values.

hope it helps.

BTW: other threads already exists about this problem. I assume you are new in this forum... you can search for a particular problem by using the 'search' option. If you don't get the required help, then make a post in that thread.

Iffat
New poster
Posts: 25
Joined: Sat Jul 22, 2006 9:47 am

Post by Iffat »

thanx a lot.... :) :) :) :) :) i get AC :) :) :)

sobuz
New poster
Posts: 4
Joined: Mon Aug 21, 2006 2:41 pm

371 why wa

Post by sobuz »

#include<stdio.h>
int main()
{
unsigned long int n,i,count=0,j,k,large=0,w;
do
{
scanf("%lu %lu",&n,&k);
if(n==0&&k==0)
exit(1);
for(j=n;j<=k;j++)
{
i=j;
do
{
if(i%2!=0)
i=3*i+1;
else
i=i/2;
count++;

}while(i!=1);

if(large<count){
w=j;
large=count;
}
count=0;
}


printf("Between %lu and %lu, %lu generates the longest sequence of %lu values.\n",n,k,w,large);

large=0;
}while(n!=0&&k!=0);
return 0;
}

emotional blind
A great helper
Posts: 383
Joined: Mon Oct 18, 2004 8:25 am
Location: Bangladesh
Contact:

Post by emotional blind »

First number may be greater than Second one in some pair... so consider it..
Just insert This line after scanf()

Code: Select all

if(n>k){i=n;n=k;k=i;}
And you will get Accepted.
After getting Accepted, Please dont forget to remove your code.
Keep Posting.

albet_januar
New poster
Posts: 35
Joined: Wed Apr 12, 2006 6:03 pm
Location: jakarta, indonesia
Contact:

Post by albet_januar »

can anybody help me to do check my code..??
why it can get WA..

Code: Select all

deleted after acc.. 
}
thx :D
Last edited by albet_januar on Thu Nov 16, 2006 12:17 pm, edited 1 time in total.

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

Suppose you are told to print 'abc', if you print 'cba' or 'bca' then you will get WA.
Ami ekhono shopno dekhi...
HomePage

albet_januar
New poster
Posts: 35
Joined: Wed Apr 12, 2006 6:03 pm
Location: jakarta, indonesia
Contact:

Post by albet_januar »

4 jan :
i don't really understand with ur explanation.. bcos im not good in english..
can u give a clearer explanation?

thx b4

Jan
Guru
Posts: 1334
Joined: Wed Jun 22, 2005 10:58 pm
Location: Dhaka, Bangladesh
Contact:

Post by Jan »

You are not printing correctly. Your code doesnot even pass the sample. Just match both outputs carefully and you will find your error.
Ami ekhono shopno dekhi...
HomePage

albet_januar
New poster
Posts: 35
Joined: Wed Apr 12, 2006 6:03 pm
Location: jakarta, indonesia
Contact:

Post by albet_januar »

albet_januar wrote:can anybody help me to do check my code..??
why it can get WA..

Code: Select all

deleted after ACC..
thx
:D

newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

Post by newton »

Code: Select all


   Accepted so deleted 









thanks.
Last edited by newton on Tue Feb 20, 2007 3:15 pm, edited 2 times in total.

rio
A great helper
Posts: 385
Joined: Thu Sep 21, 2006 5:01 pm
Location: Kyoto, Japan

Post by rio »

The largest value in the sequence will not be larger than can be accomodated in a 32-bit Pascal LongInt or C long
The "sequence" means the numbers between L and H.
It doesn't say that i * 3 + 1 fits in long.

After fixing this point, you will get WA.
There are some point to fix in your code.

newton
Experienced poster
Posts: 162
Joined: Thu Jul 13, 2006 7:07 am
Location: Campus Area. Dhaka.Bangladesh
Contact:

Post by newton »

hmm

Code: Select all

                    but if it is 00.627 sec?











newton................................ simply the best

lena
New poster
Posts: 28
Joined: Mon Mar 05, 2007 5:44 pm

371Wa ~~~~ Help ~~~~

Post by lena »

#include<stdio.h>
#include<iostream>
using namespace std;
long long int l,h;
long long ark(long long x)
{
unsigned long long a=x;
long long res = 0;
while(a!=1)
{
res++;
if(a%2==0)a/=2;
else a= 3*a+1;
}
return res;
}
int main()
{
while(cin>>l>>h,l!=0 || h!=0)
{
long long i;
if(l>h){i =l;l = h;h= i;}
if(l<=0)break;
long long res = ark(l);
long long resp = l;
long long t;
for(i=l+1;i<=h;i++)
{
t = ark(i);
if(t>res)
{
res = t;
resp = i;
}
}
printf("Between %lld and %lld, %lld generates the longest sequence of %lld values.\n",l,h,resp,res);
}
return 0;
}

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

Post by helloneo »

Don't create a new thread if there is one already..
Use this one..
http://online-judge.uva.es/board/viewtopic.php?t=2814

lena
New poster
Posts: 28
Joined: Mon Mar 05, 2007 5:44 pm

information On 371

Post by lena »

1.when n =1,the value is 3,not 1.....
2.the input and output is in the range of long,but the sequence may out of it.

Post Reply

Return to “Volume 3 (300-399)”