第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(银川),签到题5题

Posted 小哈里

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(银川),签到题5题相关的知识,希望对你有一定的参考价值。

文章目录

补题链接:https://codeforces.com/gym/104022

A.Best Player

A. Best Player
time limit per test2 seconds
memory limit per test512 megabytes
inputstandard input
outputstandard output
Though Bob has finally returned to the college, he has to stay in his dorm with the other three roommates. Don’t know who proposes.

“Let’s play a game!”

It was meant to be light-hearted, and the rules are as follows:

A roommate is designated in turn, and he writes down on paper the coordinates of n points in three-dimensional Euclidean space.
Each of the other roommates selects one of the X-axis, the Y-axis, and the Z-axis, but no two of them make the same choice. After that, each of them counts the number of points after projecting all written points along the direction of the chosen axis. Under the projection, some points may not be distinguishable. Points (1,2,1) and (1,2,5) projected along the direction of the Z-axis, for instance, are not distinguishable.
The roommate with the most points counted will win the game. In case of a tie, the one with the most points counted whose selected axis has the smallest character in the alphabetical order will be the winner. Note that in the alphabetical order X is less than Y, Y is less than Z, and by transitivity, X is less than Z.
Bob does want to win.

“Please help me; I entreat you.”

Add flowers to brocade people, all over finish is; Give timely assistance and have several people?

Input
The first line contains an integer n (1≤n≤100).

In the next n lines, each line contains three integers x, y and z (−100≤x,y,z≤100), representing a three-dimensional point at (x,y,z).

Output
Output a character t (t∈X,Y,Z) in a line indicating that the winner’s choice is the t-axis. Note that the output characters are case-sensitive.

Examples
inputCopy
2
1 1 1
1 2 1
outputCopy
X
inputCopy
3
1 2 9
1 2 2
2 2 9
outputCopy
Y
inputCopy
4
-100 -100 100
-100 100 100
100 -100 100
100 100 100
outputCopy
Z

题意:

  • 给出三维空间中的n个点,你可以选择从X, Y, Z三个视角中的一个去看(有些点会重合)
  • 求能看到的点数最多的视角是哪个,输出X,Y,Z

思路:

  • 对于X方向,当且仅当Y,Z对相等时重合,个数不累加。 YZ方向同理。
  • 因此开个三个map维护一下对应的对数,然后输出size最大的那个方向即可。
#include<bits/stdc++.h>
using namespace std;

int main()
    int n;  cin>>n;
    map<pair<int,int>, int>mx;
    map<pair<int,int>, int>my;
    map<pair<int,int>, int>mz;
    for(int i = 1; i <= n; i++)
        int x, y, z;  cin>>x>>y>>z;
        mx[y,z]++;
        my[x,z]++;
        mz[x,y]++;
    
    int mm = max(mx.size(), my.size(), mz.size());
    if(mm==mx.size())cout<<"X";
    else if(mm==my.size())cout<<"Y";
    else if(mm==mz.size())cout<<"Z";
    return 0;

E.Isomerism

E. Isomerism
time limit per test1 second
memory limit per test512 megabytes
inputstandard input
outputstandard output
In chemistry, isomerism is the phenomenon in which more than one compounds have the same chemical formula but different chemical structures. Chemical compounds that have identical chemical formulae but differ in properties and the arrangement of atoms in the molecule are called isomers.

Ethylene, which has a carbon-carbon double bond, is one of the most important fundamental chemicals in the petrochemical industry as it is the source material for a variety of products such as polyethene resin, ethylene glycol, vinyl chloride resin, acetic acid, styrene, and alpha-olefin which are produced by polymerization, oxidation, alkylation, hydration, or the addition of halogen. The precise format of an ethylene derivative is given in the figure below, where R1,R2,R3,R4 are atoms or atomic groups. We always suppose that R1 and R2 are on the same side of the carbon-carbon double bond, while R3 and R4 are on the other side. The carbon-carbon double bond in an ethylene derivative cannot rotate around the bond axis.

To distinguish isomers of the ethylene derivatives, two different naming methods, say Cis-Trans isomerism and Zasammen-Entgegen isomerism, are invented in the academic circle. The different scopes of application between these two methods are listed as follows:

If a carbon atom connects with two identical atoms or atomic groups, isomerism of the given ethylene derivative does not exist; otherwise
if some atoms or atomic groups connecting with carbon atoms are the same, the ethylene derivative is called Cis-Trans isomerism. If the two identical atoms or atomic groups lie on the same side (i.e. upside or downside in the figure above) of the carbon-carbon double bond, it is called Cis-isomerism, or else it is called Trans-isomerism;
if the four atoms or atomic groups connecting with carbon atoms are pairwise distinct, the ethylene derivative is called Zasammen-Entgegen isomerism. If the atom or the atomic group of R1 and R3 with a higher priority and the atom or the atomic group of R2 and R4 with a higher priority lie on the same side (i.e. upside or downside in the figure above) of the carbon-carbon double bond, it is called Zasamman-isomerism, or else it is called Entgegen-isomerism.
All the atoms or atomic groups which may appear in R1, R2, R3 and R4 are listed as follows in descending order of the priority, the first of which is the one with the highest priority.

