Problem Description
CA loves to play with sticks.
One day he receives four pieces of sticks, he wants to know these sticks can spell a quadrilateral.
(What is quadrilateral? Click here: https://en.wikipedia.org/wiki/Quadrilateral)
Input
First line contains T denoting the number of testcases.
T testcases follow. Each testcase contains four integers a,b,c,d in a line, denoting the length of sticks.
1≤T≤1000, 0≤a,b,c,d≤263−1
Output
For each testcase, if these sticks can spell a quadrilateral, output “Yes”; otherwise, output “No” (without the quotation marks).
Sample Input
2
1 1 1 1
1 1 9 2
Sample Output
Yes
No
Source
BestCoder Round #78 (div.2)
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main()
{
int t;
scanf("%d",&t);
long long a[4];
while(t--){
for(int i=0;i<4;i++){
scanf("%I64d",&a[i]);
}
sort(a,a+4);
if(a[3]-a[2]-a[1]>=a[0]){
printf("No\n");
}
else if((!a[0])||(!a[1])||(!a[2])||(!a[3])){
printf("No\n");
}
else{
printf("Yes\n");
}
}
return 0;
}
一直WA,后来看一大神的分析才知道是数据范围的问题。
long long的最大值:9223372036854775807
long long的最小值:-9223372036854775808
而2^63=9223372036854775808,
所以 2^63-1即long long 的最大范围
所以不能用加的
所以任意三边之和大于第四边就不能用加的,移动一下,改为a[3]-a[2]-a[1]<a[0](已从小到大sort)
另外一个边界是0,如果a[0]==0,那肯定不能构成四边形