Page 62 of 93

100 ???

Posted: Fri May 11, 2007 9:37 pm
by shakil
i solved 100 but it took 4 s. How it can solved in 0 s ???
Please help......

Posted: Sat May 12, 2007 5:40 pm
by Itachi-Forsaken
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??

Posted: Sat May 12, 2007 6:10 pm
by Rocky
now its ok ...i send it by pm check it!!!

GOOD LUCK
Rocky

Posted: Sat May 12, 2007 7:04 pm
by Itachi-Forsaken
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

Posted: Sun May 13, 2007 5:55 pm
by Rocky
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

100 - Time Exceeded (?)

Posted: Wed May 16, 2007 10:25 am
by nachopol
Hi. I've received a time exceeded (10.025 seconds) when in other computers, the program takes 0 seconds. Could it be the entrance mode? Here is the code. Thanks in advance:
#include "stdio.h"
void main(){
long n,i,x,n0,n1,mc,c=1;
while (scanf("%ld %ld",&n0,&n1)) {
printf ("%ld %ld ",n0,n1);
mc=1;
if (n0>n1) {x=n0;n0=n1;n1=x;}
for (i=n0;i<=n1;i++) {

c=1;
n=i;
while(n>1){
n=(n%2)?(3*n+1):(n/2);
c++;
}
if (c>mc) mc=c;
}
printf ("%ld\n",mc);
}
}

100 - 3n+1 - Memorisation

Posted: Wed May 16, 2007 2:21 pm
by Schultz
I have solved the 3n+1 problem by use of the memorisation method. In my computer, it solves the input "1 999999" 60 times faster than brute force. But when I submit it, besides getting AC, it takes over a second to get it correct, considering that the brute force took 3 seconds. Furthermore, I expected the 4000000 elements memorisation table to be built once only, taking no more than 0.1 seconds, but I am strongly suspecting my program is being loaded up more than once.

Finally, I want to ask how many times does the judge call my main function, i.e. how many times does it start up my program. Until today I thought it was once only but I am not sure it is.

I would post the code, but it is AC.

Thanks in advance.

EOF

Posted: Wed May 16, 2007 2:50 pm
by nachopol
The problem was in the loop. It should be:
while (scanf("%ld %ld",&n0,&n1)!=EOF)

Posted: Wed May 16, 2007 7:07 pm
by Jan
Search the board first. Don't open a new thread if there is one already.

Posted: Wed May 16, 2007 7:07 pm
by Jan
Use existing threads.

Posted: Sat May 26, 2007 5:28 pm
by SARKAR
use memorization

firstly it took 6 sec to solve the problem
using memorization i solved it in 0.06

dont worry about 0.000


suggestion to Notta Benna

Posted: Mon May 28, 2007 4:44 pm
by ani_mitr86
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

MEMORIZATION

Posted: Sun Jun 03, 2007 6:37 am
by diptesh_chatterjee
I am new to this world of programming . Can someone tell me what memorization is?? I got a TLE error when the judge executed my code

Posted: Sun Jun 03, 2007 12:12 pm
by mmonish
>>diptesh_chatterjee
I didn't do any kind of memorization & i got AC in 3.393 sec.

Here u can store the chain length. u must not calculate the chain length for a number twice.
here is an example
let i = 3 & j = 6
then first step u calculate the chain length for 3 is 8.
chain length for 4 is 3.
chain length for 5 ->16 ->8 ->4(add cycle length of 4)need no further calculation.
chain length for 6->3(add cycle length of 3) only one operation need.

Hope it helps.

How to terminate the input

Posted: Sun Jun 03, 2007 5:39 pm
by MeNFolkS
I'v been tryin out problem number 100, n the problem i'v been havin is in terminating the input.....
problems statement says tht each test case would be in a new line...like
10 100
20 200

nw how to terminate tht....

i thought this would work

while ( !feof ( stdin ) )
{
cin >> a; cin >> b;
//process
}

but this code is givin me run-time exceed error,

so i tried out the desi version

while ( scanf ( %d %d ), &a, &b ) != EOF )
{
//process
}

n this method works..


so nw wht is the correct way of terminating the input, what if i want the design to be like

while ( true )
{
cin >> a; cin >> b;
//process

if ( /*chk_condition */ )
break;
}

what should be the chk_condition over here

thx in anticipation.. :)