• 网络赛补题


    2019中国大学生程序设计竞赛(CCPC) - 网络选拔赛

    A - ^&^

    Bit operation is a common computing method in computer science ,Now we have two positive integers Aand B ,Please find a positive integer C that minimize the value of the formula (A xor C) & (B xor C) .Sometimes we can find a lot of Cto do this ,So you need to find the smallest CC that meets the criteria .

    For example ,Let's say A is equal to 5 and B is equal to 3 ,we can choose C=1,3.... ,so the answer we're looking for C is equal to 1.

    If the value of the expression is 0 when C=0, please print 1.

    Input

    The input file contains T test samples.(1<=T<=100)

    The first line of input file is an integer TT.

    Then the Tlines contains 2 positive integers, AA and BB, (1≤A,B<2321≤A,B<232)

    Output

    For each test case,you should output the answer and a line for each answer.

    Sample Input

    1
    3 5

    Sample Output

    1

     

    题解:类似于离散数学分配律(A xor C) & (B xor C)=(A&B) xor C

    异或:a xor b = (¬a ∧ b) ∨ (a ∧¬b)(⊕=xor)

    真⊕假=真

    假⊕真=真

    假⊕假=假

    真⊕真=假

    #include<bits/stdc++.h>
    using namespace std;
    int main()
    {
        long long t,a,b;
        cin>>t;
        while(t--)
        {
            cin>>a>>b;
            //cout<<(a&b)<<" ";
            if((a&b)==0)
               cout<<1<<endl;
            else
               cout<<(a&b)<<endl;
        }
        return 0;
    }
     

    G - Windows Of CCPC

    In recent years, CCPC has developed rapidly and gained a large number of competitors .One contestant designed a design called CCPC Windows .The 1-st order CCPC window is shown in the figure:

     

     

     

     

     

    And the 2-nd order CCPC window is shown in the figure:

     

     

     

     

     

     

     

     

    We can easily find that the window of CCPC of order k is generated by taking the window of CCPC of order k−1 as C of order k,and the result of inverting C/P in the window of CCPC of order k−1 as P of order k.

    And now I have an order k ,please output k-order CCPC Windows , The CCPC window of order k is a 2k∗2k matrix.

     

    Input

    The input file contains T test samples.(1<=T<=10) The first line of input file is an integer T. Then the T lines contains a positive integers k , (1≤k≤10)

    Output

    For each test case,you should output the answer .

    Sample Input

    3
    1
    2
    3

    Sample Output

    CC
    PC
    CCCC
    PCPC
    PPCC
    CPPC
    CCCCCCCC
    PCPCPCPC
    PPCCPPCC
    CPPCCPPC
    PPPPCCCC
    CPCPPCPC
    CCPPPPCC
    PCCPCPPC

    这道题看似简单,其实是需要技巧的,

    最开始是4个字符,左下角那个和其余3个不一样,

    用最初的可以拼成第2个,把第2个分成4部分,左下角和第一个相反,也就是P变为C,C变为P,其余相同。一共要输出2^n行,那么可以一行一行的输出,假设我要输出总行为8行,现在要输出第1行,

    那么其实是输出总行为4行的第1行输出两遍,

    当输出左下角的部分时,这是总行为4行的相应行相反输出1遍,在输出1遍相同的。

    #include<bits/stdc++.h>
    using namespace std;
    void solve(int n,int r,int f)
    {
        if(n==2)
        {
            if(f==1)
            {
                if(r==1)
                  printf("CC");
                else
                  printf("PC");
            }
            else
            {
                if(r==1)
                  printf("PP");
                else
                  printf("CP");
            }
            return;
        }
        int t=r%(n/2);
        if(t==0)
           t=n/2;
        if(f==1)
        {
            if(r>n*1.0/2)
               solve(n/2,t,0);
            else
               solve(n/2,t,1);
            solve(n/2,t,1);
        }
        else if(f==0)
        {
            if(r>n*1.0/2)
               solve(n/2,t,1);
            else
               solve(n/2,t,0);
            solve(n/2,t,0);
        }
    }
    int main()
    {
        int t,n;
        cin>>t;
        while(t--)
        {
            cin>>n;
            n=1<<n;
            for(int i=1;i<=n;i++)
            {
                solve(n,i,1);
                printf("
    ");
            }
        }
        return 0;
    }
     

    F - Shuffle Card

    A deck of card consists of nn cards. Each card is different, numbered from 1 to n. At first, the cards were ordered from 1 to nn. We complete the shuffle process in the following way, In each operation, we will draw a card and put it in the position of the first card, and repeat this operation for mm times.

    Please output the order of cards after mm operations.

    Input

    The first line of input contains two positive integers nn and mm.(1<=n,mn,m<=105105)

    The second line of the input file has n Numbers, a sequence of 1 through nn.

    Next there are m rows, each of which has a positive integer sisi, representing the card number extracted by the ii-th operation.

    Output

    Please output the order of cards after m operations. (There should be one space after each number.)

    Sample Input

    5 3
    1 2 3 4 5
    3
    4
    3

    Sample Output

    3 4 1 2 5

    这道题就是简单的栈,先进后出,输入后将数据倒序入栈,定义一个bool数组进行标记,判断即可

    #include<bits/stdc++.h>
    #include<stack>
    using namespace std;
    const int maxn=1e5+10;
    bool book[maxn];
    stack<int>s;
    int a[maxn];
    int main()
    {
        int n,m,x;
        cin>>n>>m;
        for(int i=1;i<=n;i++)
           cin>>a[i];
        for(int i=n;i>0;i--)
           s.push(a[i]);
        while(m--)
        {
            cin>>x;
            s.push(x);
        }
        memset(book,false,sizeof(book));
        while(!s.empty())
        {
            x=s.top();
            s.pop();
            if(book[x]==false)
            {
                printf("%d ",x);
                book[x]=true;
            }
        }
        return 0;
    }
  • 相关阅读:
    分布式系统学习一-概念篇
    JAVA多线程学习九-原子性操作类的应用
    JAVA多线程学习八-多个线程之间共享数据的方式
    JAVA多线程学习七-线程池
    vue 工作随笔
    智能云课堂整理
    mysql
    模板引挚 jade ejs
    node实战小例子
    昭山欢node资料学习笔记
  • 原文地址:https://www.cnblogs.com/ylrwj/p/11537183.html
Copyright © 2020-2023  润新知