2020ICPC亚洲网上区域赛模拟赛总结及部分题解

总结
虽然是网络赛,但这是我们这支新组的队伍第一次一起打比赛,感觉配合上还是十分生疏,尤其是读题上,B题足足花了五十分钟才读明白到底是什么意思(离谱)。
开局三个人一起看了一眼A,题目很短基本上几秒钟就看懂什么意思,然后一个队友开始想A,我看了一眼榜,发现有个队伍17秒秒杀了B(更离谱了),发现这题真长的离谱,然后我叫另外一个队友研究这道题到底啥意思,中间把A切了,于是就变成了我们三个一起研究这题啥意思。。终于在五十分钟的时候终于看懂了(英语不行是这样的),在纸上模拟了几种情况,发现大部分情况都只输出2就行了,然后我上机把这题切了。
这时我们看了一眼榜,D做出来的很多,E和I也有很多做出来的,于是我们开始同时看D和E(后悔没看I这道模拟),D是一道概率dp,我前几天刚刚做了一道几乎一毛一样的题,于是我在纸上开始推式子,让队友继续看题。后来不知道怎么回事,可能是我脑残了,我自己把自己否了,觉得这道题不可能dp推出来(赛后再看,和我之前做的那道题真的一模一样,就是题面不一样),于是就想用二维数组模拟期望,于是直到最后我都没能做出来。。
队友看出E是区间dp,可惜我们没有一个人能把这个区间dp写出来,只能怪我们做题太少了吧
最后二题结束,虽然学长安慰我们说还行,但是还有一点不甘心的吧,感觉确实可以四题甚至五题的。

A Easy Equation

题目链接
题目
You are given four positive integers 𝑥, 𝑦, 𝑧, 𝑘, please help little M calculate the number of equations 𝑥 + 𝑦 + 𝑧 = 𝑘 when 0 ≤ 𝑥 ≤ 𝑎, 0 ≤ 𝑦 ≤ 𝑏, 0 ≤ 𝑧 ≤ 𝑐, 0 ≤ 𝑘 ≤ 𝑑
输入描述:
Four integers 𝑎, 𝑏, 𝑐, 𝑑 (0 ≤ 𝑎, 𝑏, 𝑐, 𝑑 ≤106)
输出描述:
One integer the number of equations.
It is guaranteed that all the answers fit 64-bit integer.

题意
给出四个整数a,b,c,d,求满足 𝑥 + 𝑦 + 𝑧 = 𝑘 且 0 ≤ 𝑥 ≤ 𝑎, 0 ≤ 𝑦 ≤ 𝑏, 0 ≤ 𝑧 ≤ 𝑐, 0 ≤ 𝑘 ≤ 𝑑 的整数解的数量

思路
这题是我OB的,大体思路就是把式子变形成𝑦 + 𝑧 = 𝑘 - 𝑥,然后枚举𝑘 - 𝑥的所有可能性和每个可能性有多少种情况,再看左面有多少种可能,相乘再相加就得到答案

代码

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
 
int main(void) {
    ll a,b,c,d,k,x,y,z;
    cin >> a >> b >> c >> d;
    ll sum = 0ll;
    for(ll i = 0; i <= d; i++) {
        if(i > b + c)continue;
        sum += min(min(i, c) - max(0ll, i - b) + 1, min(i, b) - max(0ll, i - c) + 1) * min(a + 1ll, d + 1ll - i);
    }
    cout << sum << '\n';
    return 0;
}

B XTL’s Chessboard

题目链接
题目
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?

输入描述:
The input consists of a single test case specified with two lines. The first line contains four integers x, y, a and b, where x is the length of the chessboard, y is the width of chessboard, a,b is the coordinate of the starting grids(x,y>=2,x*y<=1000000000)
输出描述:
The output consists of a single integer, representing the number of grids the ball has passed through for odd number of times.

题意
给出n * m的棋盘和小球初始坐标(a,b),小球只能斜向45°移动,碰到边界会镜面反弹,碰到角落会原路反弹,问小球经过的路径会有多少个格子经过了奇数次。

思路
在纸上稍微画一下就会发现大部分情况都会碰到角落然后原路返回,这样除了起点和角落的格子,其他格子都经过偶数次(去一次和回来一次)除了在正方形棋盘和几个正方形连接在一起棋盘(这些棋盘会共用连接的一条边,因此n和m满足n=(k - 1)*(m - 1)+ m的情况时就是这种情况,其中k是正方形的个数,除了棋盘满足以外,还要特判小球是否是从角落出发),直接输出2就可以了。

代码

#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
 
int main(void) {
    int x,y,a,b;
    cin >> x >> y >> a >> b;
    int n = x, m = y;
    if(x > y)swap(x, y);
    if((y - x) % (x - 1) == 0) {
        if((a == 1 && b == 1) || (a == 1 && b == m) || (a == n && b == m) || (a == n && b == 1)) {
            cout << 2 << '\n';
        }else {
            int num = (y - x) / (x - 1) + 1;
            cout << num * (x * 2 - 3) + 2 - num << '\n';
        }
    }else {
        cout << 2 << '\n';
    }
}

D Pokemon Ultra Sun

题目链接
题目
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.
输入描述:
The first line is an integer T(T ≤ 8) , the number of test cases.

For each test case, the first line contains three integers hp1, hp2, w(1 ≤ hp1, hp2, w ≤ 3000), representing our pokemon’s health points, the opposite’s health points and damage. The second line contains a real number P(0 < P < 1). which is described above.
输出描述:
For each test case, print the expected number of turn rounding to 6 digits after decimal in one line.

题意
给出a,b两个正整数,每回合有p的概率将b减去w,1-p的概率将a减去w,当a或b小于等于0时游戏结束,询问游戏结束回合数的数学期望。

