Codeforces766B Mahmoud and a Triangle 2017-02-21 13:47 113人阅读 评论(0) 收藏
2 seconds
256 megabytes
standard input
standard output
Mahmoud has n line segments, the i-th
of them has length ai.
Ehab challenged him to use exactly 3 line segments to form a non-degenerate
triangle. Mahmoud doesn't accept challenges unless he is sure he can win, so he asked you to tell him if he should accept the challenge. Given the lengths of the line segments, check if he can choose exactly 3 of
them to form a non-degenerate triangle.
Mahmoud should use exactly 3 line segments, he can't concatenate two line segments or change any length. A non-degenerate triangle is a triangle
with positive area.
The first line contains single integer n (3 ≤ n ≤ 105) —
the number of line segments Mahmoud has.
The second line contains n integers a1, a2, ..., an (1 ≤ ai ≤ 109) —
the lengths of line segments Mahmoud has.
In the only line print "YES" if he can choose exactly three line segments and form a non-degenerate triangle with them, and "NO"
otherwise.
5
1 5 3 2 4
YES
3
4 1 2
NO
For the first example, he can use line segments with lengths 2, 4 and 5 to
form a non-degenerate triangle.
——————————————————————————————————
题目是在n个线段中曲靖个问能不能构成三角形
从小到大排序,然后判连续的3个能不能构成三角形即可
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <algorithm>
using namespace std;
const int MAXN=1000005; int a[MAXN];
int n;
int main()
{
while(~scanf("%d",&n))
{
for(int i=0;i<n;i++)
{
scanf("%d",&a[i]);
}
sort(a,a+n);
int flag=0;
for(int i=0;i<n-2;i++)
{
if(a[i]+a[i+1]>a[i+2]) {
flag=1;
break;
}
}
if(flag==1)
printf("YES\n");
else
printf("NO\n");
} return 0;
}
Codeforces766B Mahmoud and a Triangle 2017-02-21 13:47 113人阅读 评论(0) 收藏的更多相关文章
- Codeforces 766C Mahmoud and a Message 2017-02-21 13:57 62人阅读 评论(0) 收藏
C. Mahmoud and a Message time limit per test 2 seconds memory limit per test 256 megabytes input sta ...
- Codeforces766A Mahmoud and Longest Uncommon Subsequence 2017-02-21 13:42 46人阅读 评论(0) 收藏
A. Mahmoud and Longest Uncommon Subsequence time limit per test 2 seconds memory limit per test 256 ...
- hdu 1033 (bit masking, utilization of switch, '\0' as end of c string) 分类: hdoj 2015-06-15 21:47 37人阅读 评论(0) 收藏
bit masking is very common on the lower level code. #include <cstdio> #include <algorithm&g ...
- C语言基础:结构体 分类: iOS学习 c语言基础 2015-06-10 21:47 28人阅读 评论(0) 收藏
结构体:是一种用户自定义的数据类型 结构体定义 struct 结构体名 { 成员类型1 成员变量名1; 成员类型2 成员变量名2; -. }; typedef 原类型 ...
- 哈夫曼树-Fence Repair 分类: 树 POJ 2015-08-05 21:25 2人阅读 评论(0) 收藏
Fence Repair Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 32424 Accepted: 10417 Descri ...
- Safecracker 分类: HDU 搜索 2015-06-25 21:12 12人阅读 评论(0) 收藏
Safecracker Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) Total S ...
- 排序练习——找出前m大的数字 分类: 排序 2015-06-08 09:33 21人阅读 评论(0) 收藏
排序练习--找出前m大的数字 Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 给定n个数字,找出前m大的数字. 输入 多组输 ...
- hdu 1030 Delta-wave (C++, 0ms, explanatory comments.) 分类: hdoj 2015-06-15 12:21 45人阅读 评论(0) 收藏
problem description http://acm.hdu.edu.cn/showproblem.php?pid=1030 #include <cstdio> #include ...
- shell入门之函数应用 分类: 学习笔记 linux ubuntu 2015-07-10 21:48 77人阅读 评论(0) 收藏
最近在学习shell编程,文中若有错误的地方还望各位批评指正. 先来看一个简单的求和函数 #!/bin/bash #a test about function f_sum 7 8 function f ...
随机推荐
- 网站配色、网站模板网址 UE样式 metro报表
http://www.colourlovers.com http://unmatchedstyle.com网站模板目录 花瓣 http://huaban.com/ 油表 http://fl ...
- 【linux】centos6.5搭建svn
1.检查是否已安装 rpm -qa subversion 如果要卸载旧版本: yum remove subversion 2.安装 yum install subversion PS:yum inst ...
- Android中如何使用JUnit进行单元测试 eclipse
Android中如何使用JUnit进行单元测试 在我们日常开发android app的时候,需要不断地进行测试,所以使用JUnit测试框架显得格外重要,学会JUnit可以加快应用的开发周期. Andr ...
- 1711 Number Sequence(kmp)
Number Sequence Time Limit : 10000/5000ms (Java/Other) Memory Limit : 32768/32768K (Java/Other) To ...
- C# CS1591 缺少对公共可见类型或成员的 XML 注释 问题解决
最近在写web api的项目,用到微软的Web api help page组件,用于自动对生成API文档,见博文: https://www.cnblogs.com/lenmom/p/9081363.h ...
- fdisk用法(转载)
Linux下的fdisk功能是极其强大的,用它可以划分出最复杂的分区,下面简要介绍一下它的用法: 对于IDE硬盘,每块盘有一个设备名:对应于主板的四个IDE接口,设备名依次为:/dev/hda,/de ...
- 操作表单域中的value值
HTML <form action=""> <input type="radio" name="sex" value=&q ...
- 7_python之路之python计算器
7_python之路之python计算器 1.程序说明:Readme.cmd 1.程序文件及说明: calculator.py 2.python版本:python-3.5.3 3.程序使用:pytho ...
- How to create a site with AJAX enabled in MVC framework.
How to create a site with AJAX enabled in MVC framework. The Project illustrates how to create a web ...
- leetcode110
/** * Definition for a binary tree node. * public class TreeNode { * public int val; * public TreeNo ...