2019CCPC 網絡選拔賽 解題報告

              2019中國大學生程序設計競賽(CCPC) - 網絡選拔

1001 ^&^(HDU6702)

Problem Description

Bit operation is a common computing method in computer science ,Now we have two positive integers A and 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 C to do this ,So you need to find the smallest C 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 T.

Then the T lines contains 2 positive integers, A and B, (1≤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

題意分析

找出最小的值c使(a^c)&(b^c)最大。 (位運算的水題,簽到)


#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <string.h>
#include <stack>
#include <map>
using namespace std;
#define ll long long
#define fo(i, a, b) for (int i = a; i < b; i++)
#define foo(i, a, b) for (int i = a; i > b; i--)
#define mst(a, b) memset(a, b, sizeof(a))
const int maxn = 1e5+10;
int main()
{
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    ll a, b;
    int t;
    cin >> t;

    while (t--)
    {
        cin >> a >> b;

        if ((a & b) == 0)
            cout << min(a, b);
        else
            cout << (a & b);
        cout << endl;
    }
    return 0;
}
 

1006 Shuffle Card(HDU6707)

Problem Description

A deck of card consists of n cards. Each card is different, numbered from 1 to n. At first, the cards were ordered from 1 to n. 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 m times.

Please output the order of cards after m operations.

 

Input

The first line of input contains two positive integers n and m.(1<=n,m<=105)

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

Next there are m rows, each of which has a positive integer si, representing the card number extracted by the i-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

題意分析:

最開始給出一個排列,然後m次操作,把a移動到最前面,求最後的排列(stl+簡單模擬。簽到)

解題思路:

用map進行查重模擬一遍,不論某個數字改變多少次,怎麼移動。從最後一步往前推。最後一步移動的肯定是在最前面。

然後依次在後面,往結果裏存,用map檢查該數字是否已經存入結果。

(這題因爲我數組開小了,把1e5當做1w了,超時了好幾次。我自己背鍋。在時間允許的情況下,建議開動態的。避免我這樣的問題,超時的原因吃好幾次罰時纔出來。)

 

#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <string.h>
#include <stack>
#include <map>
using namespace std;
#define ll long long
#define fo(i, a, b) for (int i = a; i < b; i++)
#define foo(i, a, b) for (int i = a; i > b; i--)
#define mst(a, b) memset(a, b, sizeof(a))
const int maxn = 100500;
int main()
{
    // freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    map<int, int> a;
    int q[maxn];
    int qq[maxn];
    int s[maxn];
    int n, m;
    while (cin >> n >> m)
    {
        map<int, int> a;
        fo(i, 0, n)
        {
            cin >> q[i];
            a[q[i]] = 0;
        }
        fo(i, 0, m)
        {
            cin >> qq[i];
        }
        foo(i, m - 1, -1)
        {
            if (a[qq[i]] != 1)
            {
                cout << qq[i] << ' ';
                a[qq[i]] = 1;
            }
        }
        fo(i, 0, n)
        {
            if (a[q[i]] == 0)
            {
                cout << q[i] << ' ';
                a[q[i]] = 1;
            }
        }
        mst(q, 0);
        mst(qq, 0);
        mst(s, 0);
    }
}

1007 Windows Of CCPC(HDU6708)


Problem Description

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,其餘相同。

思路:

按照上面的規則,看k的數據範圍不是很大,就用打表的方式,因爲每一個k的表都是建立在k-1的情況下。(題目雖然不難,但是理清怎麼打好這個表,不容易,心累)


#include <iostream>
#include <algorithm>
#include <string>
#include <math.h>
#include <string.h>
using namespace std;
#define ll long long
#define fo(i, a, b) for (int i = a; i < b; i++)
#define foo(i, a, b) for (int i = a; i > b; i++)
#define mst(a, b) memset(a, b, sizeof(a))
const int maxn = 1050;
char ch[maxn][maxn];
int main()
{
    //freopen("in.txt", "r", stdin);
    ios::sync_with_stdio(false);
    mst(ch,0);
    ch[0][0] = ch[0][1] = ch[1][1] = 'C';
    ch[1][0] = 'P';
    ll cnt = 1;
    fo(k, 1, 10)
    {
        cnt = pow(2, k);
        // cout << cnt << endl;
        fo(i, cnt, 2 * cnt)//右下
            fo(j, cnt, 2 * cnt)
                ch[i][j] = ch[i - cnt][j - cnt];
        fo(i, 0, cnt)//右上
            fo(j, cnt, 2 * cnt)
                ch[i][j] = ch[i][j - cnt];
        fo(i, cnt, 2 * cnt)//左下倒置
            fo(j, 0, cnt)
        {
            if (ch[i - cnt][j] == 'C')
                ch[i][j] = 'P';
            else
                ch[i][j] = 'C';
        }
    }

    int t;
    cin >> t;
    while (t--)
    {
        int k;
        cin >> k;
        int ans = pow(2, k);
        fo(i, 0, ans)
        {
            fo(j, 0, ans)
               cout << ch[i][j];

            cout << endl;
        }
    }
}

 

今日體驗:

    還是自己太菜,只會做這些簽到題,還花了很長時間。不能快速的理清思路,總是邊寫邊想,這樣不好。題感也越來越差了,看來還是最近沒刷題的原因啊。多刷題,提升題感。總的來說,今天打的很自卑。
 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章