Gym_100971_Triangles
来源:互联网 发布:电影票网络代售商 编辑:程序博客网 时间:2024/06/09 14:50
There is a set of n segments with the lengths li. Find a segment with an integer length so that it could form a non-degenerate triangle with any two segments from the set, or tell that such segment doesn't exist.
The first line contains a single integer n (2 ≤ n ≤ 200000) — the number of segments in the set.
The second line contains n integers li separated by spaces (1 ≤ li ≤ 109) — the lengths of the segments in the set.
If the required segment exists, in the first line output «YES» (without quotes). In this case in the second line output a single integer x — the length of the needed segment. If there are many such segments, output any of them.
If the required segment doesn't exist, output «NO» (without quotes).
23 4
YES2
33 4 8
YES6
33 4 9
NO
题意:给你一组数,问你能否找到一个数使这个数和这组数中任意两个数组成三角形。
解:
在这组数中挑最小的两组确定一个x的范围,再挑最小和最大的数确定一个x的范围,两个范围一交集就能的到x了。
代码:
#include <iostream>#include <cstdio>#include <cstring>#include <algorithm>#include <cstdlib>using namespace std;const int maxn=2e5+5;int a[maxn];int main(){ int n; while(~scanf("%d",&n)) { for(int i=0;i<n;i++) scanf("%d",&a[i]); sort(a,a+n); int b,c; b=a[0]+a[1]; c=a[n-1]-a[0]; if(c+1<b) printf("YES\n%d\n",c+1); else printf("NO\n"); } return 0;}
- Gym_100971_Triangles
- AS 2.3启动APP报错Not found; no service started
- iOS指定视图圆角位置
- Qt4.8下的OpenGL以及Glut画茶壶
- c++ assert() 使用方法
- C语言获取Shell返回结果的实现方法
- Gym_100971_Triangles
- Apache Beam发布第一个稳定版本
- 多线程编程-互斥锁
- Android 进阶学习笔记
- Dlib库【9】——Surf特征点
- strdup函数
- 4814: [Cqoi2017]小Q的草稿
- CR, LF, CR/LF 回车 换行
- 微信小程序 fixed 解决 textarea 的 placeholder 不固定问题