# [比赛][ICPC2020] 2020ICPC亚洲区域赛网上模拟赛

1、比赛链接

https://ac.nowcoder.com/acm/contest/8688

2、题目情况

A 题（AC）：前缀和 + 动态规划

B 题（AC，已填坑）：找规律 + 模拟

C 题：略

D 题（AC）：概率动态规划

E 题（AC）：区间动态规划

F 题：LCA / Tarjan 缩点

G 题：略

H 题：动态规划

I 题（AC，已填坑）：模拟

J 题：乱搞？

（为什么不直接写是动态规划专题训练？）

3、得分情况

AC 了 A, B, D, E, I 五道，终榜 rank 77。

A. Easy Equation

1、题目链接

https://ac.nowcoder.com/acm/contest/8688/A

2、题面

You are given four positive integers 𝑥, 𝑦, 𝑧, 𝑘, please help little M calculate the number of equations 𝑥 + 𝑦 + 𝑧 = 𝑘 when 0 ≤ 𝑥 ≤ 𝑎, 0 ≤ 𝑦 ≤ 𝑏, 0 ≤ 𝑧 ≤ 𝑐, 0 ≤ 𝑘 ≤ 𝑑

3、题目大意

4、分析与思路

6、代码

 1 #include <bits/stdc++.h>
2 using namespace std;
3 const int B = 1e6 + 1;
4 const int N = 3e6 + 50;
5 typedef long long ll;
6 int a,b,c,d;
7 ll dp[N][3];
8 int main() {
9     scanf("%d %d %d %d", &a, &b, &c, &d);
10     for(int i = 0; i <= a; i++) dp[i][0] = 1;
11     ll sum = 0;
12     int l = 0;
13     for(int i = 0; i <= a+b; i++) {
14         sum += dp[i][0];
15         if(i-l > b) {
16             sum -= dp[l++][0];
17         }
18         dp[i][1] += sum;
19     }
20     sum = 0;
21     l = 0;
22     for(int i = 0; i <= a+b+c; i++) {
23         sum += dp[i][1];
24         if(i-l > c) {
25             sum -= dp[l++][1];
26         }
27         dp[i][2] += sum;
28     }
29     sum = 0;
30     for(int i = 0; i <= d; i++) {
31         sum += dp[i][2];
32     }
33     printf("%lld\n", sum);
34     return 0;
35 }

（樊总的代码）

B. XTL's Chessboard

1、题目链接

https://ac.nowcoder.com/acm/contest/8688/B

2、题面

Xutianli is a perfectionist, who only owns "Good Chessboard".

A well-known definition to the Good Chessboard is that there exists two integers u,v which satisfies ux+vy=1+u+v, with the given length x and width y.

Once Zjx came to XTL's home and brought a small ball. This ball was originally used to hit XTL, because he always touches fish under the pan pond every day（touch fish means dereliction of duty）. However, seeing that XTL had really worked conscientiously and enthusiastically, Zjx felt very guilty and gave the ball to XTL as a gift.

After that is a boring time of two boys. XTL design a game based on his "Good Chessboard" Prescribed procedure is as follows.

On the rectangular chessboard composed of squares of X * Y, select a left or bottom grid as the starting grid, and then place a ball in the center of the grid. The diameter of the ball is the length of the side of a grid on the chessboard. Push the ball up 45 degrees to make it roll on the chessboard. When the ball touches the edge of the board, it will bounce back. The rebound rule is: the rebounding route is perpendicular to the original route, just as the reflection of light on a plane mirror. If the ball attaches the corner, it will roll back according to the original route. The ball moves on the chessboard from the starting grid (if the starting grid is in the upper left or lower right corner, it will rebound immediately at the beginning) until it returns to the starting grid.

XTL will take a piece of his cherished chessboard from his storeroom, place the ball, and kick it obliquely up 45 degrees to let Zjx count the number of grids the ball has passed through for odd number of times and tell XTL the answer after the ball stops moving.

Zjx dislikes the game as boring. He wants to do some homework about the Lie Algebroid connection, to discuss some properties about commutative group, to find out some new Mathematical technique in order to improve the effectiveness and robustness of traditional algorithms, and finally send several SCI articles randomly for the sake of postgraduate recommendation.

Smart as you, can you tell him the solution OF this extremely depressing Question?

3、题目大意

（题都做完了给我冒出个这么个说明）

4、分析与思路

x = y 时，不会抵达任一角落，而是从从一条路返回起点，那么路径所有点都只经过 1 次，即奇数次，答案为 (x - 1) + (y - 1) = (x - 1) * 2；