-F, -Cl, -Br, -I, -CH3, -CH2CH3, -CH2CH2CH3, -H
Now, you are asked to determine if there is any isomerism for a given ethylene derivative and find out the naming method it fits for when possible.

Input
The first line contains an integer T (1≤T≤105), indicating the number of test cases.

Then follow T test cases. For each test case:

The only line contains four strings R1, R2, R3 and R4 (R1,R2,R3,R4∈-F, -Cl, -Br, -I, -CH3, -CH2CH3, -CH2CH2CH3, -H), which are the atoms or atomic groups connecting to carbon atoms of the ethylene derivative.

Output
For each test case, output a string in one line, describing the type of isomerism the ethylene derivative fits for as follows:

If there is no isomerism of this ethylene derivative, output “None”;
If it is Cis-isomerism, output “Cis”;
If it is Trans-isomerism, output “Trans”;
If it is Zasamman-isomerism, output “Zasamman”;
Otherwise, it should be Entgegen-isomerism, so output “Entgegen”.
Example
inputCopy
2
-H -H -H -Cl
-F -F -Br -Cl
outputCopy
None
Cis

题意:

  • T组数据(1e5),每次给出4个字符串,代表碳-碳双键周围的 4 个原子团。
  • 原子团的可能取值按优先度从高到低为: -F、-Cl、-Br、-I、-CH3、-CH2CH3、-CH2CH2CH3、-H。
  • 根据性质输出:
    一个碳原子与两个相同的原子团相连,则输出 None。
    两个相同的原子团位于碳-碳双键的同一侧(即图中的上侧或下侧),则输出 Cis
    两个相同的原子团位于碳-碳双键的不同侧(即图中的上左或右侧),则输出 Trans
    R1和R3中具有较高优先级的的原子团 与 R2 和 R4 中具有较高优先级的的原子团位于碳-碳双键的同一侧,则输出 Zasamman.
    R1和R3中具有较高优先级的的原子团 与 R2 和 R4 中具有较高优先级的的原子团位于碳-碳双键的不同侧,则输出Entgegen

思路:

  • 前3种情况都可以直接判断。
    R1=R3 || R2=R4,输出None
    R1=R2 || R3=R4,输出Cis
    R1=R4 || R2=R3,输出Trans
  • 对于最后两种情况,分别取maxR1, R3和maxR2,R4进行比较。
#include<bits/stdc++.h>
using namespace std;

int main()
    string kk[] = "-F", "-Cl", "-Br", "-I", "-CH3", "-CH2CH3", "-CH2CH2CH3", "-H";
    map<string, int>rk;
    for(int i = 0; i < 8; i++)rk[kk[i]] = i;

    int T;  cin>>T;
    while(T--)
        string R1, R2, R3, R4;  cin>>R1>>R2>>R3>>R4;
        if(R1==R3 || R2==R4)cout<<"None\\n";
        else if(R1==R2 || R3==R4)cout<<"Cis\\n";
        else if(R1==R4 || R2==R3)cout<<"Trans\\n";
        else
            if(rk[R1] < rk[R3] && rk[R2] < rk[R4])cout<<"Zasamman\\n";
            else if(rk[R1] > rk[R3] && rk[R2] > rk[R4])cout<<"Zasamman\\n";
            else
                cout<<"Entgegen\\n";
            
        
    
    return 0;

J.Let’s Play Jigsaw Puzzles!

J. Let’s Play Jigsaw Puzzles!
time limit per test4 seconds
memory limit per test512 megabytes
inputstandard input
outputstandard output
Bob bought a new jigsaw puzzle yesterday. The puzzle consists of m2 rectangular pieces, where each piece contains a unique number ranged from 1 to m2 used for identification and four associated numbers indicating the adjacent pieces.

Specifically, the piece numbered i is described with four numbers ni, si, wi and ei, corresponding to four adjacent pieces: the piece numbered ni (resp., si, wi and ei) lie on the north side (resp., south side, west side and east side). If an associated number is −1, no more piece would lie on the corresponding side.

Undoubtedly, the goal of this game is to arrange all pieces in the correct locations. The instruction says that the complete image is square, with m rows and m columns.

At this juncture, Bob is at the International Collegiate Programming Contest in Yinchuan. He has no time to solve the jigsaw puzzle but has to solve Problem K instead. Can you help him?

Input
The first line contains an integer m (1≤m≤103).

In the next m2 lines, the i-th line contains four integers ni, si, wi and ei (ni,si,wi,ei∈−1∪[1,m2]). It is guaranteed that a corresponding solution does exist.

Output
Output a sorted jigsaw puzzle in m lines from north to south, where each line contains m integers representing the pieces from west to east in the corresponding row of the jigsaw puzzle.

Example
inputCopy
2
-1 3 -1 2
-1 4 1 -1
1 -1 -1 4
2 -1 3 -1
outputCopy
1 2
3 4

题意:

  • 有一个m*m的矩阵,被拆分为m*m个拼图,给出数字i对应的拼图(一行四个数,分别表示这块拼图的上下左右四个方向的数字,没有数字就是-1)。
  • 求原本的矩阵并输出。

