HDU 5655 CA Loves Stick 水题

题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5656

CA Loves Stick

 

 Accepts: 381   Submissions: 3204

 Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 262144/262144 K (Java/Others)

问题描述

CA喜欢玩木棍。

有一天他获得了四根木棍,他想知道用这些木棍能不能拼成一个四边形。(四边形定义:https://en.wikipedia.org/wiki/Quadrilateral

输入描述

第一行TT,表示有TT组数据。

接下来TT组数据,每组数据包含四个整数a,b,c,da,b,c,d,分别为四根木棍的长度。

1 le T le 1000,~0 le a,b,c,d le 2^{63}-11≤T≤1000, 0≤a,b,c,d≤263​−1

输出描述

对于每个数据,如果能拼成一个四边形,输出“Yes”;否则输出“No”(不包括双引号)。

输入样例

2

1 1 1 1

1 1 9 2

输出样例

Yes

No

题解:

-2^63:  xb1000...0(63个0) ,即 -0;(LL)1<<63

   0:  xb0000...0(64个0),即+0;

  最小三边和大于最大边即可构成4边形

  但数据很多会爆,所以要做些处理

代码:

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

typedef long long LL;
const LL t_63 = ((LL)1 << 63);
LL a[11];


int main() {
    int tc;
    scanf("%d", &tc);
    LL x = 0;
    while (tc--) {
        for (int i = 0; i < 4; i++) scanf("%lld", a + i);
        sort(a, a + 4);
        if (a[0]>0 && a[0] - t_63 + a[1]>a[3] - a[2] - t_63) {
            printf("Yes
");
        }
        else printf("No
");
    }
    return 0;
}
View Code
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;

typedef long long LL;
LL a[11];


int main() {
    int tc;
    scanf("%d", &tc);
    while (tc--) {
        for (int i = 0; i < 4; i++) scanf("%lld", a + i);
        sort(a, a + 4);
        if (a[0]>0&&a[0]>a[3] - a[2]-a[1]) {
            printf("Yes
");
        }
        else printf("No
");
    }
    return 0;
}
View Code
原文地址:https://www.cnblogs.com/fenice/p/5369872.html