HDU 6512 Triangle

Triangle

Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)

Problem Description

After Xiaoteng took a math class, he learned a lot of different shapes, but Xiaoteng’s favorite triangle is because he likes stable shapes, just like his style.

After the Xiaoxun knew it, he wanted to give a triangle as a gift to Xiaoteng. He originally planned to do one, but he was too tired. So he decided to bring some wooden sticks to Xiaoteng and let Xiaoteng make a triangle himself.

One day, Xiaoxun brought n sticks to Xiaoteng. Xiaoteng wanted to try to use three of them to form a triangle, but the number is too much, Xiaoteng stunned, so he can only ask for your help.

Input

There are mutiple test cases.

Each case starts with a line containing a integer n(1≤n≤5×106) which represent the number of sticks and this is followed by n positive intergers(smaller than 231−1) separated by spaces.

Output

YES or NO for each case mean Xiaoteng can or can’t use three of sticks to form a triangle.

Sample Input

4
1 2 3 4

Sample Output

YES

思路:

需要注意的是这题很容易超时,不能用cin, cout,还是多组数据,之后暴力解决就行了

#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
int main() {
    int n;
    while (scanf("%d", &n) != EOF){
    	bool flag = false;
	    vector<int> a(n);
	    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
	    for (int i = 0; i < n - 2; i++) {
	        if (a[i] + a[i + 1] > a[i + 2]) {
	            cout << "YES\n";
	            flag = true;
	            break;
	        }
	    } 
	    if (flag == false) cout << "NO\n";
	}
    return 0;
} 
全部评论

相关推荐

牛客97567122...:我最近投的几个,都是要不已读不回,要不不回,还有直接拒绝的
点赞 评论 收藏
分享
程序员牛肉:你这简历有啥值得拷打的?在牛客你这种简历一抓一大把,也就是个人信息不一样而已。 关键要去找亮点,亮点啊,整个简历都跟流水线生产出来的一样。
点赞 评论 收藏
分享
评论
点赞
收藏
分享

创作者周榜

更多
牛客网
牛客网在线编程
牛客网题解
牛客企业服务