11479 - Is this the easiest problem?

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

Moderator: Board moderators

Hasselli
New poster
Posts: 22
Joined: Mon Apr 16, 2012 8:08 pm
Contact:

Re: 11479 - Is this the Easiest Problem?

Post by Hasselli »

got AC
Last edited by Hasselli on Fri Apr 27, 2012 10:38 am, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11479 - Is this the Easiest Problem?

Post by brianfry713 »

Use long long instead of int.
Check input and AC output for thousands of problems on uDebug!
renatov
New poster
Posts: 20
Joined: Fri Sep 21, 2012 6:33 am

Re: 11479 - Is this the Easiest Problem?

Post by renatov »

brianfry713 wrote:Use long long instead of int.
You are right, I've just got an "Accepted" when I changed int to long long. I tested if I could have declared just as long, and I got accepted too. So, it doesn't have to be long long, it can be just long. It seems that UVA's gcc specifies 16 bits for int declarations, so we must use long or greater in order to get 32 bits variables and have our code Accepted.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11479 - Is this the Easiest Problem?

Post by brianfry713 »

UVA's g++ and gcc have int=32 bits, long=64 bits, long long=64 bits. The reason int doesn't work for this problem is if you try and add or subtract 32-bit signed int's you may get overflow.
Check input and AC output for thousands of problems on uDebug!
darksk4
New poster
Posts: 13
Joined: Sun Jul 29, 2012 7:10 pm

Re: 11479 - Is this the Easiest Problem?

Post by darksk4 »

why is this WA? the input is right the variable is long long.

Code: Select all

#include<iostream>

using namespace std;


int main(){

	long long cycle, a, b ,c;


	cin >> cycle;	

	for(int counter = 0 ; counter < cycle; counter++){
		cin >> a >> b >> c;
		cout <<  "Case " << counter + 1 << ": ";			
			if(( a + b > c)&& (a + c > b) && (b + c > a)){


				if( a == b && b == c)
					cout << "Equilateral";
	
				else if((a == b) || (b== c) || (a == c))
					cout << "Isosceles";

				else
					cout << "Scanlene";
			}
			else
				cout << "Invalid";

	cout << endl;
		
	}




	return 0;
}

renatov
New poster
Posts: 20
Joined: Fri Sep 21, 2012 6:33 am

Re: 11479 - Is this the Easiest Problem?

Post by renatov »

To check if the sides form a triangle, you should performe 2 tests:

1. See if every input is greater than zero
2. | b - c | < a < b + c
renatov
New poster
Posts: 20
Joined: Fri Sep 21, 2012 6:33 am

Re: 11479 - Is this the Easiest Problem?

Post by renatov »

brianfry713 wrote:UVA's g++ and gcc have int=32 bits, long=64 bits, long long=64 bits. The reason int doesn't work for this problem is if you try and add or subtract 32-bit signed int's you may get overflow.
You are right. I compiled a simple program to test C data type under Linux, with GCC 4.4.5-8, and here is the output:

Code: Select all

             DATA TYPE | printf() |  scanf() | BITS |               MINIMO |               MAXIMO | PRECISAO
                  char |      c/s |      c/s |    8 |                 -128 |                  127 |        0
           signed char |      hhd |      hhd |    8 |                 -128 |                  127 |        0
         unsigned char |      hhu |      hhu |    8 |                    0 |                  255 |        0
             short int |       hd |       hd |   16 |               -32768 |                32767 |        0
    unsigned short int |       hu |       hu |   16 |                    0 |                65535 |        0
                   int |        d |        d |   32 |          -2147483648 |           2147483647 |        0
           (octal) int |        o |        o |   32 |                    0 |          17777777777 |        0
     (hexadecimal) int |      x/X |      x/X |   32 |                    0 |             7FFFFFFF |        0
          unsigned int |        u |        u |   32 |                    0 |           4294967295 |        0
              long int |       ld |       ld |   32 |          -2147483648 |           2147483647 |        0
     unsigned long int |       lu |       lu |   32 |                    0 |           4294967295 |        0
         long long int | I64d/lld | I64d/lld |   64 | -9223372036854775808 |  9223372036854775807 |        0
unsigned long long int | I64u/llu | I64u/llu |   64 |                    0 | 18446744073709551615 |        0
                 float |      e/f |      e/f |   32 |         1.175494e-38 |         3.402823e+38 |        6
                double |    le/lf |    le/lf |   64 |        2.225074e-308 |        1.797693e+308 |       15
           long double |    Le/Lf |    Le/Lf |   96 |       3.362103e-4932 |       1.189731e+4932 |       18
UVA's gcc version is 4.5.3, but I think there are no differences. I compiled this program in Windows too and the values are the same, except for long double. Either %Le and %Lf aren't the proper way to specify data type in printf(), or Windows can't handle this data type yet. Here is long double output in Windows:

