计蒜客ACM ICPC 2017 Warmup Contest 9--I题-Sticky Situation
来源:互联网 发布:linux mint 中文 编辑:程序博客网 时间:2024/05/24 00:45
- 2000ms
- 65536K
While on summer camp, you are playing a game of hide-and-seek in the forest. You need to designate a “safe zone”, where, if the players manage to sneak there without being detected,they beat the seeker. It is therefore of utmost importance that this zone is well-chosen.
You point towards a tree as a suggestion, but your fellow hide-and-seekers are not satisfied. After all, the tree has branches stretching far and wide, and it will be difficult to determine whether a player has reached the safe zone. They want a very specific demarcation for the safe zone. So, you tell them to go and find some sticks, of which you will use three to mark anon-degenerate triangle (i.e. with strictly positive area) next to the tree which will count as the safe zone. After a while they return with a variety of sticks, but you are unsure whether you can actually form a triangle with the available sticks.
Can you write a program that determines whether you can make a triangle with exactly three of the collected sticks?
Input
The first line contains a single integer N , with 3 ≤ N ≤ 20 000, the number of sticks collected. Then follows one line with Npositive integers, each less than 260, the lengths of the sticks which your fellow campers have collected.
Output
Output a single line containing a single word: possible if you can make a non-degenerate triangle with three sticks of the provided lengths, and impossible if you can not.
样例输入1
31 1 1
样例输出1
possible
样例输入2
53 1 10 5 15
样例输出2
impossible
#include<iostream>#include<algorithm>using namespace std;int n;long long a[20001];long long sum;int main(){while(scanf("%d",&n)!=EOF){for(int i=0;i<n;i++) scanf("%lld",&a[i]);sort(a,a+n);bool flag=false;for(int i=0;i<n-2;i++){sum=a[i]+a[i+1];if(sum<=a[i+2]) continue;if(sum>a[i+2]){flag=true;break;}}if(flag) printf("possible\n");else printf("impossible\n");}return 0;}
- 计蒜客ACM ICPC 2017 Warmup Contest 9--I题-Sticky Situation
- 计蒜客ACM ICPC 2017 Warmup Contest 9--I题-Older Brother
- 计蒜客ACM ICPC 2017 Warmup Contest 9--C题
- 计蒜客 ACM-ICPC 2017 Warmup Contest 12
- 计蒜客 Bridge Automation(ACM ICPC 2017 Warmup Contest 9)
- 计蒜客 Charles in Charge(ACM ICPC 2017 Warmup Contest 9)
- 计蒜客ACM ICPC 2017 Warmup Contest 9--B题-Battle Simulation
- 计蒜客 ACM ICPC 2017 Warmup Contest 1 G Game Rank
- ACM ICPC 2017 Warmup Contest 1
- ACM ICPC 2017 Warmup Contest 5
- ACM ICPC 2017 Warmup Contest 6 G
- ACM ICPC 2017 Warmup Contest 1 F. Fleecing the Raffle
- ACM ICPC 2017 Warmup Contest 1 (NCPC 2016)
- ACM ICPC 2017 Warmup Contest 4(ACM Northeastern European Regional Contest,Northern Subregion 2015)
- ACM ICPC 2017 Warmup Contest 6(ACM Google Cup 2011 Invitational Programming Contest)
- ACM ICPC 2017 Warmup Contest 2(ACM Northeastern European Regional Contest,Northern Subregion 2016)
- ACM ICPC 2017 Warmup Contest 8(ACM PolyU International Invitation Contest)
- ACM ICPC 2017 Warmup Contest 1(Nordic Collegiate Programming Contest 2016)
- LeetCode 202.Happy Number 利用存储结构或快慢指针
- JavaScript关于事件绑定
- 线程池的简介及四种创建方法
- L10 find命令和linux文件后缀
- 小朋友学C语言(12):判断
- 计蒜客ACM ICPC 2017 Warmup Contest 9--I题-Sticky Situation
- Dubbo介绍
- 机器学习实战读书笔记(一)
- 初识FLASK路由
- HTML模板引擎
- 安卓常用工具类-FileUtils【文件相关的工具类】
- 小朋友学C语言(13):逻辑运算符
- python基础学习四
- 不瞒你说,这个就是你一直想要的相册