码迷,mamicode.com
首页 > 其他好文 > 详细

hrbust 2373 小C的问题

时间:2018-03-25 20:49:39      阅读:171      评论:0      收藏:0      [点我收藏+]

标签:bre   范围   break   false   printf   scanf   ace   while   lld   

题意:中文题意,自行阅读

思路:比赛结束以后讲题,这个思路还真是惊艳到了,由三角形两边之和大于第三边,所以如果一直满足斐波那契数列的话最多为100项(超过100项就爆掉了,超出数据范围)

所以大于100的区间肯定是可以构成三角形的,而小于100的区间,就取出来判断一下

代码:

#include <bits/stdc++.h>
using namespace std;
const int maxn=100000+7;
typedef long long LL;

LL a[maxn],b[maxn];

bool check(int l,int r)
{
    int len=r-l+1;
//    printf("test %d\n",len);
    for(int i=0;i<len;i++){
        b[i]=a[l+i];
    }
    sort(b,b+len);
    bool ok=true;
    for(int i=2;i<len;i++){
        if(b[i]<b[i-1]+b[i-2]){
            ok=false;
            break;
        }
    }
    if(!ok)return true;
    return false;
}
int main()
{
    int n;
    while(~scanf("%d",&n)){
        for(int i=1;i<=n;i++){
            scanf("%lld\n",&a[i]);
        }
        int m;
        scanf("%d",&m);
        while(m--){
            int l,r;
            scanf("%d%d",&l,&r);
            if((r-l+1)>100)puts("Yes");
            else{
                if(check(l,r))puts("Yes");
                else puts("No");
            }
        }
    }
    return 0;
}

 

hrbust 2373 小C的问题

标签:bre   范围   break   false   printf   scanf   ace   while   lld   

原文地址:https://www.cnblogs.com/lalalatianlalu/p/8646226.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!