zoukankan      html  css  js  c++  java
  • hrbust 2373 小C的问题

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

    思路:比赛结束以后讲题,这个思路还真是惊艳到了,由三角形两边之和大于第三边,所以如果一直满足斐波那契数列的话最多为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
    ",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
    ",&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;
    }
  • 相关阅读:
    Ubuntu
    SSH
    Markdown
    Mac OS 上的一些骚操作
    Linux Bash
    JConsole
    IDEA
    Groovy
    Github
    Git
  • 原文地址:https://www.cnblogs.com/lalalatianlalu/p/8646226.html
Copyright © 2011-2022 走看看