x ≠ y 时，必然抵达角落而原路返回，只有起点和角落点两个点经过 1 次，其他点必然经过偶数次，答案为 2。

（题目对起点给出了许多限制条件，这里不一一说明）

5、代码

 1 #include <bits/stdc++.h>
2 using namespace std;
3
4 int x, y, a, b;
5
6 int main() {
7     cin >> x >> y >> a >> b;
8     cout << (x == y ? (x - 1) * 2 : 2);
9     return 0;
10 }

（可以不需要 x == y 的判断）

C. XTL's Chessboard（Continuation）

1、题目链接

https://ac.nowcoder.com/acm/contest/8688/C

2、题面

Since last time, Zjx was able to give the answer in a flash with your help, Xutianli learned from the bitter experience and went to acquire a chessboard factory, which can manufacture any type of chessboard at any time.

XTL explained to Zjx that he was training in "quantum artificial intelligence". That is, when Zjx did not observe, XTL was in the superposition state of artificially training his own intelligence and fishing for fish. Once Zjx is observed, XTL will be in touching fish mode. (touching fish means dereliction of duty)

Since Zjx found out that his observation would lead to dereliction, the more he thought about it, the more ashamed he felt, and decided to visit XTL's house to apologize.
After a friendly correspondence, XTL took out a ball and asked Zjx to play a new game.
Prescribed procedure is as follows.

On the rectangular chessboard composed of squares of X * Y, select a left or bottom grid as the starting grid, and then place a ball in the center of the grid. The diameter of the ball is the length of the side of a grid on the chessboard. Push the ball up 45 degrees to make it roll on the chessboard. When the ball touches the edge of the board, it will bounce back. The rebound rule is: the rebounding route is perpendicular to the original route, just as the reflection of light on a plane mirror. If the ball attaches the corner, it will roll back according to the original route. The ball moves on the chessboard from the starting grid (if the starting grid is in the upper left or lower right corner, it will rebound immediately at the beginning) until it returns to the starting grid.

XTL will use the chessboard factory to make a random chessboard, place the ball, and kick it obliquely up 45 degrees to let Zjx count the number of grids the ball has passed through for odd number of times and tell XTL the answer after the ball stops moving.

Last time you helped zjx, so zjx had sluggishness, and asks you to help him find out the answer. His paper has reached a critical moment, and Zjx had contacted several SCI journals in the Mariana Trench.

Smart as you, can you tell him the solution of this extremely depressing game?

3、题目大意

4、分析与思路

5、出题人题解

6、代码

D. Router Mesh

1、题目链接

https://ac.nowcoder.com/acm/contest/8688/D

2、题面

Two pokemons are in a battle.One is our and another is the opposite’s.

Our pokemon is in confusion and the opposite’s pokemon is frozen.

Once per turn , the opposite’s pokemon does nothing and our pokemon gives w damages to the opposite’s pokemon with a probability of P while gives w damages to itself with a probability of 1 − P.

Our pokemon has hp1 health points and the opposite’s pokemon has hp2 health points.

If one pokemon’s health points are zero or below zero, the game is over.

Your task is to calculate the expected number of turn.

3、题目大意

4、分析与思路

5、题解

6、代码

 1 #include<bits/stdc++.h>
2
3 using namespace std;
4
5 int a,b,c;
6 double dp[3010][3010],p;
7 bool st[3010][3010];
8 double f(int a,int b)
9 {
10     if(b<=0||a<=0){
11         return 0;
12     }
13     if(st[a][b]) return dp[a][b];
14     st[a][b]=true;
15
16
17     return dp[a][b]=1.0+(1.0-p)*f(a-c,b)+p*f(a,b-c);
18 }
19 void solve()
20 {
21     memset(dp,0,sizeof dp);
22     memset(st,0,sizeof st);
23     cin>>a>>b>>c>>p;
24     f(a,b);
25     printf("%.6lf\n",dp[a][b]);
26 }
27 int main()
28 {
29     int t;
30     cin>>t;
31     while(t--) solve();
32     return 0;
33 }

（瑞杰的代码）

E. Eat Walnuts

1、题目链接

https://ac.nowcoder.com/acm/contest/8688/E

2、题面

As we all know, in the ACM ICPC held in 2017, the organizer of Xinjiang University presented a box of walnuts to each coach. Our coach is happy to share with the team members except Mr.Watermelon. He is going to test Mr.Watermelon with a game when Mr.Watermelon want to eat some walnuts.

