Codeforces Gym100971 C.Triangles-组三角形 (IX Samara Regional Intercollegiate Programming Contest Russia...

 

 

 

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

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

 

代码:

 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\n"); 17 printf("%d\n",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\n"); 24 printf("%d\n",cnt); 25  } 26 else printf("NO\n"); 27  } 28 else{ 29 if(a[0]+a[n-1]>cnt){ 30 printf("YES\n"); 31 printf("%d\n",cnt); 32  } 33 else printf("NO\n"); 34  } 35  } 36  } 37 return 0; 38 }

 

转载于:https://www.cnblogs.com/ZERO-/p/9703036.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值