Page 91 of 93

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

Posted: Thu Jan 30, 2014 6:37 pm
by amzad.ethan
Here is my code. can anyone tell me why I have got WA???

Code: Select all

import java.util.Scanner;
class Main
{
  public static void main(String [] args)
  {
    Scanner e=new Scanner(System.in);
    while (e.hasNext())
    {
      int p=0;
      int r=0;
      int i= e.nextInt();
      int j = e.nextInt();
      if (j<i)
      {
        p=i;
        r=j;
        int temp=i;
        i=j;
        j=temp;
      }
      else 
      {
        p=i;
        r=j;
      }
      int [] a=new int [j+1];
      int m=i;
      while (m<=j)
      {
        int n=m;
        int c=1;
        while (n!=1)
        {
          if (n%2!=0)
          {
            n=3*n+1;
          }
          else 
          {
            n=n/2;
          }
          c++;
        }
        a[m]=c;
        m++;                  
      }
      int max=a[0];
      int c=1;
      while (c<j)
      {
        if (max<a[c])
        {
          max=a[c];
        }
        c++;
      }
      System.out.println(p+" "+r+" "+max);
    }
  }
}

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

Posted: Thu Jan 30, 2014 10:32 pm
by brianfry713
Input:

Code: Select all

1 1
1 2
2 2
Correct output:

Code: Select all

1 1 1
1 2 2
2 2 2

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

Posted: Tue Apr 22, 2014 7:39 pm
by gautamsingh
I submitted this code about 20 minutes ago and still no verdict is being shown. Submission ID is 13533745 and same for 13533473 which was submitted about an hour ago. (this one's incorrect though)

Code: Select all

#include <algorithm>
#include <cstdio>
#define INF 9999999
using namespace std;
int a[1000050];
int coll(int p)
{
	int c = 1, temp = p;
	if (a[p] != 0)
		return a[p];
	else
	{
		while (temp != 1)
		{
			if (temp % 2 == 0)
				temp /= 2;
			else
				temp = 3*temp + 1;
			++c;	
		}
		a[p] = c;
	}
	return c;
}	
int main() 
{
	int i, j;
	while ((scanf ("%d%d", &i, &j)) != EOF)
	{
		int ans = -INF;
		for (int p = min(i, j); p <= max(i, j); ++p)
			ans = max(ans, coll(p));
		printf ("%d %d %d\n", i, j, ans);	
	}
	return 0;
}

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

Posted: Tue Apr 22, 2014 8:27 pm
by brianfry713
The judge is currently having issues, try again later.

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

Posted: Wed Apr 23, 2014 6:06 am
by gautamsingh
brianfry713 wrote:The judge is currently having issues, try again later.
I got it accepted. The judge was too slow. Thanks for your help. Should I delete the code posted above?

Re: 100

Posted: Thu Jun 19, 2014 4:35 am
by samoel_stt
I keep getting wrong answer, what i am doing wrong?

Code: Select all

#include <stdio.h>
#include <stdlib.h>
int proceso(long num){
    int cont = 1;
    while( num != 1){
        if (num % 2 == 1) num = 3*num+1;
        else num = num/2;
        cont++;
    }   
    return cont;
}
void ciclo3n(int n1,int n2, int *max){
    int i;
    int maximo = proceso(n1);
    for(i=n1+1;i<=n2;i++){
        int cur = proceso(i);
        if(cur > maximo)
            maximo = cur;        
    }
    *max = maximo;
}
int main(int argc, char** argv) {
    long n1=0,n2=0;
    for(;;){
        if ( scanf("%d %d",&n1,&n2) == EOF) break;
        if (0<n1 && n1<1000000 && 0<n2 && n2<1000000){
            if (n1 > n2){
                int aux = n1;
                n1 = n2;
                n2 = aux;
            }
            int max=0;
            ciclo3n(n1,n2,&max);
            printf("%d %d %d\n",n1,n2,max);
        }        
    }
    return 0;
}

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

Posted: Thu Jun 19, 2014 10:45 am
by Shadow_Coder
Given below is my code. It works for all the test cases which I've tried, it swaps i and j, if i>j as well. Yet, it's still getting WA. Any suggestions?

Code: Select all

#include <iostream>
#include <algorithm>
using namespace std;

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

int main() {
    int i, j, I, J, Max;
    while(!cin.eof()){
    	cin >> i >> j;
    	cout << i << " " << j << " "; 
    	I = min(i, j); J = max(i, j);
    	Max = -1;
    	for(int k=I;k<=J;k++){
    		Max = max(Max, cycleLength(k)); 
    	}
    	cout << Max;
    	if(!cin.eof()) { cout << "\n"; }
    }
	return 0;
}

Re: 100

Posted: Thu Jun 19, 2014 10:20 pm
by brianfry713
Input:

Code: Select all

9 1
AC output:

Code: Select all

9 1 20

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

Posted: Thu Jun 19, 2014 10:21 pm
by brianfry713
Change your loop to while(cin >> i >> j) {
Don't use cin.eof() while reading integers because the last line of the input will end with a newline char.
Also make sure you always print a newline char at the end of the last line.

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

Posted: Fri Jun 20, 2014 3:51 pm
by Shadow_Coder
I got AC, but tell me, why do we need a newline character at the end of the last line, when it is not so in the sample output?

Re: 100

Posted: Sat Jun 21, 2014 8:28 am
by villainoftime
Why am I getting wrong answer, please??

#include<stdio.h>


int collatz(int n);
int cyclecounter(int n);

int main()
{
int i, j, cycle, MAX;
while(scanf("%d %d", &i, &j)==2)
{
MAX=0;
int n=i, p;
if(i>j)
p=-1;
else
p=1;
for(; n!=j; n+=p)
{
int cycle=cyclecounter(n);
if(MAX<cycle)
MAX=cycle;
}
printf("%d %d %d\n", i, j, MAX);
}
return 0;
}




int collatz(int n)
{
if(n%2==0)
return(n/2);
return(3*n+1);
}


int cyclecounter(int n)
{
int cycle=0;
n=collatz(n);
cycle++;
while(n!=1)
{
n=collatz(n);
cycle++;
}
return(cycle+1);
}

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

Posted: Mon Jun 23, 2014 8:55 pm
by brianfry713
If you want to get AC, always print a newline char at the end of the last line.

Re: 100

Posted: Mon Jun 23, 2014 9:32 pm
by brianfry713
Input 1 1, output should be 1 1 1

UVa:100 why WA?

Posted: Thu Jun 26, 2014 4:36 pm
by sampad74
Got AC

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

Posted: Thu Jun 26, 2014 7:34 pm
by brianfry713
i or j might be larger than 10000