He put some walnuts in a row and let Mr.Watermelon pick one of them. And this walnut is not the ﬁrst or last in the queue. The price Mr.Watermelon need to pay is : the walnut, the walnut in front of the walnut, and the walnut behind the walnut , the square of the sum of the size of these three walnuts.

For example, now there is a row of walnuts in front of Mr.Watermelon. Their size is: 3 1 50 20 15. If this time Mr.Watermelon picked the third walnut. He needs to pay (1 + 50 + 20) ∗ (1 + 50 + 20) = 5041.

After a walnut is taken away, it will leave the queue. Then Mr.Watermelon picks a walnut again until only two walnuts remain in the queue.

Mr.Watermelon wants to know what the minimum price he will pay when he takes walnuts until there are only two walnuts in the queue. But he needs more time to spend with his girlfriend. So he ask you to help him calculate this problem.

3、题目大意

4、分析与思路

5、题解

6、代码

F. wrestling on road

1、题目链接

https://ac.nowcoder.com/acm/contest/8688/F

2、题面

Mr.Banana and Kazuya are well known philosophers in New Nippori. Van, the king of New Nippori, can’t administer the empire without them, so he give the title of left and right guardian to them.

Because of the diﬀerent politics, they are in the opposite sides. New Nippori has morning meeting every day and Van needs to design two routes so that Mr.Banana and Kazuya can participate in morning meeting. What makes things unmanageable is that if one road (not including two end points)belongs to both Mr.Banana’s and Kazuya’s route, they will wrestling with each other.

Generally, New Nippori is consist of n cities and m bidirectional roads without selﬂoops and there is at most one road connect any two cities. Mr.Banana lives in city 1 and Kazuya lives in city 2. There are two limosines in city n and n − 1, which they should get on to the morning meeting. More formally:

• if a road is in Mr.Banana’s route then it can’e be in Kazuya’s route and vice versa.
• if Mr.Banana should get on the limosine in city n while Kazuya should get on the limosine in city n − 1.

3、题目大意

4、分析与思路

5、题解

6、代码

G. Ghost Reporting

1、题目链接

https://ac.nowcoder.com/acm/contest/8688/G

2、题面

As a ghost, stealth camouflage can protect you from the threat of ordinary troops. Unfortunately, stealth camouflage can't help you fill your stomach.

Recently you heard that there is a big plan on it, which seems to be to launch a large number of tactical nuclear missiles, and it is paid by piece. This can make you happy, you usually see those ordinary troops upset, not to mention that it can make you a lot of money now. So you start asking for information everywhere. You now know the following information:

1) The target of the attack this time is the group of Tadalin lunatics.You will face N goals.

2) You need to obtain the tactical nuclear missile before you can guide it.

3) According to your usual training data, it takes T seconds for you to complete the guidance of a nuclear bomb, which means you can't do other things in these T seconds. And every time you complete the guidance of a nuclear bomb, you will need to spend zi seconds to get to the next target location; in order to make more money, you sneak into the headquarters to get your own course of action, which means you Know in advance the time it takes to reach the i-th target location from the i-1th target point each time. (The 0th target point is the starting point)

4) The headquarters will distribute launch rights to ghosts that have reached the target location and are not guiding in a certain period of time every T seconds.

5) The time period for the headquarters to issue nuclear bombs is fixed, and the time to receive nuclear bombs satisfies \t{X≤tmodT≤Y}, t is the current moment, and X and Y are given data.

6) If the time reached the target location is not within the release time period, the headquarters will arrange for someone to distribute the nuclear bomb to you and deduct the overtime  for your nuclear bomb.

7) The distribution of nuclear bombs is completed instantaneously, and each ghost must immediately guide it once it gets a nuclear bomb. And once the guidance is completed, the ghost immediately goes to the next target location. Once you reach the next target point, you must immediately apply for a nuclear bomb.

8) The overtime pay for each nuclear bomb is W.

9) You will start from the headquarters, which means that the time to reach the first target location as planned is x1.

In order to make more money, you found your good brother who was a machine gunner and borrowed a lot of adrenaline from him. Although this thing hurts your body, it is better than those 996 programmers. These adrenaline can help you reach the target location one second earlier, but due to your body restriction you can only use adrenaline once on the way to the next target point (even if you originally only need 1 second, you can also use adrenaline to make you Reach the next target location in an instant, after all, people and their physique cannot be generalized).
Now, it's time to make a plan and see how much you can earn.

3、题目大意

4、分析与思路

5、题解

6、代码

H. Nuclear launch detected

1、题目链接

https://ac.nowcoder.com/acm/contest/8688/H

2、题面

