HDU5655

来源:互联网 发布:微博怎么设置个性域名 编辑:程序博客网 时间:2024/05/05 10:05

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≤2^63−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

Explanation

该题给我们四条线段的长度问是否能拿这四条线段构成一个四边形
我们考虑一个极限情况,当三条线段共线首尾连接时,第四条边无论多长都无法构成四边形,但在当连接后的三条边任意轻微改变其中两条边的夹角就存在一条边可以与其构成四边形了,那么第四条边则为最长边,且其长度满足小于其他三边之和

Code

#include <stdio.h>#include <algorithm>using namespace std;int main(){    int t;    scanf("%d",&t);    while(t--){        long long a[5];        scanf("%lld%lld%lld%lld",&a[0],&a[1],&a[2],&a[3]);        sort(a,a+4);        if(a[0]==0)            printf("No\n");        //若存在长度为0的边则一定无法构成四边形        else{            if(a[3]-a[2]-a[1]<a[0])                printf("Yes\n");            else                printf("No\n");              /*这里要注意数据超范围           1> 对三条边作和则会超出long long范围           2> 最大边减去另外三条边也会超出long long范围 */        }    }    return 0;}
原创粉丝点击