zoukankan      html  css  js  c++  java
  • Codeforces Round #637 (Div. 2)

    题目链接:http://codeforces.com/contest/1341

    A

    思路:判断n*(a-b)即最小的是否大于最大的(c+d),和n*(a+b)是否小于最小的(c-d)即可,其余的都是满足条件的

    //-------------------------------------------------
    //Created by HanJinyu
    //Created Time :四  4/23 22:43:12 2020
    //File Name :637A.cpp
    //-------------------------------------------------
    
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <list>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    typedef double db;
    typedef long long ll;
    const int maxn = 200005;
    
    int main()
    {
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int n,a,b,c,d;
            scanf("%d%d%d%d%d",&n,&a,&b,&c,&d);
            int z=n*(a-b),y=n*(a+b);
            int zz=(c-d),yy=(c+d);
            if(z>yy||y<zz)
                printf("No
    ");
            else
                printf("Yes
    ");
    
        }
     
         return 0;
    }
    View Code

    B

    思路:当a[i]>a[i-1]&&a[i]>a[i+1]时,用数组标记一下,然后求出前缀和,记录当前共有几个峰,用b[i-1]-b[i-k+1]即能筛选出最大峰数的段,那么l就是i-k+1了。由于是被分成的段数,因此要峰数加1

    //-------------------------------------------------
    //Created by HanJinyu
    //Created Time :四  4/23 22:43:12 2020
    //File Name :637Bcpp
    //-------------------------------------------------
    
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <list>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    typedef double db;
    typedef long long ll;
    const int maxn = 200005;
    int main()
    {
        freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        int t;
        scanf("%d",&t);
        while(t--)
        {
            int k,n;
            scanf("%d%d",&n,&k);
            ll a[maxn],b[maxn],c[maxn];
            memset(b,0,sizeof(b));
            memset(c,0,sizeof(c));
            for(int i=1;i<=n;i++)
            {
                scanf("%lld",&a[i]);
            }
           // b[1]=0;c[1]=0;
            for(int i=2;i<=n-1;i++)
            {
                if(a[i]>a[i-1]&&a[i]>a[i+1])
                    b[i]=1;
                else
                    b[i]=0;
            }
            for(int i=1;i<=n;i++)
                    b[i]+=b[i-1];
            int res=0,l=1;
            for(int i=k;i<=n;i++)
            {
                if(b[i-1]-b[i-k+1]>res)
                {
                    res=b[i-1]-b[i-k+1];
                    l=i-k+1;
                }
            }
            printf("%d %d
    ",res+1,l);
        }
     
         return 0;
    }
    View Code

    C

    思路:额,据说看样例就能发现规律:只要是Yes的数组里,左边那个数比右边那个数小的差值都是1,是No的存在小的和相邻右边的差值不为1.。。。

    //-------------------------------------------------
    //Created by HanJinyu
    //Created Time :二  4/28 22:47:43 2020
    //File Name :637C.cpp
    //-------------------------------------------------
    
    #include <stdio.h>
    #include <string.h>
    #include <iostream>
    #include <algorithm>
    #include <vector>
    #include <queue>
    #include <set>
    #include <map>
    #include <list>
    #include <map>
    #include <string>
    #include <math.h>
    #include <stdlib.h>
    #include <time.h>
    using namespace std;
    typedef double db;
    typedef long long ll;
    const int maxn = 200005;
    
    int main()
    {
        // freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        int T;
        scanf("%d",&T);
        while(T--){
    
            int n;
            scanf("%d",&n);
            int a[maxn];
            for(int i=0;i<n;i++)
            {
    
                scanf("%d",&a[i]);
            }
            bool flag=false;
            for(int i=0;i<n-1;i++)
            {
    
                if(a[i]<a[i+1])
                {
    
                    if(a[i]!=a[i+1]-1)
                        {
    
                            flag=true;
                            break;
                        }
                }
            }
            if(!flag||n==1)
                printf("Yes
    ");
            else
                printf("No
    ");
        }
     
         return 0;
    }
    View Code
  • 相关阅读:
    研究称90%的癌症由非健康生活习惯导致
    章苏阳:早期投资,第一是看人,第二也是看人,第三还是看人!
    文章翻译第七章7-9
    文章翻译第七章4-6
    文章翻译第六章1-3
    翻译文章第六章8-11
    文章翻译第七章10-12
    VR虚拟现实技术在教育领域的前景展望
    围棋比赛不算什么,更牛的是机器人能预测未来
    c语言简单实现word count功能
  • 原文地址:https://www.cnblogs.com/Vampire6/p/12775285.html
Copyright © 2011-2022 走看看