Page 86 of 93

### Re: time limit excede problem

Posted: Fri Oct 26, 2012 12:09 am
Don't read from a file. You can see a sample solution to problem 100 at:
http://uva.onlinejudge.org/index.php?op ... &Itemid=30

### Re: time limit excede problem

Posted: Fri Oct 26, 2012 9:47 pm

### Re: If you get WA in problem 100, read me before post!

Posted: Tue Nov 27, 2012 9:45 pm
My answer to problem 100 is pasted here on ideaone.

As you can see from the input and output, the program works as expected.

However, using the online judge I get "runtime error."

What is the problem?

Edit:

Ok, based on reading some previous posts I have made my program handle reversed ranges.

Updated code is here http://ideone.com/HK0ugg

However, I still get "runtime error." What is the problem?

### Re: If you get WA in problem 100, read me before post!

Posted: Wed Nov 28, 2012 10:00 am
Nevermind, I simply wasn't returning 0. It works

### 100 Runtime Error

Posted: Sun Dec 09, 2012 9:30 pm

Code: Select all

``````import java.util.*;

class Main {

public static void main(String[] args){
new Main().solveProblem();
}

public void solveProblem(){
final Scanner in = new Scanner(System.in);
while(in.hasNextInt()){
int i = in.nextInt();
int j = in.nextInt();
int[] values = new int[j-i+1];
for(int k = i;k <= j;k++){
values[k-i] = findSeqNum(k);
}
int most = getMax(values,j-i+1);
System.out.println(""+i+" "+j+" "+most);
}
in.close();
}

public int findSeqNum(int n){
int count = 1;
while(n != 1){
if(n%2 == 0)
n = n / 2;
else
n = 3 * n + 1;
count++;
}
return count;
}

public int getMax(int[] vals,int size){
int max = vals[0];
for(int i = 0;i < size;i++)
if(vals[i] > max)
max = vals[i];
return max;
}
}``````
So what am I doing wrong here?

### Re: 100 Runtime Error

Posted: Tue Dec 11, 2012 12:43 am
What happens if i>j?

### Newbie can't get AC

Posted: Thu Dec 13, 2012 12:27 am
Hello i am new to the UVA online Judge.
I copied the sample program that is a solution to problem 100.
But I get a compilation error ewvery time i submit that program.

This is the sample i try to get AC i found it on the site of UVA
What can be wrong?

program p100 ;
var
i, j: integer;
function getCL(N: integer): integer;
var k: integer;
begin
k := 1;
while N <> 1 do begin
if odd(N) then N := 3*N + 1
else N := N div 2;
k := k + 1;
end;
getCL := k;
end;
function getMaxCL(i, j: integer): integer;
var k: integer;
max, curCL: integer;
begin
max := 0;
for k:=i to j do begin
curCL := getCL(k);
if curCL > max then max := curCL;
end;
getMaxCL := max;
end;
begin
{\$IFNDEF ONLINE_JUDGE}
assign(input, 'input.txt');
reset(input);
assign(output, 'output.txt');
rewrite(output);
{\$ENDIF}
while not eof(input) do begin
write(i, ' ', j, ' ');
if i < j then
writeln(getMaxCL(i, j))
else
writeln(getMaxCL(j, i));
end;
{\$IFNDEF ONLINE_JUDGE}
close(input);
close(output);
{\$ENDIF}
end.

### Newbie can't get AC

Posted: Fri Dec 14, 2012 12:38 am
Can anyone post a program for problem 100 then got AC.
I tried the sample program but than got TLE and RTE.
I like to know what I'm doing wrong in my submissions.

Thanks

### Re: If you get WA in problem 100, read me before post!

Posted: Fri Dec 14, 2012 6:44 am

Code: Select all

``````/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package sample_java;

/**
*
* Problem: 100
*/
//

import java.io.IOException;
import java.util.StringTokenizer;

class Main
{
static String ReadLn (int maxLg)  // utility function to read from stdin
{
byte lin[] = new byte [maxLg];
int lg = 0, car = -1;
String line = "";

try
{
while (lg < maxLg)
{
if ((car < 0) || (car == '\n')) break;
lin [lg++] += car;

}
}
catch (IOException e)
{
return (null);
}

if ((car < 0) && (lg == 0)) return (null);  // eof
return (new String(lin, 0, lg));
}

int loop(int i)
{
int n=i;
int count=1;
while(n>1)
{
if(n%2==0)
{
n=n/2;
}
else
{
n=3*n+1;
}
count++;
}
return count;
}

int max_cycle(int j,int k)
{

int max=-1;
for(int i=j;i<k;i++)
{
int count=loop(i);
if(count>max)
{
max=count;
}
}
return max;
}

public static void main (String args[])  // entry point from OS
{
Main myWork = new Main();  // create a dinamic instance
myWork.Begin();            // the true entry point
}

void Begin()
{
String input;
StringTokenizer idata;
int a, b, min, max;

while ((input = Main.ReadLn (255)) != null)
{
idata = new StringTokenizer (input);
a = Integer.parseInt (idata.nextToken());
b = Integer.parseInt (idata.nextToken());
if (a < b) { min=a; max=b; } else { min=b; max=a; }

System.out.println (a + " " + b + " " + max_cycle(min, max));
}

}

}
``````
What could be the possible reason for RE for that code?

### Re: If you get WA in problem 100, read me before post!

Posted: Fri Dec 14, 2012 7:41 pm

### Re: If you get WA in problem 100, read me before post!

Posted: Sat Dec 15, 2012 4:17 am
now getting WA..:/

### Re: If you get WA in problem 100, read me before post!

Posted: Sat Dec 15, 2012 6:13 am
Input:

Code: Select all

``1 1``
AC output:

Code: Select all

``1 1 1``

### Re: If you get WA in problem 100, read me before post!

Posted: Sat Feb 09, 2013 8:19 pm
AC

### Re: If you get WA in problem 100, read me before post!

Posted: Mon Feb 11, 2013 11:03 pm
There is more than one case in the sample input and output. You should continue reading i and j until there are no more. Do a loop like:
while(cin >> i >> j) {
...
}

### input error in 3n+1 problem

Posted: Tue Feb 12, 2013 7:46 am
Hi everybody,

I was trying to solve 3n+1 exercise . I don't know how to get input.
can anybody help?