You are the second person Tadalin was promoted. You have seen Ginara upset for a long time, but now the Coplu sector is facing a powerful enemy ------ Imoen, a fallen Sarnagar. Aranak sends your troops to a fortress in Tanzanis to stop Imoen's special forces-the ghost. Everything went well originally, but the enemy suddenly started using tactical nuclear missile, which seriously affected your plan. After all, no troops can withstand a nuclear bomb. Fortunately, Archbishop Artanis of the Protoss agreed to provide you with Zap Technology, which gave the battlefield a glimmer of hope. You will use the Zap to send N troops to the battlefield.

According to the information sent back by your adjutant, we found that there is a safe window period for the enemy's nuclear missile strike, and this window period shows a periodicity with a period of H hours, that is, from time L to R in every H hours is safe .Faced with this situation, you should be very happy, but you find that the authority of the Zap system is not in your hands, which means that troops may arrive when you don't want to. According to the wire report, your i-th troop will arrive ai+H hours after the i-1th troop arrives (the first troop will arrive at the ai-th hour as planned). You understand that if you let the troops arrive in this situation, you will probably have to regroup your troops. Fortunately, you can use the starry sky acceleration technology, which can make the troops arrive one hour earlier, so that you may be able to regroup fewer troops.

Commander, it's time to make a decision. Please find the maximum number of surviving troops.

3、题目大意

4、分析与思路

5、题解

6、代码

I. Character Wheels

1、题目链接

https://ac.nowcoder.com/acm/contest/8688/I

2、题面

You are given one n *  character wheels, and it is guaranteed that n is even. Please implement these following operations:

1. Clockwise/Counter-clockwise rotate the x-th wheel  y  times. Rotating one time means rotatting 90 degrees. The instruction is L/R x yR indicates rotating clockwise and L indicates rotating counter-clockwise. For example, R 1 3 means rotate the 1-st wheel 3 times clockwise.
2. Print all the wheels, the instruction is P.

3、题目大意

> L x y，第 x 圈所有字母逆时针旋转 90 度 y 次；

> R x y，第 x 圈所有字母顺时针旋转 90 度 y 次；

> P，输出当前矩阵

4、分析与思路

① 先读入后转换

(n / 2 + x, n / 2 - x + 1), (n / 2 + x, n / 2 + x), (n / 2 - x + 1, n / 2 + x), (n / 2 - x + 1, n / 2 - x + 1)

② 边读入边转换

n 相当小，所以怎么暴力怎么来。

*我始终记得比赛时这张图是写的 “from inside to outside”，于是便是按照从里到外写的，然后一看样例却是个反的，只好临时把输入的 x 转换了一下，但事后再看又变成了 “from outside to inside”，是我和樊总比赛都眼花了？

5、代码

 1 #include <bits/stdc++.h>
2 using namespace std;
3
4 const int MAXN = 50 + 5;
5
6 int n, m, x, y;
7 char o, a[MAXN][MAXN], b[MAXN][MAXN];
8
9 void print() {
10     for (int i = 1; i <= n; i++) {
11         for (int j = 1; j <= n; j++)
12             cout << a[i][j];
13         cout << endl;
14     }
15 }
16
17 int main() {
18     cin >> n;
19     for (int i = 1; i <= n; i++)
20         cin >> a[i] + 1;
21     cin >> m;
22     for (int i = 1; i <= m; i++) {
23         cin >> o;
24         if (o == 'P') print();
25         else {
26             cin >> x >> y, x = n / 2 - x + 1, y %= 4;
27             if (o == 'R')
28                 for (int j = 1; j <= y; j++) {
29                     int c = n / 2 + x, d = n / 2 - x + 1;
30                     for (int k = 1; k <= c - d; k++) {
31                         b[d][d + k - 1] = a[c - k + 1][d];
32                         b[c - k + 1][d] = a[c][c - k + 1];
33                         b[c][c - k + 1] = a[d + k - 1][c];
34                         b[d + k - 1][c] = a[d][d + k - 1];
35                     }
36                     for (int k = 1; k <= c - d; k++) {
37                         a[d][d + k - 1] = b[d][d + k - 1];
38                         a[c - k + 1][d] = b[c - k + 1][d];
39                         a[c][c - k + 1] = b[c][c - k + 1];
40                         a[d + k - 1][c] = b[d + k - 1][c];
41                     }
42                 }
43             else
44                 for (int j = 1; j <= y; j++) {
45                     int c = n / 2 + x, d = n / 2 - x + 1;
46                     for (int k = 1; k <= c - d; k++) {
47                         b[c - k + 1][d] = a[d][d + k - 1];
48                         b[c][c - k + 1] = a[c - k + 1][d];
49                         b[d + k - 1][c] = a[c][c - k + 1];
50                         b[d][d + k - 1] = a[d + k - 1][c];
51                     }
52                     for (int k = 1; k <= c - d; k++) {
53                         a[d][d + k - 1] = b[d][d + k - 1];
54                         a[c - k + 1][d] = b[c - k + 1][d];
55                         a[c][c - k + 1] = b[c][c - k + 1];
56                         a[d + k - 1][c] = b[d + k - 1][c];
57                     }
58                 }
59         }
60     }
61     return 0;
62 }

 1 #include <bits/stdc++.h>
