SDUT 2021 Spring Team Contest--- 21

C - Jumbled Communication

 Kattis - communication 

Your best friend Adam has recently bought a Raspberry Pi and some equipment, including a wireless temperature sensor and a 433MHz receiver to receive the signals the sensors sends. Adam plans to use the Raspberry Pi as an in-door display for his weather sensor. As he is very good with electronics, he quickly managed to get the receiver to receive the signals of the sensor. However, when he looked at the bytes sent by the sensor he could not make heads or tails of them. After some hours looking through a lot of websites, he found a document explaining that his weather sensor scrambles the data it sends, to prevent it from being used together with products from other manufacturers.

Luckily, the document also describes how the sensor scrambles its communication. The document states that the sensor applies the expression x ^ (x << 1) to every byte sent. The ^ operator is bit-wise XOR1, e.g., 10110000 ^ 01100100=1101010010110000 ^ 01100100=11010100. The << operator is a (non-circular) left shift of a byte value2, e.g., 10111001 << 1=0111001010111001 << 1=01110010.

In order for Adam’s Raspberry Pi to correctly interpret the bytes sent by the weather sensor, the transmission needs to be unscrambled. However, Adam is not good at programming (actually he is a pretty bad programmer). So he asked you to help him and as a good friend, you are always happy to oblige. Can you help Adam by implementing the unscrambling algorithm?

Input

The input consists of:

  • one line with an integer nn (1≤n≤1051≤n≤105), the number of bytes in the message sent by the weather sensor;

  • one line with nn integers b1,…,bnb1,…,bn (0≤bi≤2550≤bi≤255 for all ii), the byte values of the message.

Output

Output nn byte values (in decimal encoding), the unscrambled message.

Sample Input 1Sample Output 1
5
58 89 205 20 198
22 55 187 12 66
#include <algorithm>
#include <iostream>
#include <set>
using namespace std;

int main()
{
    int n;
    scanf("%d",&n);
    int key;
    for(int i=0;i<n;i++)
    {
        scanf("%d",&key);
        for(int j=0;j<=255;j++)
        {
            if((j^(j*2%256))==key)
            {
                if(i==n-1)
                {
                    cout<<j<<endl;
                }
                else
                {
                    cout<<j<<" ";
                }
                break;
            }
        }
    }
    return 0;
}

D - Dreamer

 Kattis - dreamer 

Bash just woke up from his sweetest dream ever. In his dream, he became the best Pokenom trainer — like no one ever was. It was on the date …

Unfortunately, Bash forgot the exact date. He only remembered that the date was written in format ‘DD MM YYYY’ with exactly 88 digits. He also remembers these 88 digits (but he does not remember their order). Of course, the date must be a valid date.

Since Bash was born on Jan 1st, 2000, he knows that the date was on or after Jan 1st, 2000. (Note that the date can be Jan 1st, 2000 — it means Bash is destined to be the best Pokenom trainer since he was born!).

Bash really wants to know the date when he become the best Pokenom trainer. How many possible valid dates could there be? What is the earliest valid date that Bash could become the best Pokenom trainer?

Notes

On a leap year, February has 2929 days. Following are the rules for determining leap years:

  • A year divisible by 400400 is a leap year,

  • A year divisible by 100100 but not by 400400 is NOT a leap year,

  • A year divisible by 44 but not by 100100 is a leap year,

  • A year not divisible by 44 is NOT a leap year.

Input

  • The first line contains one integer tt (1≤t≤50)(1≤t≤50) — the number of test cases.

  • Each of the next tt lines describes one test case, contains eight digits in the format ‘XX XX XXXX’ (eight digits, separated by two blank spaces). Note that the input might not represent a valid date.

Note that the first month of the year is represented by 0101, and the first day of the month by 0101.

Output

For each test case, output a single line containing the number of possible dates and the earliest date which Bash could become the best Pokenom trainer, in the format ‘DD MM YYYY’. If there are no valid dates, print a single line containing ‘00’ (zero) instead.

