CA Loves Stick HDU - 5655
2017-08-02 20:32
176 查看
题目大意:意思非常简单,就是给你四个木棒,是否能用这四个木棒拼成一个四边形
解题思路:只需要判断最小的三条边的和是否大于第四条边就行了。但是数据给的最大是long long int,所以不能直接比较,转化一下,还有需要判断木棒中 不能有0
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)
InputFirst line contains TT denoting
the number of testcases.
TT testcases
follow. Each testcase contains four integers a,b,c,da,b,c,d in
a line, denoting the length of sticks.
1≤T≤1000, 0≤a,b,c,d≤263−11≤T≤1000, 0≤a,b,c,d≤263−1
OutputFor each testcase, if these sticks can spell a quadrilateral, output "Yes"; otherwise, output "No" (without the quotation marks).
Sample Input
Sample Output
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long int a[5];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int f1,f2,f3,f4,f5,f6;
for(int i=0;i<4;i++)
scanf("%lld",&a[i]);
sort(a,a+4); //从小到大排序
if(a[0]==0) //有0 肯定不能组成四边形
{
printf("No\n");
continue;
}
if(a[0]>a[3]-a[1]-a[2]) //判断最小的三条边是否大于第四条边
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
解题思路:只需要判断最小的三条边的和是否大于第四条边就行了。但是数据给的最大是long long int,所以不能直接比较,转化一下,还有需要判断木棒中 不能有0
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)
InputFirst line contains TT denoting
the number of testcases.
TT testcases
follow. Each testcase contains four integers a,b,c,da,b,c,d in
a line, denoting the length of sticks.
1≤T≤1000, 0≤a,b,c,d≤263−11≤T≤1000, 0≤a,b,c,d≤263−1
OutputFor 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
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
long long int a[5];
int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int f1,f2,f3,f4,f5,f6;
for(int i=0;i<4;i++)
scanf("%lld",&a[i]);
sort(a,a+4); //从小到大排序
if(a[0]==0) //有0 肯定不能组成四边形
{
printf("No\n");
continue;
}
if(a[0]>a[3]-a[1]-a[2]) //判断最小的三条边是否大于第四条边
printf("Yes\n");
else
printf("No\n");
}
return 0;
}
相关文章推荐
- HDU 5655 CA Loves Stick
- hdu 5655 CA Loves Stick(简单题)(Bestcoder #78 1001)
- HDU - 5655 CA Loves Stick
- hdu 5655 CA Loves Stick(水题)
- hdu 5655 CA Loves Stick
- HDU 5655 CA Loves Stick 水题
- HDU 5655 CA Loves Stick(思维题目)【bestcoder】
- B - CA Loves Stick HDU - 5655
- HDU - 5655 CA Loves Stick(竟有四边形判定定理。。。)
- HDU 5655 CA Loves Stick 水题
- hdu-5655 CA Loves Stick(水题)
- hdu 5655 CA Loves Stick【思维】
- HDU 5655 CA Loves Stick
- hdu 5655 CA Loves Stick
- hdu 5655 CA Loves Stick
- HDU-5655 CA Loves Stick(Water) 判断
- HDU 5655 CA Loves Stick(四根棍子能否拼成四边形)
- HDU 5655 CA Loves Stick
- CA Loves Stick HDU - 5655
- HDU-5655 CA Loves Stick(数学)