思路:

  • 开始没看到第i行代表的就是数字i的拼图,于是写了个bfs根据四个顶点的数字往外面跑。
    但是WA了,然后发现等于3的时候的123456789是跑不出解的,然而题目并没有给出无解的情况,才意识到题目的给的其实是数字i的拼图。
  • 不过bfs加个特判和奇数的情况也可以过。
//bfs
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2020;
int u[maxn*maxn], d[maxn*maxn], l[maxn*maxn], r[maxn*maxn];
int uu[maxn*maxn], dd[maxn*maxn], ll[maxn*maxn], rr[maxn*maxn]; //维护i点四个方向点位信息
int a[maxn][maxn];
struct node int x, y, v; ;
int dx[] = -1,1,0,0;
int dy[] = 0,0,-1,1;
int main()
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int m;  cin>>m;
    if(m==1) cout<<"1\\n"; return 0;
    queue<node>q;
    for(int i = 1; i <= m*m; i++)
        cin>>u[i]>>d[i]>>l[i]>>r[i]; 
        if(u[i]!=-1)dd[u[i]] = i; //值为u[i], 下面的元素是第几个
        if(d[i]!=-1)uu[d[i]] = i;
        if(l[i]!=-1)rr[l[i]] = i;
        if(r[i]!=-1)ll[r[i]] = i;
        if(u[i]==-1 && l[i]==-1) a[1][1] = i; a[1][2] = r[i];  a[2][1] = d[i];  q.push(1,2,r[i]);  q.push(2,1,d[i]); q.push(1,1,i);  
        if(r[i]==-1 && u[i]==-1) a[1][m] = i; a[1][m-1] = l[i];  a[2][m] = d[i];  q.push(1,m-1,l[i]);  q.push(2,m,d[i]); q.push(1,m,i); 
        if(r[i]==-1 && d[i]==-1) a[m][m] = i;
    
    for(int i = 0; i <= m+1; i++)a[0][i] = a[m+1][i] = a[i][0] = a[i][m+1] = 1;
    auto func = [&](int ox, int oy, int x, int y, int t)
        if(x<=0 || y<=0 || x>=m || y>=m)return ;
        for(int i = 0; i < 4; i++)
            int nx = x+dx[i], ny = y+dy[i];
            if(nx==ox && ny == oy)continue;
            if(a[nx][ny]==0)
                if(i==0 && u[t]!=-1)a[nx][ny] = u[t];  q.push(nx, ny, u[t]);
                if(i==1 && d[t]!=-1)a[nx][ny] = d[t];  q.push(nx, ny, d[t]);
                if(i==2 && l[t]!=-1)a[nx][ny] = l[t];  q.push(nx, ny, l[t]);
                if(i==3 && r[t]!=-1)a[nx][ny] = r[t];  q.push(nx, ny, r[t]);
            
        
    ;
    while(q.size())
        int x = q.front().x, y = q.front().y, v = q.front().v;  q.pop();
        if(uu[v] != 0)func(x, y, x-1, y, uu[v]);
        if(dd[v] != 0)func(x, y, x+1, y, dd[v]);
        if(ll[v] != 0)func(x, y, x, y-1, ll[v]);
        if(rr[v] != 0)func(x, y, x, y+1, rr[v]);
    
    for(int i = 1; i <= m; i++)
        for(int j = 1; j <= m; j++)
            cout<<a[i][j]<<" \\n"[j==m];
        
    
    return 0;



  • 不过其实题目有这个性质的话,本来就有更简单的做法,首先还是一样先确定四个角落的位置。
    然后我们只需要遍历所有已经确定位置的块(按层递推即可),将与之相邻的块(下一层的块)也放进表示地图的二维数组中。就可以在m*m的时间里跑出来。
  • 正确性也不难证明,因为数字是不重复的,每个拼图也必定是唯一的,如果知道了以一层的数字,每个数字的表示下方的数组存的就是下一层的数字。
//直接递推
#include<bits/stdc++.h>
using namespace std;
const int maxn = 2020;
int u[maxn*maxn], d[maxn*maxn], l[maxn*maxn], r[maxn*maxn];
int a[maxn][maxn];
int main()
    ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
    int m;  cin>>m;
    for(int i = 1; i <= m*m; i++)
        cin>>u[i]>>d[i]>>l[i]>>r[i];
        if(u[i]==-1 && l[i]==-1)a[1][1] = i;
    
    for(int i = 2; i <= m; i++)a[1][i] = r[a[1][i-1]];
    for(int i = 2; i <= m; i++)
        for(int j = 1; j <= m; j++)
            a[i][j] = d[a[i-1][j]];
        
    
    for(int i = 1; i <= m; i++)
        for(int j = 1以上是关于第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(银川),签到题5题的主要内容,如果未能解决你的问题,请参考以下文章

第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(银川),签到题5题

第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(银川),签到题5题

第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(上海),签到题5题

第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(上海),签到题5题

第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(昆明),签到题4题

第 45 届国际大学生程序设计竞赛(ICPC)亚洲区域赛(昆明),签到题4题