Sample Input 1Sample Output 1
3
04 11 2018
23 45 6789
01 01 0002
524 18 11 2004
0
4 01 01 2000

题解:

求给出的8位数字,全排列,有多少种合法日期,注意判断闰年,求出距离20000101最近的日期。全排列函数暴力就行,注意全排列需要数组有序。

 

#include <bits/stdc++.h>

using namespace std;


int main() {
    int t;
    cin >> t;
    getchar();
    while (t--) {
        string str, s = "";
        getline(cin, str);
        for (int i = 0; str[i]; i++) {
            if (str[i] != ' ') {
                s += str[i];
            }
        }
        sort(s.begin(), s.end());
        //cout << s << endl;
        map<string, int> a;
        a.clear();
        int year1 = 10000;
        int mon1 = 13;
        int day1 = 32;
        int sum = 0;
        do {
            if (a[s] == 1) continue;
            a[s] = 1;
            int year = (s[0] - '0') * 1000 + (s[1] - '0') * 100 +
                       (s[2] - '0') * 10 + (s[3] - '0');
            if (year < 2000) {
                continue;
            }
            int mon = (s[4] - '0') * 10 + s[5] - '0';
            int day = (s[6] - '0') * 10 + s[7] - '0';
            if (mon == 2) {
                if (day > 0 && day <= 28) {
                    sum++;
                    if (year < year1) {
                        year1 = year;
                        mon1 = mon;
                        day1 = day;
                    } else if (year == year1) {
                        if (mon < mon1) {
                            mon1 = mon;
                            day1 = day;
                        } else if (mon == mon1) {
                            if (day < day1) {
                                day1 = day;
                            }
                        }
                    }
                } else if (day == 29) {
                    if (year % 100 == 0) {
                        if (year % 400 == 0) {
                            sum++;
                            if (year < year1) {
                                year1 = year;
                                mon1 = mon;
                                day1 = day;
                            } else if (year == year1) {
                                if (mon < mon1) {
                                    mon1 = mon;
                                    day1 = day;
                                } else if (mon == mon1) {
                                    if (day < day1) {
                                        day1 = day;
                                    }
                                }
                            }
                        }
                    } else {
                        if (year % 4 == 0) {
                            sum++;
                            if (year < year1) {
                                year1 = year;
                                mon1 = mon;
                                day1 = day;
                            } else if (year == year1) {
                                if (mon < mon1) {
                                    mon1 = mon;
                                    day1 = day;
                                } else if (mon == mon1) {
                                    if (day < day1) {
                                        day1 = day;
                                    }
                                }
                            }
                        }
                    }
                }
            } else if (mon == 1 || mon == 3 || mon == 5 || mon == 7 ||
                       mon == 8 || mon == 10 || mon == 12) {
                if (day > 0 && day <= 31) {
                    sum++;
                    if (year < year1) {
                        year1 = year;
                        mon1 = mon;
                        day1 = day;
                    } else if (year == year1) {
                        if (mon < mon1) {
                            mon1 = mon;
                            day1 = day;
                        } else if (mon == mon1) {
                            if (day < day1) {
                                day1 = day;
                            }
                        }
                    }
                }
            } else if (mon == 4 || mon == 6 || mon == 9 || mon == 11) {
                if (day > 0 && day <= 30) {
                    sum++;
                    if (year < year1) {
                        year1 = year;
                        mon1 = mon;
                        day1 = day;
                    } else if (year == year1) {
                        if (mon < mon1) {
                            mon1 = mon;
                            day1 = day;
                        } else if (mon == mon1) {
                            if (day < day1) {
                                day1 = day;
                            }
                        }
                    }
                }
            }
        } while (next_permutation(s.begin(), s.end()));
        if (sum == 0)
            cout << sum << endl;
        else {
            cout << sum << " ";
            if (day1 < 10)
                cout << "0" << day1 << " ";
            else
                cout << day1 << " ";
            if (mon1 < 10) {
                cout << "0" << mon1 << " ";
            } else
                cout << mon1 << " ";
            cout << year1 << endl;
        }
    }
    return 0;
}

