Thanks changed the code to long int and solved it
Just for curiosity, well the choice I made for float types is because they do carry a more representative type than integers at least when I looked at floats.h
FLT_MAX=340282346638528859811704183484516925440.000000
while max integers are short unless you are using long int with a word of 64 bits(limits.h)
So float is able to carry much more...but I'm having trouble though in others problems with operations on big numbers like float(this is not the first time). how can I store a number like 11111111111111111111111111111111111111111111111111111111111.0 on a long double for instance? any tips?
const maxn=1000000;
var
i,a,b,max:longint;
l:array[0..maxn] of longint;
function tryl(n:int64;t:longword):longint;
var
nextn:int64;len:longint;tmp:extended;
begin
if n<=maxn then begin
if l[n]>0 then tryl:=l[n]+t else begin
if n mod 2=0 then tmp:=n div 2 else tmp:=n*3+1;
nextn:=round(tmp);
len:=tryl(nextn,t+1);
tryl:=len;
if n<=maxn then l[n]:=len-t;
end;
end else begin
if n mod 2=0 then tmp:=n div 2 else tmp:=n*3+1;
nextn:=round(tmp);
len:=tryl(nextn,t+1);
tryl:=len;
if n<=maxn then l[n]:=len-t;
end;
end;
begin
l[1]:=1;
for i:=2 to maxn do begin
l[i]:=tryl(i,0);
end;
while true do begin
if eof() then break;
readln(a,b);
max:=0;
if a<=b then begin
for i:=a to b do begin
if l[i]>max then max:=l[i];
end;
end else begin
for i:=b to a do begin
if l[i]>max then max:=l[i];
end;
end;
writeln(a,' ',b,' ',max);
end;
end.
Hi,
I am new to online-judge.uva.es . Just to get started , i solved the 3n+1 problem which works perfectly on my machine where i use Dev-C++ 4.9.9.2 IDE and the OS is Windows XP and the language im using to code is C.
Dev-C++ is using gcc as the compiler and my program compiles without any errors or warnings on my machine but when i submit it via submit-o-matic i get a compile error.
We like to keep the forums as clean as possible, to make it easier to find information in them. With the great amount of problems and users trying to solve them, we issued a simple rule: if a thread exists for a particular problem, please use it and don't create a new one. For problem 100 there already exists an enormous amount of threads, so it would have been better if you used one of them.
When you submit your code to the UVA judge, the judge will send you a response email with the result. In case of a compiler error, it will send you the compiler output, so you can use that to debug your code. You may have to enable the appropriate option on your user profile.
In this particular case, the function call to calculate_cycle_length() appears in main() before it's declared or defined. So either put a declaration at the top of your code or change the order of the two fumctions.
The biggest problem with most problems is not how to solve the problem, but how to not solve what is not the problem.
I am getting a WA. I dont know why i am getting it because the code is working perfectly fine on my machine.I using C language to code and Dev-C++ 4.9.9.2 as the IDE .
Thanks for the reply little_joey . The compiler error goes when I remove the // comments from my code and also as you correctly said by changing the order of the functions. I can understand that some compilers like the one at uva can be very strict about function declarations and the order in which they are defined but why doesnt the compiler support these comments ??.
Anyways,now im getting a WA and following your advice ive posted my query here. http://online-judge.uva.es/board/viewto ... highlight=
About comments: the double slash ("//") is not valid in traditional C, so either use the "/*" - "*/" pair, or submit your code as C++.
I notice that you store all input in an array, before calculating and printing the results. This is possible, but better is to get the cases one at the time and immediately calculate and print the results. The number of input cases in undetermined, and 1000 may be to small.
Your answer for the case "1 1" is incorrect. Think about it.
Why do you print the newline at the beginning of your output? You'll get presentation error, even if the answer would be correct. The newline belongs at the end of your output line.
Read the documentation on the scanf() function. "while(scanf("%ld%ld",&i,&)!=EOF)" might work in some cases, but you should use "while(scanf(..)==2)": scanf returns the number of successfully read items, which is two in this case.
Hope it helps.
The biggest problem with most problems is not how to solve the problem, but how to not solve what is not the problem.