• Codeforces Round #633 (Div. 2)


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

    A

    思路:覆盖先看最左边,可知有两种,一个是直接上下“|”类似这样覆盖,那么后面的都只能是上下“ /”类似这样上下覆盖,只有一种,当最左边上下是“ /”这样覆盖时,后面的只要有一个是“|”这样覆盖的,那么情况也就定了,那么一共就n-1中,因此总共有n种

    //-------------------------------------------------
    //Created by HanJinyu
    //Created Time :一  4/20 20:59:15 2020
    //File Name :633A.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);
        ll a;
        scanf("%lld",&a);
        ll x;
        while(a--)
        {
            scanf("%lld",&x);
            printf("%lld
    ",x);
    
        }
     
         return 0;
    }
    View Code

    B

    思路:大体就是下图这样,先排序,然后选择中间的两个,若是奇数个数,则往后选中间两个,这样最小的剩下的就是a[0]了,直接放最后就好了。

    中间选好了之后,即a[(n-1)/2],a[(n-1)/2+1],在选择a[(n-1)/2]的左边那个数,和a[(n-1)/2+1]右边那个数,这样了中间向两边扩张即可。

     

    //-------------------------------------------------
    //Created by HanJinyu
    //Created Time :一  4/20 21:28:30 2020
    //File Name :633B.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);
            ll a[maxn];
            for(int i=0;i<n;i++)
                scanf("%lld",&a[i]);
            sort(a,a+n);
            printf("%lld %lld ",a[(n-1)/2],a[(n-1)/2+1]);
            if(n%2==1)
            {
    
                for(int i=(n-1)/2-1;i>=1;i--)
                {
                    printf("%lld %lld ",a[i],a[n-i]);
                }
                printf("%lld
    ",a[0]);
            }
            else
            {
                for(int i=(n-1)/2-1;i>=0;i--)
                {
                    printf("%lld %lld ",a[i],a[n-1-i]);
                }
                printf("
    ");
            }
        }
     
         return 0;
    }
    View Code

    C

    思路:他可以任意在K秒给数组任意个数加上2^(k-1),我们只要找到a[i]<a[i-1]的时候,记录m=a[i],只要后面的数小于一开始那个下降的数m,就保留与其差的最大值cha,当a[i]大于那个一开始下降的那个头m,就更新那个数 m,求出cha是2的几次方即可,由于是2^(k-1),故结果还要加1

    //-------------------------------------------------
    //Created by HanJinyu
    //Created Time :一  4/20 23:18:23 2020
    //File Name :633C.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;
    const int mod=1e9+7;
    int main()
    {
        //freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
        int t;
        scanf("%d",&t);
        while(t--)
        {
    
            int n;
            scanf("%d",&n);
            ll a[maxn];
            bool flag=false;
            ll m,cha=0;
            for(int i=0;i<n;i++)
            {
                scanf("%lld",&a[i]);
                if(i!=0&&a[i]<a[i-1]&&flag==false)
                {
                    flag=true;
                    m=a[i-1];
                    cha=m-a[i];
                }
                else if(a[i]<m&&flag)
                    cha=max(cha,m-a[i]);
                else if(a[i]>m&&flag)
                    m=a[i];
            }
            if(flag==false)
            {
                printf("0
    ");continue;
            }
             ll count=0; 
             while(1) 
             {
    
             if (cha>>=1) count++;
             else
                 break;
             }
             printf("%lld
    ",count+1);
    
        }
     
         return 0;
    }
    View Code
  • 相关阅读:
    现在的代码,贴一下
    2014年七月写过的代码,现在看来,还有待改进呀
    第一次做技术论坛发博文,不知道说点啥
    04-树6. Huffman Codes--优先队列(堆)在哈夫曼树与哈夫曼编码上的应用
    04-树5. File Transfer--并查集
    04-树4. Root of AVL Tree-平衡查找树AVL树的实现
    03-树3. Tree Traversals Again (25)将先序遍历和中序遍历转为后序遍历
    03-树2. List Leaves (25) 二叉树的层序遍历
    二叉树的遍历:先序中序后序遍历的递归与非递归实现及层序遍历
    最大子序列和问题之算法优化
  • 原文地址:https://www.cnblogs.com/Vampire6/p/12741150.html
Copyright © 2020-2023  润新知