G - Gotta Catch Em All!

 Kattis - gottacatchemall 

The Kanto region has NN junctions and N−1N−1 bidirectional roads. Junctions are numbered from 11 to NN, inclusive. All roads have the same length and each of them connects two different junctions.

At any moment, a Pokenom can appear in any of these junctions.

To become the best Pokenom trainer, like no one ever was, Bash is studying the behavior of the Pokenom in Kanto region. Bash has found that, when trying to capture a Pokenom at junction uu, the Pokenom can run away to junction vv, iff the optimal path between uu and vv has length exactly 22.

More formally, a path of length KK from junction ss to junction tt is an ordered sequence of junctions v0→v1→v2→⋯→vKv0→v1→v2→⋯→vK, where v0=s,vK=tv0=s,vK=t and for each valid index ii, vivi and vi+1vi+1 are connected directly by some road. A path is called optimal iff there is no shorter path with the same starting and ending junctions. Two paths v0→v1→⋯→vkv0→v1→⋯→vk and w0→w1→⋯wlw0→w1→⋯wl are different iff either k≠lk≠l or there exist some valid ii such that vi≠wivi≠wi.

A Pokenom can use an optimal path of length exactly 22. Help Bash count the number of such paths.

Input

  • The first line contains one integer NN (1≤N≤3⋅105)(1≤N≤3⋅105) — the number of junctions.

  • Each of the rest N−1N−1 lines contains two integers uu and vv (1≤u,v≤N,u≠v)(1≤u,v≤N,u≠v) — two endpoints of a single road.

Output

  • The only line contains exactly one integer — the number of optimal paths of length 22.

Explanation for the first example

  • There are two optimal paths of length 22: (2→1→3)(2→1→3) and (3→1→2)(3→1→2).

  • The path (1→2→1)(1→2→1) is a valid path of length 22 from 11 to 11 but it is not optimal since there is a path of length 00 from 11 to 11.

Sample Input 1Sample Output 1
3
1 2
1 3
2
Sample Input 2Sample Output 2
5
2 1
1 5
3 1
4 3
8
Sample Input 3Sample Output 3
10
1 2
2 3
2 4
1 5
3 6
2 7
7 8
5 9
5 10
24
Sample Input 4Sample Output 4
8
1 2
2 3
3 4
4 5
5 6
6 1
2 1
12

题解:给出一个无向图,然后求出终点与起点之间最短的道路是为2的路有多少条,一个三元环,就可以求出记录每个点入度,然后就可以排列组合数任意去两个,以为起点终点可以对换,所以乘2,即∑(a(i)-1)*a(i);因为有三元环的存在,三元环的任意两个顶点可以之间的距离可以为2,也可以为1,但是不符合题意,所以三元环贡献的道路应该被减去,一个三元环贡献六个道路,所以最终答案为∑(a(i)-1)*a(i)- 6*m;m为三元环的个数。

 

如果是无向图,暴力求解三元环的个数,一个三元环会被记录六次。但是时间会超时。

我们可以将无向图变为有向图,我们可以将入度小的点指向入度大的点,如果入度相等,我们就将序号小的指向序号大的,这样就成了有向图,一个三元环只会被记录一次。

在这里插入图片描述

#include<bits/stdc++.h>

