您的位置:首页 > 其它

HDU - 5655 CA Loves Stick

2016-04-03 21:00 369 查看

1.题面

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

2.题意

给你四个木棍的长度,问你这四根木棍能不能组成一个四边形。

3.思路

四边形成立的条件比较简单,就是任意三边之和大于第四边。

但是这道题目有两个坑。

一是输入的四条边中可能会出现长度为0的边。

二是四个数据都比较大,直接加减都容易爆long long。我的解决方案是使用unsighed long long,sort后判断a[0]+a[1] < a[2] + a[3]。

4.代码

/*****************************************************************
> File Name: tmp.cpp
> Author: Uncle_Sugar
> Mail: uncle_sugar@qq.com
> Created Time: 2016年04月02日 星期六 19时04分08秒
*****************************************************************/
# include <cstdio>
# include <cstring>
# include <cmath>
# include <cstdlib>
# include <climits>
# include <iostream>
# include <iomanip>
# include <set>
# include <map>
# include <vector>
# include <stack>
# include <queue>
# include <algorithm>
using namespace std;

const int debug = 1;
const int size  = 5000 + 10;
const int INF = INT_MAX>>1;
typedef unsigned long long ll;

int main()
{
std::ios::sync_with_stdio(false);cin.tie(0);
int i,j;
int T;
cin >> T;
while (T--){
ll r[4];
for (i=0;i<4;i++){
cin >> r[i];
}
sort(r,r+4);
if (r[0]>0&&r[0]+r[1]>r[3]-r[2])
cout << "Yes\n";
else
cout << "No\n";
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: