day_4-acm 水题爆数据

数据超范围害死人

反正碰到这样的题目就没有一次就能成功的AC,怎么都不够仔细和谨慎啊,直接看题吧点我看原题

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≤263−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

代码块

#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <iostream>
#include <algorithm>
using namespace std; 
long long  a[5];  

int main()  
{  
    int t;  
    scanf("%d",&t);  
    while(t--)  
    {  
        scanf("%I64d%I64d%I64d%I64d",&a[0],&a[1],&a[2],&a[3]);  
        sort(a,a+4);  
        if(a[0]==0)
        {  
            printf("No\n");  
            continue;  
        }  
        if(a[3]-a[2]-a[1]<a[0])  
        printf("Yes\n");  
        else  
        printf("No\n");  
    }  
    return 0;  
} 

总结

这道题前前后后一共做了四次才成功提交,第一次没有注意数据范围直接强行定义int型数据,第二次没有考虑到当四个数存在0的时候是不可能排成四边形的,第三次定义一个sumsum=a[0]+a[1]+a[2]-a[3];然后根据sum 的值来进行判定,想了想觉得long long 型的sum也很有可能爆了数据,然后改成sum=a[0]-a[3]+a[1]+a[2];其实再进一步思考就发现,这一步都可以直接省略的,反正是对三个较小数据之和和最大数据的差值进行判断,直接放进判断条件不就可以了嘛。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值