using namespace std;
const int N = 1000010;
typedef unsigned long long ull;
typedef long long LL;
typedef pair<int,int> PII;
const int mod=1e6+3;
int dis[N];
int vis[N];
map<PII,int>q;
vector<int>s[N];
int u[N],v[N];
bool cmp(int p1,int p2)
{
    if(dis[p1]==dis[p2])
    {
        return p1<p2;
    }
    else
    {
        return dis[p1]<dis[p2];
    }
}
int main()
{

    int n;
    scanf("%d",&n);
    int max1=0;
    int cnt=0;
    for(int i=1; i<n; i++)
    {
        int uu,vv;
        scanf("%d %d",&uu,&vv);
        if(q[ {uu,vv}]==0&&q[ {vv,uu}]==0)
        {
            u[cnt]=uu;
            v[cnt]=vv;
            cnt++;
            q[{uu,vv}]=1;
            dis[uu]++;
            dis[vv]++;
            max1=max(max1,max(uu,vv));
        }
    }
    for(int i=0;i<=cnt;i++)
    {
        if(cmp(u[i],v[i]))
        {
            s[u[i]].push_back(v[i]);
        }
        else
        {
            s[v[i]].push_back(u[i]);
        }
    }
    LL num=0;
    LL ans=0;
    for(int i=1; i<=max1; i++)
    {
        if(dis[i]>1)
        {
            LL x=dis[i];
            LL sum=x*(x-1);
            num=num+sum;
        }
        for(int j=0;j<s[i].size();j++)
        {
            vis[s[i][j]]=i;
        }
        for(int j=0;j<s[i].size();j++)
        {
            int p=s[i][j];
            for(int k=0;k<s[p].size();k++)
            {
                if(vis[s[p][k]]==i)
                {
                    ans++;
                }
            }
        }
    }
    cout<<num-6*ans<<endl;
    return 0;
}

J - Joyless Game

 Kattis - joylessgame 

Playing games is the best way to improve flexibility, critical thinking and strategy.

To become the best Pokenom player, Bash is playing some games with his Pokenom Chikapu.

  • Bash writes down a string SS containing only lowercase English letters. No 22 consecutive characters in SS are equal.

  • Bash and Chikapu alternatively take turns to play.

  • In each turn, a player must delete one character in SS. There are 22 conditions:

    • The first and last characters can not be deleted.

    • After the character is deleted, in the new string, no 22 consecutive characters are equal.

  • The player who cannot delete a character loses.

  • Chikapu plays first.

After playing 109+7109+7 games, Chikapu won 00 games and lost all 109+7109+7 times. Chikapu thinks that Bash is cheating, by selecting a string SS such that Bash always wins.

Given some string SS, can you help determine who would win the game, if they both play optimally?

Input

The first line of input contains the integer TT — the number of test cases (1≤T≤20)(1≤T≤20).

The next TT lines each contain exactly one string SS (3≤|S|≤105)(3≤|S|≤105).

Output

For each test case, print on one line the name of the winner, if they both play optimally. Please note that this problem uses case-sensitive checker.

Sample Input 1Sample Output 1
2
vietnam
icpc
Chikapu
Bash

题解:这是一个博弈题,开头和结尾两个字母不能被拿,其他字母可以被拿,不能让两个相同的字母相邻,所以就会出现两种情况,如果开头和结尾相同,最后就会剩余3个字母,(n-3)字母会被拿;如果开头和结尾不相同,最后就剩下2个字母,(n-2)个字母会被拿,所以%2,=1,Chikapu赢,=0,Bash赢。

#include<bits/stdc++.h>
using namespace std;
const int N = 10000100;
typedef unsigned long long ull;
typedef long long LL;
typedef pair<int,int> PII;
const int mod=1e6+3;

int main()
{

    int t;
    scanf("%d",&t);
    while(t--)
    {

        string a;
        cin>>a;
        int n=a.size();
        if(a[0]==a[n-1])
        {
            int m=(n-3)%2;
            if(m==1)
            {
                printf("Chikapu\n");
            }
            else
            {
                printf("Bash\n");
            }
        }
        else
        {
            int m=(n-2)%2;
            if(m==1)
            {
                printf("Chikapu\n");
            }
            else
            {
                printf("Bash\n");
            }
        }
    }
    return 0;
}

 

 

 

 

 

 

 

 

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值