hdu 5655 CA Loves Stick
CA Loves Stick
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 981 Accepted Submission(s): 332
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)
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
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
题意:给你四条边,判断是否能组成一个四边形
题解:任意三边之和大于第四边(第四边为最大边) a+b+c>=d; 转化为减法a+b>=d-c;
注意:1、三个数相加可能超64位 2、如果边为0 就输出no
#include<stdio.h> #include<string.h> #include<vector> #include<map> #include<queue> #include<stack> #include<cstdio> #include<string> #include<math.h> #include<algorithm> #define LL long long #define PI atan(1.0)*4 #define DD double #define MAX 450 #define mod 10003 #define INF 0x3f3f3f3f using namespace std; unsigned __int64 s[6]; int main() { int t; unsigned __int64 n,m,a,b,c,d; scanf("%d",&t); while(t--) { scanf("%I64u%I64u%I64u%I64u",&a,&b,&c,&d); if(a==0||b==0||c==0||d==0) { printf("No\n"); continue; } s[0]=a;s[1]=b;s[2]=c;s[3]=d; sort(s,s+4); if(s[1]+s[0]>=s[3]-s[2]) printf("Yes\n"); else printf("No\n"); } return 0; }