zoukankan      html  css  js  c++  java
  • codeforces

    B. Mahmoud and a Triangle
    time limit per test
    2 seconds
    memory limit per test
    256 megabytes
    input
    standard input
    output
    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.

    Input

    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.

    Output

    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.

    Examples
    Input
    5
    1 5 3 2 4
    Output
    YES
    Input
    3
    4 1 2
    Output
    NO
    题意:给定n个数,问能否找到三个数可以构成三角形
    题解:从大到小判断相邻三个即可
    代码:
     1 #include <iostream>
     2 #include <algorithm>
     3 #include <cstring>
     4 #include <cstdio>
     5 #include <bitset>
     6 #include <vector>
     7 #include <queue>
     8 #include <stack>
     9 #include <cmath>
    10 #include <list>
    11 #include <set>
    12 #include <map>
    13 #define rep(i,a,b) for(int i = a;i <= b;++ i)
    14 #define per(i,a,b) for(int i = a;i >= b;-- i)
    15 #define mem(a,b) memset((a),(b),sizeof((a)))
    16 #define FIN freopen("in.txt","r",stdin)
    17 #define FOUT freopen("out.txt","w",stdout)
    18 #define IO ios_base::sync_with_stdio(0),cin.tie(0)
    19 #define mid ((l+r)>>1)
    20 #define ls (id<<1)
    21 #define rs ((id<<1)|1)
    22 #define N 100005
    23 #define INF 0x3f3f3f3f
    24 #define INFF ((1LL<<62)-1)
    25 using namespace std;
    26 typedef long long LL;
    27 typedef pair<int, int> PIR;
    28 const double eps = 1e-8;
    29 
    30 int n, a[N];
    31 int main()
    32 {IO;
    33     while(cin >> n){
    34         rep(i, 1, n)    cin >> a[i];
    35         sort(a+1, a+n+1);
    36         int ok = 0;
    37         per(i, n, 3){
    38             int x = a[i], y = a[i-1], z = a[i-2];
    39             if(x+y > z && x+z > y && y+z > x){
    40                 ok = 1;
    41                 break;
    42             }
    43         }
    44         cout << (ok ? "YES" : "NO") << endl;
    45     }
    46     return 0;
    47 }
    View Code
  • 相关阅读:
    solr schema.xml配置
    solrconfig.xml配置文件
    solr 使用edismax来控制评分
    solr 打分和排序机制(转载)
    VMware vCenter Converter Standalone使用,物理机转换虚拟机
    Windows server开机登录取消按ctrl+alt+delete组合键
    pycharm专业版2020.1.1版本最新亲测激活,其他版本也复用
    jmeter服务器监控和插件管理
    windows下安装navicat15破解,详解最全
    linux解压汉字文件是乱码
  • 原文地址:https://www.cnblogs.com/Jstyle-continue/p/6379673.html
Copyright © 2011-2022 走看看