Code: Select all

             DATA TYPE | printf() |  scanf() | BITS |               MINIMO |               MAXIMO | PRECISAO
           long double |    Le/Lf |    Le/Lf |   96 |        0.000000e+000 |       -1.#QNAN0e+000 |       -1
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11479 - Is this the Easiest Problem?

Post by brianfry713 »

You can submit a code like this, if it returns RE a check failed, if it returns WA the checks passed.

Code: Select all

#include <stdio.h>
#include <stdlib.h>

//uva g++ and gcc int=4,long=8,long long=8
//My UNIX g++ int=4,long=4,long long=8

int main(void) {
  if(sizeof(int)!=4) return 1;
  if(sizeof(long)!=8) return 1;
  if(sizeof(long long)!=8) return 1;
  printf("done\n");
  return 0;
}
For portability on one of my linux or UNIX machines I always use long long instead of long. The size of each data type is going to vary somewhat depending on your machine and your compiler.
http://en.wikipedia.org/wiki/C_data_types
Check input and AC output for thousands of problems on uDebug!
darksk4
New poster
Posts: 13
Joined: Sun Jul 29, 2012 7:10 pm

Re: 11479 - Is this the Easiest Problem?

Post by darksk4 »

Can I ask? What is the Difference between this two codes?

my bad XD
Thanks brianfry713 for correcting my post hahah
Last edited by darksk4 on Thu Oct 04, 2012 7:55 am, edited 1 time in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11479 - Is this the Easiest Problem?

Post by brianfry713 »

The first code misspelled Scalene.
Check input and AC output for thousands of problems on uDebug!
mazid
New poster
Posts: 6
Joined: Sun Dec 23, 2012 9:16 am

11479 - Is this the easiest problem? getting WA

Post by mazid »

Please help. why I m getting WA??
AC :lol: :D
Thanks brianfry713
Last edited by mazid on Sat Apr 06, 2013 7:35 pm, edited 2 times in total.
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11479 - Is this the easiest problem? getting WA

Post by brianfry713 »

use long long
Check input and AC output for thousands of problems on uDebug!
Kff7
New poster
Posts: 1
Joined: Fri Oct 25, 2013 12:01 am

11479 - Is this the easiest problem?

Post by Kff7 »

Please, can anyone tell me the fault??
I'm allways get "wrong answer"

Code: Select all

import java.io.*;
import java.util.*;

public class Main{
  
  public static void main(String[] args){
  
  Scanner scan = new Scanner(System.in);
  long[] seite = new long[3];
  int t;
  
  
  do{
    t = scan.nextInt();
  }while(t>19 || t < 1);
  
  
  for(int i=0; i<t; i++){
  
    seite[0] = scan.nextInt();
    seite[1] = scan.nextInt();
    seite[2] = scan.nextInt();
    
    Arrays.sort(seite);
    
    
    
    if(seite[0] <= 0 || seite[1] <= 0 || seite[2] <=0){
      System.out.println("Case 1: Invalid");
    }
    
    else if(seite[0] + seite[1] <= seite[2]){
      System.out.println("Case 1: Invalid");
    }
    
    else if(seite[0] == seite[1] && seite[0] == seite[2]){
      System.out.println("Case 2: Equilateral");
    }
    
    else if(seite[0] == seite[1] || seite[1] == seite[2]){
      System.out.println("Case 3: Isosceles");
    }
    
    else{
      System.out.println("Case 4: Scalene");
    }
  
  }
  
  }
}
brianfry713
Guru
Posts: 5947
Joined: Thu Sep 01, 2011 9:09 am
Location: San Jose, CA, USA

Re: 11479 - Is this the easiest problem?

Post by brianfry713 »

Input:

Code: Select all

4
1 2 5
1 2 5
1 2 5
1 2 5
Output should be:

Code: Select all

Case 1: Invalid
Case 2: Invalid
Case 3: Invalid
Case 4: Invalid
Check input and AC output for thousands of problems on uDebug!
heera.brur
New poster
Posts: 1
Joined: Mon Sep 15, 2014 1:44 pm

Re: 11479 - Is this the easiest problem?

Post by heera.brur »

Why wrong answer on following code ?

Code: Select all

#include <stdio.h>
int main() {
    long long int i,m,a,b,c;
    scanf("%lld",&m);


    for(i=1; i<=m; i++) {
        scanf("%lld %lld %lld",&a,&b,&c);

        printf("Case %lld: ", i);

        if(a<=0 || b<=0 || c<=0) {
            printf("Invalid\n");
            continue;
        }

        if(a==b && b==c) {
            printf("Equilateral\n");
        } else if(a==b || b==c || c==a) {
            printf("Isosceles\n");
        } else if((a+b)>c && (b+c)>a && (c+a)>b) {
            printf("Scalene\n");
        } else {
            printf("Invalid\n");
        }
    }

    return 0;
}



Post Reply

Return to “Volume 114 (11400-11499)”