思路
概率dp,dp[i][j]表示a为i且b为j时的游戏结束数学期望
dp[i][j] = 1 + p * dp[i][j - w] + (1 - p) * dp[i - w][j]

代码

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

const int MAXN = 2e5 + 5;

int t, n, m, k, flag = 1;
double dp[3005][3005];
int main(void) {
	IO;
	cin >> t;
	while(t--) {
		memset(dp, 0, sizeof(dp));
		
		int hp1, hp2, w;
		double p;
		cin >> hp1 >> hp2 >> w >> p;
		for(int i = 1; i <= hp1; i++) {
			for(int j = 1; j <= hp2; j++) {
				dp[i][j] = p * dp[i][max(0, j - w)] + (1 - p) * dp[max(0, i - w)][j] + 1;
			}
		}
		printf("%.6lf\n", dp[hp1][hp2]);
	}
}

E Eat Walnuts

题目链接
题目
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 first 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.
输入描述:
Input contains multiple test cases.The first line of each test case contains a integer n(3 ≤ n ≤ 100), the number of walnuts at the beginning. The second line contains n positive integers separated by spaces, representing the size of each walnut. Each positive integer does not exceed 1,000.

For 50% of the testcases, n ≤ 50.

For 90% of the testcases, n ≤ 90.

For 100% of the testcases, n ≤ 100.

The number of the testcases does not exceed 1000.
输出描述:
For each test case, print a integer–the minimum price Mr.Watermelon will pay.

题意
有n个数字的序列a,每次能从a2到an-1选择一个数字ai消去,消去的花费是(ai-1+ai+ai+1)2,问直到序列只有两个数字的最低花费总和

思路
区间dp,dp[i][j]表示将i到j的序列全部消去需要的最低花费
dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j] +(ai+ak+aj)2)

代码

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

#define inf 0x7fffffff
const int MAXN = 2e5 + 5;

int t, n;
ll dp[105][105];
ll a[105];
ll x(ll p) {return p * p;}
int main(void) {
	IO;
	while(cin >> n) {
		for(int i = 1; i <= n; i++) cin >> a[i];
		for(int len = 3; len <= n; len++) {
			for(int i = 1; i + len - 1 <= n; i++) {
				int j = i + len - 1;
				dp[i][j] = inf;
				for(int k = i + 1; k < j; k++)
					dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j] + x(a[i] + a[j] + a[k]));
			}
		}
		cout << dp[1][n] << '\n';
	}
}

I Character Wheels

题目链接
题目
链接:https://ac.nowcoder.com/acm/contest/8688/I
来源:牛客网

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

在这里插入图片描述

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

输入描述:
First line contains one integer 𝑛 ( 4 ≤ 𝑛 ≤ 50), indicates the size of the wheels.
Then followed the wheels.
After that, one line contains one integer 𝑚 ( 1 ≤ 𝑚 ≤ 100), indicates the number ofoperations.
Then followed 𝑚 lines, one line one instruction.
it is guaranteed that at least there is one P instruction and the wheels only contain lowercase letters.
输出描述:
If the instruction is P, then print all the wheels.

题意
给一个n*n的矩阵,从外到内每一圈编号1~n/2,R就是向右转,L就是向左转,将第x圈旋转y次,每次九十度,输入P打印当前矩阵

思路
模拟即可

代码

#include<bits/stdc++.h>
using namespace std;

#define ll long long
#define IO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)

const int MAXN = 2e5 + 5;

int t, n, m, k, flag = 1;
char mp[55][55];
int main(void) {
	IO;
	cin >> n;
	for(int i = 1; i <= n; i++) for(int j = 1; j <= n; j++) cin >> mp[i][j];
	cin >> t;
	while(t--) {
		char op;
		cin >> op;
		if(op != 'P') {
			int x, y;
			cin >> x >> y;
			
			char now[1000];
			int num = 0, nowx = x, nowy = x;
			
			while(nowy + nowx <= n + 1) {
				now[++num] = mp[nowx][nowy];
				nowy++;
			}
			nowy--;
			while(nowx < nowy) {
				nowx++;
				now[++num] = mp[nowx][nowy];
			}
			while(nowy + nowx > n + 1) {
				nowy--;
				now[++num] = mp[nowx][nowy];
			}
			while(nowx > nowy + 1) {
				nowx--;
				now[++num] = mp[nowx][nowy];
			}
			nowx--;
			
			y = y % 4;
			if(op == 'L') {
				k = (y * (n - x * 2 + 1)) % num + 1;
			}else {
				k = (-y * (n - x * 2 + 1)) % num + num + 1;
			}
			
			while(nowy + nowx <= n + 1) {
				mp[nowx][nowy] = now[k];
				nowy++;
				k = k % num + 1;
			}
			nowy--;
			while(nowx < nowy) {
				nowx++;
				mp[nowx][nowy] = now[k];
				k = k % num + 1;
			}
			while(nowy + nowx > n + 1) {
				nowy--;
				mp[nowx][nowy] = now[k];
				k = k % num + 1;
			}
			while(nowx > nowy) {
				nowx--;
				mp[nowx][nowy] = now[k];
				k = k % num + 1;
			}
			
//			for(int i = 1; i <= n; i++) {
//				for(int j = 1; j <= n; j++)
//					cout << mp[i][j];
//				cout << '\n';
//			}
			
//			for(int i = 1; i <= num; i++) cout << now[i];cout << '\n';
			
		}else {
			for(int i = 1; i <= n; i++) {
				for(int j = 1; j <= n; j++)
					cout << mp[i][j];
				cout << '\n';
			}
			
		}
	}
}
  • 2
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 15
    评论
评论 15
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值