• ACM ICPC 2017 Warmup Contest 9 L


    L. Sticky Situation

    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 N , with 3 ≤ N ≤ 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

    题目来源

    ACM ICPC 2017 Warmup Contest 9

     

    问数组中是否存在3个数组成三角形。

     1 //2017-10-24
     2 #include <cstdio>
     3 #include <cstring>
     4 #include <iostream>
     5 #include <algorithm>
     6 #define ll long long
     7 
     8 using namespace std;
     9 
    10 const int N = 21000;
    11 ll arr[N];
    12 int n;
    13 
    14 int main()
    15 {
    16     while(~scanf("%d", &n)){
    17         for(int i = 0; i < n; i++)
    18             scanf("%lld", &arr[i]);
    19         sort(arr, arr+n);
    20         bool ok = false;
    21         for(int i = 0; i < n-2; i++)
    22           if(arr[i] + arr[i+1] > arr[i+2]){
    23               ok = true;
    24               break;
    25           }
    26         if(ok)printf("possible
    ");
    27         else printf("impossible
    ");
    28     }
    29 
    30     return 0;
    31 }
  • 相关阅读:
    hdu5360 Hiking(水题)
    hdu5348 MZL's endless loop(欧拉回路)
    hdu5351 MZL's Border(规律题,java)
    hdu5347 MZL's chemistry(打表)
    hdu5344 MZL's xor(水题)
    hdu5338 ZZX and Permutations(贪心、线段树)
    hdu 5325 Crazy Bobo (树形dp)
    hdu5323 Solve this interesting problem(爆搜)
    hdu5322 Hope(dp)
    Lightoj1009 Back to Underworld(带权并查集)
  • 原文地址:https://www.cnblogs.com/Penn000/p/7723641.html
Copyright © 2020-2023  润新知