2 using namespace std;
3
4 const int MAXN = 2e2 + 5;
5
6 int n, m, x, y, l[MAXN];
7 char o, a[MAXN][MAXN], b[MAXN][MAXN], c[MAXN];
8
9 void print() {
10     for (int i = 1; i <= n; i++) {
11         for (int j = 0; j <= l[i] - 1; j++) {
12             a[i][i + j] = b[i][j + 1];
13             a[i + j][n - i + 1] = b[i][j + l[i] + 1];
14             a[n - i + 1][n - i + 1 - j] = b[i][j + 2 * l[i] + 1];
15             a[n - i + 1 - j][i] = b[i][j + 3 * l[i] + 1];
16         }
17     }
18     for (int i = 1; i <= n; i++) {
19         for (int j = 1; j <= n; j++)
20             cout << a[i][j];
21         cout << endl;
22     }
23 }
24
25 int main() {
26     cin >> n;
27     for (int i = 1; i <= n; i++)
28         cin >> a[i] + 1;
29     for (int i = 1; i <= n; i++) {
30         l[i] = n - i * 2 + 1;
31         for (int j = 0; j <= l[i] - 1; j++) {
32             b[i][j + 1] = a[i][i + j];
33             b[i][j + l[i] + 1] = a[i + j][n - i + 1];
34             b[i][j + 2 * l[i] + 1] = a[n - i + 1][n - i + 1 - j];
35             b[i][j + 3 * l[i] + 1] = a[n - i + 1 - j][i];
36         }
37     }
38     cin >> m;
39     for (int i = 1; i <= m; i++) {
40         cin >> o;
41         if (o == 'P') print();
42         else {
43             cin >> x >> y, y %= 4;
44             if (o == 'L')
45                 for (int j = 1; j <= y; j++) {
46                     for (int k = 1; k <= l[x]; k++)
47                         c[k] = b[x][k];
48                     for (int k = l[x] + 1; k <= 4 * l[x]; k++)
49                         b[x][k - l[x]] = b[x][k];
50                     for (int k = 1; k <= l[x]; k++)
51                         b[x][3 * l[x] + k] = c[k];
52                 }
53             else
54                 for (int j = 1; j <= y; j++) {
55                     for (int k = 1; k <= l[x]; k++)
56                         c[k] = b[x][3 * l[x] + k];
57                     for (int k = 3 * l[x]; k >= 1; k--)
58                         b[x][k + l[x]] = b[x][k];
59                     for (int k = 1; k <= l[x]; k++)
60                         b[x][k] = c[k];
61                 }
62         }
63     }
64     return 0;
65 } 

J. Matrix Subtraction

1、题目链接

https://ac.nowcoder.com/acm/contest/8688/J

2、题面

As we all know, the girls in the anime are always high school students and also need to go to school every day. So, hanging a piece of bread in their mouth haste to school is always a stereotype.

But things always go bad sometimes, just like went to bed late last night and had to go to school in time, or just have to go to some retails to buy something. So, the shortest way to school is some time not an optimal way. In this case, we need to find one way which exactly contains k steps and each step will not overlap with each other (overlap means we can’t go to the same route twice). Just as below, we can’t go back to A from B, because we have gone through this route before.
And for some simplification, we can imagine that the block is just like a matrix and we have to go to school in just k steps from our house. And your house is on the up left and the school is on the bottom right.
One optional way from our house to school in 9 steps is just EEEEESSSS
And one optional way from our house to school in 11 steps is just EEEEESSSWSE

So, give you a 𝑛 × 𝑚 block and the number 𝑘, can you find one way from your house to school within exact k steps and each step will not overlap with each other?

3、题目大意

4、分析与思路

5、题解

6、代码

https://ac.nowcoder.com/acm/contest/8688/A

posted @ 2020-10-31 23:30  jinkun113  阅读(1412)  评论(0编辑  收藏  举报