HDU 5655 CA Loves Stick
2016-04-03 11:36
218 查看
题目地址:http://acm.hdu.edu.cn/showproblem.php?pid=5655
思路:只要有一个边大于其他三边的和就不能组成四边形,可以先排序一下,然后做减法,做加法有可能超long long
AC代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
const int inf = 0x3f3f3f3f;//1061109567
typedef long long LL;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
LL a[4];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
bool flag = false;
for(int i=0; i<4; i++)
{
scanf("%I64d",&a[i]);
if(a[i] == 0)
flag = true;
}
if(flag)
{
printf("No\n");
continue;
}
sort(a,a+4);
LL sum = a[3];
int i;
for(i=0; i<3; i++)
{
sum -= a[i];
if(sum < 0)
break;
}
if(i != 3)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
思路:只要有一个边大于其他三边的和就不能组成四边形,可以先排序一下,然后做减法,做加法有可能超long long
AC代码:
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <cstring>
#include <climits>
#include <cmath>
#include <cctype>
const int inf = 0x3f3f3f3f;//1061109567
typedef long long LL;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
using namespace std;
LL a[4];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
bool flag = false;
for(int i=0; i<4; i++)
{
scanf("%I64d",&a[i]);
if(a[i] == 0)
flag = true;
}
if(flag)
{
printf("No\n");
continue;
}
sort(a,a+4);
LL sum = a[3];
int i;
for(i=0; i<3; i++)
{
sum -= a[i];
if(sum < 0)
break;
}
if(i != 3)
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
相关文章推荐
- 向量叉乘与叉乘矩阵
- 图的邻接表存储
- IOS成长之路-使用xib界面与和代码相关联的方法
- JavaScript深入理解函数参数列表及“不存在重载”
- DuiLib(3)——DuiLib与MFC嵌套攻略
- Java 中带参带返回值方法的使用
- 冒泡排序
- 迷宫寻宝(一) ---- 状态压缩
- Ghost后 windows 2008 不能启动
- IOS开发 使用XIB自定义一个UIView
- 二叉树
- phpcms authkey注入中转脚本
- CSU 1716(字符串)
- MingW Cmake bulid OpenCV
- 【笔记】 《js权威指南》- 第8章 函数 - 8.2 - 8.3 函数调用 实参 形参
- iOS开发UI篇—xib的简单使用
- pom文件详解
- 队列
- 在网络请求中使用实体
- PHPCMSV9 AuthKey泄露导致注入EXP