HDU - 5655 CA Loves Stick
2016-04-03 21:00
369 查看
1.题面
http://acm.hdu.edu.cn/showproblem.php?pid=56552.题意
给你四个木棍的长度,问你这四根木棍能不能组成一个四边形。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; }
相关文章推荐
- Spring的依赖注入(DI)三种方式
- 算法训练 判定数字
- Android入门(十一)SQLite CURD
- Android入门(十)SQLite创建升级数据库
- 每天一条linux命令
- 关于scanf和scanf_s的注意事项及问题
- Android之SurfaceView使用总结
- 2016.4.3 servlet学习
- 文本框滚动条
- Java并发工具类CountDownLatch和CyclicBarrier
- VirtualBox-5.0.16设置windows与ubuntu的共享文件夹
- 算法训练 字符串逆序
- Android入门(九)文件存储与SharedPreferences存储
- java第5章学习总结
- request 和 response之间实现servlet线程非阻塞
- Linux Shell笔记
- Spring在web请求中定义编码(org.springframework.web.filter.CharacterEncodingFilter)
- Liferay 6.1开发学习(四):Service Builder
- 蛇形矩阵
- 浅谈webWorker