hdu5655-BestCoder Round #78 (div.2)
2016-07-15 19:27
274 查看
题目:
CA Loves Stick
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2126 Accepted Submission(s): 612
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≤2e63−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)
题意:
给4条边,判断是否构成四边形。思路很简单,先排序,最小三边a+b+c>d即可。
但是注意这里的数据范围:0≤a,b,c,d≤2e63−1
首先,需要特判a, b, c, d是否小于等于0
其次,注意每一条边都有可能到long long的上界,用了unsigned long long 也只能承受一次相加。
可以变形一下:a>d-c-b
挺坑的,注意数据范围就不会WA这么多次了
代码:
我这样,也过了(–)..
CA Loves Stick
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)
Total Submission(s): 2126 Accepted Submission(s): 612
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≤2e63−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)
题意:
给4条边,判断是否构成四边形。思路很简单,先排序,最小三边a+b+c>d即可。
但是注意这里的数据范围:0≤a,b,c,d≤2e63−1
首先,需要特判a, b, c, d是否小于等于0
其次,注意每一条边都有可能到long long的上界,用了unsigned long long 也只能承受一次相加。
可以变形一下:a>d-c-b
挺坑的,注意数据范围就不会WA这么多次了
代码:
#include <iostream> #include <cstring> #include <algorithm> const int maxn = 4; unsigned long long arr[maxn]; using namespace std; int main(){ int n; while(cin>>n){ for(int i=0; i<n; i++){ memset(arr, 0, sizeof(arr)); cin>>arr[0]>>arr[1]>>arr[2]>>arr[3]; sort(arr, arr+4); if(arr[0]==0||arr[1]==0||arr[2]==0||arr[3]==0) {cout<<"No"<<endl; continue;} if(arr[0]>arr[3]) cout<<"Yes"<<endl; else if(arr[0]+arr[1]>arr[3]) cout<<"Yes"<<endl; else if(arr[0]+arr[1]+arr[2]>arr[3]) cout<<"Yes"<<endl; else cout<<"No"<<endl; } } return 0; }
我这样,也过了(–)..
相关文章推荐
- 线程与进程的区别
- c#——Winform PropertyGrid使用
- 依赖倒置原则详解--七大面向对象设计原则(3)
- 安卓手机测试常见BUG
- [Leetcode]303. Range Sum Query - Immutable
- 【poj2741】 Colored Cubes
- 【NOIP模拟】修路
- POJ 1062 昂贵的聘礼
- 【POJ3277】City Horizon,线段树
- JZOJ1732. 消息传播
- 《编程之法》1.3字符串的全排列,组合,重复排列,八皇后问题
- SAP各种冲销凭证
- Summer day 4
- Linked List Cycle II
- Android布局自我理解与总结
- ubuntu下deb包的安装方法
- Linux启用和配置Java
- ShareSDK QQ分享失败的坑
- FloatingActionButton控件初步使用
- codeforces 696B B. Puzzles(树形dp+概率)