zoukankan      html  css  js  c++  java
  • 2017ACM/ICPC广西邀请赛

    A - A Math Problem

     HDU - 6182 

    You are given a positive integer n, please count how many positive integers k satisfy kknkk≤n. 

    InputThere are no more than 50 test cases. 

    Each case only contains a positivse integer n in a line. 

    1n10181≤n≤1018 
    OutputFor each test case, output an integer indicates the number of positive integers k satisfy kknkk≤n in a line.Sample Input

    1
    4

    Sample Output

    1
    2

    A是最好做的,找到那个最大的数,15吧

    写快速幂只是不想循环,感觉也很麻烦

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    ll la(int n)
    {
        ll ans=1,base=n;
        while(n)
        {
            if(n&1)ans=ans*base;
            n>>=1,base=base*base;
        }
        return ans;
    }
    int main()
    {
        ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
        ll n;
        while(cin>>n)
        {
            int i;
            for(i=1;i<16;i++)
                if(la(i)>n)break;
            cout<<i-1<<"
    ";
        }
        return 0;
    }

    E - CS Course

     HDU - 6186 

    Little A has come to college and majored in Computer and Science. 

    Today he has learned bit-operations in Algorithm Lessons, and he got a problem as homework. 

    Here is the problem: 

    You are giving n non-negative integers a1,a2,,ana1,a2,⋯,an, and some queries. 

    A query only contains a positive integer p, which means you 
    are asked to answer the result of bit-operations (and, or, xor) of all the integers except apap. 

    InputThere are no more than 15 test cases. 

    Each test case begins with two positive integers n and p 
    in a line, indicate the number of positive integers and the number of queries. 

    2n,q1052≤n,q≤105 

    Then n non-negative integers a1,a2,,ana1,a2,⋯,an follows in a line, 0ai1090≤ai≤109 for each i in range[1,n]. 

    After that there are q positive integers p1,p2,,pqp1,p2,⋯,pqin q lines, 1pin1≤pi≤n for each i in range[1,q].
    OutputFor each query p, output three non-negative integers indicates the result of bit-operations(and, or, xor) of all non-negative integers except apap in a line. 
    Sample Input

    3 3
    1 1 1
    1
    2
    3

    Sample Output

    1 1 0
    1 1 0
    1 1 0

    让你求n个数除x这个数的按位与和按位或还有异或和,明明前缀后缀最方便,sb写了一个统计二进制位的

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int N=1e5+5;
    int a[N],num[31],f[31];
    int la(int n)
    {
        int i=0;
        while(n)
        {
            if(n&1)num[i]++;
            n>>=1,i++;
        }
    }
    int main()
    {
        ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
        int n,q;
        while(cin>>n>>q)
        {
            int xor1=0;
            memset(num,0,sizeof num);
            for(int i=0; i<n; i++)
                cin>>a[i],xor1^=a[i];
            for(int i=0; i<n; i++)la(a[i]);
            while(q--)
            {
                int x;
                cin>>x;
                x--;
                for(int i=0; i<31; i++)
                    f[i]=num[i];
                int i=0;
                int t=a[x];
                while(t)
                {
                    if(t&1)f[i]--;
                    t>>=1,i++;
                }
                int and1=0,or1=0;
                for(int i=30;i>=0;i--)
                {
                    and1=and1*2+(f[i]==n-1);
                    or1=or1*2+(f[i]!=0);
                }
                cout<<and1<<" "<<or1<<" "<<(xor1^a[x])<<"
    ";
            }
        }
        return 0;
    }

    G - Duizi and Shunzi

     HDU - 6188 

    Nike likes playing cards and makes a problem of it. 

    Now give you n integers, ai(1in)ai(1≤i≤n) 

    We define two identical numbers (eg: 2,22,2) a Duizi, 
    and three consecutive positive integers (eg: 2,3,42,3,4) a Shunzi. 

    Now you want to use these integers to form Shunzi and Duizi as many as possible. 

    Let s be the total number of the Shunzi and the Duizi you formed. 

    Try to calculate max(s)max(s). 

    Each number can be used only once. 

    InputThe input contains several test cases. 

    For each test case, the first line contains one integer n(1n1061≤n≤106). 
    Then the next line contains n space-separated integers aiai (1ain1≤ai≤n) 
    OutputFor each test case, output the answer in a line. 
    Sample Input

    7
    1 2 3 4 5 6 7
    9
    1 1 1 2 2 2 3 3 3
    6
    2 2 3 3 3 3 
    6
    1 2 3 3 4 5

    Sample Output

    2
    4
    3
    2
    
    
            
     

    Hint

    Case 1(1,2,3)(4,5,6)
    
    Case 2(1,2,3)(1,1)(2,2)(3,3)
    
    Case 3(2,2)(3,3)(3,3)
    
    Case 4(1,2,3)(3,4,5)

    贪心组对子和顺子就好了

    #include<bits/stdc++.h>
    using namespace std;
    int n,x,a[1000005];
    int main()
    {
        while(scanf("%d",&n)!=EOF)
        {
            memset(a,0,sizeof a);
            int sum=0;
            for(int i=0;i<n;i++)
                scanf("%d",&x),a[x]++;
            for(int i=1;i<n-1;i++)
            {
                sum+=a[i]/2;
                a[i]%=2;
                sum+=a[i+1]/2;
                a[i+1]%=2;
                if(a[i]&&a[i+1]&&a[i+2])
                {
                    sum++;
                    a[i]--;
                    a[i+1]--;
                    a[i+2]--;
                }
            }
            printf("%d
    ",sum+a[n-1]/2+a[n]/2);
        }
        return 0;
    }

    我是只考虑第一张的

    #include <stdio.h>
    #include <string.h>
    const int N=1e5+5;
    int a[N];
    int main()
    {
        int n;
        while(~scanf("%d",&n))
        {
            memset(a,0,sizeof(int)*(n+5));
            for(int i=0; i<n; i++)
            {
                int x;
                scanf("%d",&x);
                a[x]++;
            }
            int ans=0;
            for(int i=1; i<n-1; i++)
            {
                ans+=a[i]/2;
                if(a[i]&1&&a[i+1]&1&&a[i+2])
                {
                    ans++;
                    a[i+1]--;
                    a[i+2]--;
                }
            }
            ans+=a[n-1]/2+a[n]/2;
            printf("%d
    ",ans);
        }
        return 0;
    }

    D - Covering

     HDU - 6185 

    Bob's school has a big playground, boys and girls always play games here after school. 

    To protect boys and girls from getting hurt when playing happily on the playground, rich boy Bob decided to cover the playground using his carpets. 

    Meanwhile, Bob is a mean boy, so he acquired that his carpets can not overlap one cell twice or more. 

    He has infinite carpets with sizes of 1×21×2 and 2×12×1, and the size of the playground is 4×n4×n. 

    Can you tell Bob the total number of schemes where the carpets can cover the playground completely without overlapping? 

    InputThere are no more than 5000 test cases. 

    Each test case only contains one positive integer n in a line. 

    1n10181≤n≤1018 
    OutputFor each test cases, output the answer mod 1000000007 in a line. 
    Sample Input

    1
    2

    Sample Output

    1
    5

    暴力算几项,肯定是前四项推出来第五项的,

    暴力跑一下

    然后暴力猜系数,矩阵快速幂

    #include<bits/stdc++.h>
    using namespace std;
    typedef long long ll;
    const int MD=1e9+7;
    int A[5]={0,1,5,11,36};
    struct Matrix
    {
        ll a[4][4];
        Matrix()
        {
            memset(a,0,sizeof(a));
        }
        Matrix operator*(const Matrix  y)
        {
            Matrix  ans;
            for(int i=0; i<4; i++)
                for(int j=0; j<4; j++)
                    for(int k=0; k<4; k++)
                        ans.a[i][j]=(ans.a[i][j]+a[i][k]*y.a[k][j]+MD)%MD;
            return ans;
        }
        void operator=(const Matrix b)
        {
            for(int i=0; i<4; i++)
                for(int j=0; j<4; j++)
                    a[i][j]=b.a[i][j];
        }
    };
    ll la(ll x)
    {
        Matrix ans,t;
        t.a[0][0]=t.a[0][1]=t.a[1][2]=t.a[2][3]=t.a[2][0]=1;
        t.a[3][0]=-1,t.a[1][0]=5;
        ans.a[0][0]=36,ans.a[0][1]=11,ans.a[0][2]=5,ans.a[0][3]=1;
        while(x)
        {
            if(x&1)ans=ans*t;
            t=t*t;
            x>>=1;
        }
        return ans.a[0][0];
    }
    int main()
    {
        ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
        ll n;
        while(cin>>n)
        {
            if(n<5)cout<<A[n]<<"
    ";
            else
                cout<<la(n-4)<<"
    ";
        }
        return 0 ;
    }
  • 相关阅读:
    记录一次SpringCloud Alibaba整合Springboot出现的'com.netflix.client.config.IClientConfig' that could not be found
    ysoserial-URLDNS链分析
    DIVA闯关-APP测试
    前端页面直接转换为PDF文件流
    中位数最大问题
    【vim】Linux添加环境变量等
    FFmpeg使用笔记
    【memo】及时留坑
    【album】深度学习 / 机器学习 / 人工智能
    【Linux】软件安装使用【aubio / FFmpeg】
  • 原文地址:https://www.cnblogs.com/BobHuang/p/8805066.html
Copyright © 2011-2022 走看看