zoukankan      html  css  js  c++  java
  • Codeforces Gym100971 C.Triangles-组三角形 (IX Samara Regional Intercollegiate Programming Contest Russia, Samara, March 13)

    这个题就是组三角形,从给出的数组里任选两个和未知的边组三角形。

    任意两边之和大于第三边,记住这个就可以了。

    代码:

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<iostream>
     4 #include<cmath>
     5 #include<algorithm>
     6 using namespace std;
     7 const int N=1e6+10;
     8 int a[N];
     9 int main(){
    10     int n;
    11     while(~scanf("%d",&n)){
    12         for(int i=0;i<n;i++)
    13             scanf("%d",&a[i]);
    14         sort(a,a+n);
    15         if(n==2){
    16             printf("YES
    ");
    17             printf("%d
    ",a[1]-a[0]+1);
    18         }
    19         else{
    20             int cnt=a[0]+a[1]-1;
    21             if(cnt<a[n-1]){
    22                 if(cnt+a[0]>a[n-1]){
    23                     printf("YES
    ");
    24                     printf("%d
    ",cnt);
    25                 }
    26                 else printf("NO
    ");
    27             }
    28             else{
    29                 if(a[0]+a[n-1]>cnt){
    30                     printf("YES
    ");
    31                     printf("%d
    ",cnt);
    32                 }
    33                 else printf("NO
    ");
    34             }
    35         }
    36     }
    37     return 0;
    38 }
  • 相关阅读:
    Java内置包装类
    for循环思路题
    常用函数
    函数
    冒泡排序
    数组的运用
    for循环中有意思的练习题。
    for循环
    运算中容易出现的错误
    分支的运用
  • 原文地址:https://www.cnblogs.com/ZERO-/p/9703036.html
Copyright © 2011-2022 走看看