计蒜客ACM ICPC 2017 Warmup Contest 9--I题-Sticky Situation

本文介绍了一个关于在森林中玩捉迷藏游戏时选择安全区的问题。为了明确划定安全区域,需要用三根棍子围成一个非退化的三角形。文章提供了一段程序代码,用于判断收集到的棍子是否能够组成这样的三角形。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

  • 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.

image.png

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 , with 3 ≤ ≤ 20 000, the number of sticks collected. Then follows one line with Npositive integers, each less than 2^{60}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
3
1 1 1
样例输出1
possible
样例输入2
5
3 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;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值