hdu 6512 Triangle

时间:2022-09-04 12:15:48
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 【构造】 &lpar;2016中国大学生程序设计竞赛&lpar;长春&rpar;&rpar;

    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&period;Triangle Partition-三角形-水题 &lpar;2018 Multi-University Training Contest 1 1003&rpar;

    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. &lbrack; html canvas 透明度 globalApha &rsqb; canvas绘图属性 透明度 globalApha 属性演示

    <!DOCTYPE html> <html lang='zh-cn'> <head> <title>Insert you title</title ...

  2. Android Http请求框架一:Get 和 Post 请求

    1.HttpUtil package com.app.android01; import java.io.BufferedReader; import java.io.IOException; imp ...

  3. MVC中利用ActionFilterAttribute过滤关键字

    在开发过程中,有时候会对用户输入进行过滤,以便保证平台的安全性.屏蔽的方法有很多种,但是今天我说的这种主要是利用MVC中的ActionFilterAttribute属性来实现.由于MVC天然支持AOP ...

  4. WCF Data Service 使用小结 —— 了解OData(一)

    最近做了一个小项目,其中用到了 WCF Data Service,之前是叫 ADO.NET Data Service 的.关于WCF Data Service,博客园里的介绍并不多,但它确实是个很好的 ...

  5. 我是一块cpu 《转载》

    我是一块cpu,原装intel,在一台普通的台式计算机里供职.我有个小弟是内存,我要靠他时时刻刻陪伴我工作,其实有时候我并不是没有某某地址的资料,而是懒得翻--麻烦. 还有一个老大哥叫bios,每次那 ...

  6. &lbrack;CSS备忘&rsqb; css3零散

    -webkit-overflow-scrolling:touch;下拉滚动回弹

  7. 修改UI及盒子启动及部分后续操作

    服务器操作: 1.配置nfs: # vim /etc/exports /home/nfsroot *(insecure,rw,no_root_squash) mkdir -pv /home/nfsro ...

  8. 步步为营-62-Excel的导入和导出

    说明:NPOI组件的使用 1 添加引用 2 代码 using System; using System.Collections.Generic; using System.ComponentModel ...

  9. 控制div显示隐藏(有文字图片介绍)

    <div class="toggle"> <p id="zi">收起</p> <p id="zhe&quot ...

  10. 对JAVASCRIPT匿名函数的理解

    网上很多解释,我无法理解,我想知道原理...这篇文章应该可以透彻一点 Query片段: (function(){ //这里忽略jQuery所有实现 })(); 要说匿名函数,我们首先要由函数本身说起. ...