11479 - Is this the easiest problem?
Moderator: Board moderators
Re: 11479 - Is this the Easiest Problem?
got AC
Last edited by Hasselli on Fri Apr 27, 2012 10:38 am, edited 1 time in total.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11479 - Is this the Easiest Problem?
Use long long instead of int.
Check input and AC output for thousands of problems on uDebug!
Re: 11479 - Is this the Easiest Problem?
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 wrote:Use long long instead of int.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11479 - Is this the Easiest Problem?
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!
Re: 11479 - Is this the Easiest Problem?
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;
}
Re: 11479 - Is this the Easiest Problem?
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
1. See if every input is greater than zero
2. | b - c | < a < b + c
Re: 11479 - Is this the Easiest Problem?
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: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.
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
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
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11479 - Is this the Easiest Problem?
You can submit a code like this, if it returns RE a check failed, if it returns WA the checks passed.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
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;
}
http://en.wikipedia.org/wiki/C_data_types
Check input and AC output for thousands of problems on uDebug!
Re: 11479 - Is this the Easiest Problem?
Can I ask? What is the Difference between this two codes?
my bad XD
Thanks brianfry713 for correcting my post hahah
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.
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11479 - Is this the Easiest Problem?
The first code misspelled Scalene.
Check input and AC output for thousands of problems on uDebug!
11479 - Is this the easiest problem? getting WA
Please help. why I m getting WA??
AC
Thanks brianfry713
AC
![:lol:](./images/smilies/icon_lol.gif)
![:D](./images/smilies/icon_biggrin.gif)
Thanks brianfry713
Last edited by mazid on Sat Apr 06, 2013 7:35 pm, edited 2 times in total.
-
- 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
use long long
Check input and AC output for thousands of problems on uDebug!
11479 - Is this the easiest problem?
Please, can anyone tell me the fault??
I'm allways get "wrong answer"
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");
}
}
}
}
-
- Guru
- Posts: 5947
- Joined: Thu Sep 01, 2011 9:09 am
- Location: San Jose, CA, USA
Re: 11479 - Is this the easiest problem?
Input:Output should be:
Code: Select all
4
1 2 5
1 2 5
1 2 5
1 2 5
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!
-
- New poster
- Posts: 1
- Joined: Mon Sep 15, 2014 1:44 pm
Re: 11479 - Is this the easiest problem?
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;
}