Problem Description
After Xiaoteng took a math class, he learned a lot of different shapes, but Xiaoteng's favorite triangle is because he likes stable shapes, just like his style.

After the Xiaoxun knew it, he wanted to give a triangle as a gift to Xiaoteng. He originally planned to do one, but he was too tired. So he decided to bring some wooden sticks to Xiaoteng and let Xiaoteng make a triangle himself.

One day, Xiaoxun brought n sticks to Xiaoteng. Xiaoteng wanted to try to use three of them to form a triangle, but the number is too much, Xiaoteng stunned, so he can only ask for your help.

 
Input
There are mutiple test cases.

Each case starts with a line containing a integer  n(1≤n≤5×106)  which represent the number of sticks and this is followed by n positive intergers(smaller than 231−1) separated by spaces.

 
Output
YES or NO for each case mean Xiaoteng can or can't use three of sticks to form a triangle.
 
Sample Input
4
1 2 3 4
 
Sample Output
YES
 
Source
 
很水的题,原来输入的数据是排好序的,怪不得加上排序就超时了,对于排好序的,只需要判断相邻两个的和是否大于第三个就可以了,想一想画面,很好理解。
代码:
#include <iostream>
#include <cstdlib>
#include <cstdio> using namespace std;
int n,a[];
int main() {
while(~scanf("%d",&n)) {
for(int i = ;i < && i < n;i ++) {
scanf("%d",&a[i]);
}
int flag = ;
for(int i = ;i < n;i ++) {
scanf("%d",&a[i]);
if(flag) continue;
if(a[i - ] > a[i] - a[i - ]) {
flag = ;
}
}
puts(flag ? "YES" : "NO");
}
}

hdu 6512 Triangle的更多相关文章

  1. HDU 5914 Triangle 数学找规律

    Triangle 题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=5914 Description Mr. Frog has n sticks, who ...

  2. hdu 4324 Triangle LOVE

    题目连接 http://acm.hdu.edu.cn/showproblem.php?pid=4324 Triangle LOVE Description Recently, scientists f ...

  3. HDU 5914 Triangle 【构造】 (2016中国大学生程序设计竞赛(长春))

    Triangle Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Su ...

  4. HDU 5914 Triangle(打表——斐波那契数的应用)

    题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=5914 Problem Description Mr. Frog has n sticks, whos ...

  5. HDU 4324 Triangle LOVE 拓扑排序

    Problem Description Recently, scientists find that there is love between any of two people. For exam ...

  6. HDU 4324 Triangle LOVE (拓扑排序)

    Triangle LOVE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Tot ...

  7. HDU 6300.Triangle Partition-三角形-水题 (2018 Multi-University Training Contest 1 1003)

    6300.Triangle Partition 这个题就是输出组成三角形的点的下标. 因为任意三点不共线,所以任意三点就可以组成三角形,直接排个序然后输出就可以了. 讲道理,没看懂官方题解说的啥... ...

  8. hdu 4324 Triangle LOVE(拓扑判环)

    Triangle LOVE Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) To ...

  9. hdu 4324 Triangle LOVE(拓扑排序,基础)

    题目 /***************************参考自****************************/ http://www.cnblogs.com/newpanderking ...

随机推荐

  1. 数组可以直接转换为DataRow

    string[] cc=new string[3]{...}; Dt.Rows.Add(cc);

  2. C#一般处理程序 ashx.cs使用Session报错问题

    HttpContext.Current.Session["UserID"].ToString();//报错,报Session为Null, 此时需要添加引用和继承IRequiresS ...

  3. oracle 在xml中批量插入,批量修改及多组条件查询

    最近公司用ibatis开发项目,本来可以用存储过程处理批量插入,批量修改及多组条件查询:但由于使用模块相对较小,暂时就在xml中配置,以前没有在xml做过类似处理,有必要记录一下:好了,代码如下: & ...

  4. [Python Study Notes]行人检测

    # -------------------------------------------------------------- # @文件: 行人识别.py # @工程: blog # @时间: 2 ...

  5. 【转】phpize学习

    为什么使用phpize? 比如刚开始安装的时候使用 ./configure --prefix=/usr/local/php7 --exec-prefix=/usr/local/php7 --bindi ...

  6. 使用database control配置数据库时 要求在当前oracle主目录中配置监听程序

    1:配置本地的环境变量 打开cmd命令界面  C:\Users\gechong>lsnrctl start 这时候报适配器错误 2.在cmd中输入 tnslsnr命令

  7. Python pika, TypeError: exchange_declare() got an unexpected keyword argument 'type' 问题修复

    网上很多写法都是 type='fanout' 这样的.(这里是基于python=3.6版本, pika=0.13.0 版本) credentials = pika.PlainCredentials(' ...

  8. Socket编程--TCP服务端注意事项

    僵尸进程处理 僵尸进程和孤儿进程: 基本概念:我们知道在unix/linux中,正常情况下,子进程是通过父进程创建的,子进程在创建新的进程.子进程的结束和父进程的运行是一个异步过程,即父进程永远无法预 ...

  9. Linux修改MySQL max_allowed_packet 值

    修改配置文件 vi /etc/my.cnf change "max_allowed_packet = 1M" to "max_allowed_packet = 32M&q ...

  10. jquery('tr','div')和jquery('tr,div')

     jQuery('tr', 'div') 等价于 $('tr', 'div')    表示div里面寻找tr    jQuery('tr, div') <=> $('tr, div') 表 ...