B. Mahmoud and a Triangle-水水的-codeforce
本來我都不想寫這一道題了,結果一查,題解還那麼多。如果還是比較有趣的。。
給定一個數n,然後給你n個數,問這些數是否能構成三角形。
原文給的是 這個單詞。A non-degenerate triangle,不退化的三角形,後經必應發現 不退化三角形就是
退化三角形是指面積為零的三角形。滿足下列條件之一的三角形即可稱為退化三角形:三個內角的度數為 (180°,0°,0°) 或 (90°,90°,0°);三邊其中一條邊的長度為0;一條邊的長度等於另外兩條之和。有人認為退化三角形並不能算是三角形,這是由於它介乎於三角不等式之間,在一些資料中已否定了其中一條邊等於其餘兩條邊之和的情況。
一句話,退化三角形就不是三角形。。。
所以原題就是看是否可以找三條邊構成三角形,,,
還有一個要了解的地方,我開始用的迴圈遍歷,後來發現一個道理,
我們只需要對相鄰的邊進行遍歷就可以了,因為相鄰排序為
a,b,c,d,e,f,g;
如果a+b
#include <iostream>
#include <cstdio>
#include <algorithm>
using namespace std;
const int maxn=100005;
int main()
{ int a[maxn];
int n;
scanf("%d",&n);
for(int i=1;i<=n;i++)
{ scanf ("%d",&a[i]);
}
sort(a+1,a+n+1);
for(int i=1;i<=n-2;i++)
{ if(a[i]+a[i+1]>a[i+2]&&a[i+2]-a[i]<a[i+1])
{printf("YES\n");
return 0;
}
}
printf("NO\n");
return 0;
}