2022/1/23总结

今天干了啥?感觉在摸鱼,又感觉没在摸鱼。为什么摸鱼,因为今天好像没做题,一直在看理论,不论是其他人的博客还是《大话数据结构》好像没怎么实战环节。为什么感觉没摸鱼,因为确实花时间在学习上了。今天唯一做的2道题目还是洛谷测试的,放上来吧。


题目描述

Imp likes his plush toy a lot.

Recently, he found a machine that can clone plush toys. Imp knows that if he applies the machine to an original toy, he additionally gets one more original toy and one copy, and if he applies the machine to a copied toy, he gets two additional copies.

Initially, Imp has only one original toy. He wants to know if it is possible to use machine to get exactly xx copied toys and yy original toys? He can't throw toys away, and he can't apply the machine to a copy if he doesn't currently have any copies.

输入格式

The only line contains two integers x and y ( 0<=x,y<=10^9 ) — the number of copies and the number of original toys Imp wants to get (including the initial one).

输出格式

Print "Yes", if the desired configuration is possible, and "No" otherwise.

You can print each letter in arbitrary case (upper or lower).

题意翻译

题目描述

Imp非常喜欢他的毛绒玩具。

最近,他发现了一个可以克隆毛绒玩具的机器。Imp知道如果他将一个玩具本体进行克隆,他将会得到两个本体(新增一个)和一个克隆体;而如果将一个克隆体进行克隆,他将会得到三个克隆体(新增两个)。

一开始,Imp只有一个毛绒玩具本体。他想要知道他能否使用这个机器得到恰好x 个克隆体和y 个本体。他不能把玩具扔掉,也不能在没有克隆体的时候对一个克隆体进行克隆。 输入格式

一行两个整数x,y(0≤x,y≤10^9) ,分别表示Imp想要得到的玩具克隆体数量和本体数量(包括一开始的一个本体)。 输出格式

如果能够满足题意,输出"Yes",否则输出"No"。大小写不敏感。 说明

在样例一中,Imp可以对本体进行两次克隆,再对克隆体进行两次克隆。 翻译贡献者:浮尘ii

输入输出样例

输入 #1复制

6 3

输出 #1复制

Yes

输入 #2复制

4 2

输出 #2复制

No

输入 #3复制

1000 1001

输出 #3复制

Yes

说明/提示

In the first example, Imp has to apply the machine twice to original toys and then twice to copies.

这道题目,就是简单的加法循环。我们可以发现,因为每次复制必定会多出来克隆体,而不一定会多出来本体,这意味着克隆体最终数量一定比本体多(如果复制了的话),而且本体只有一种方式增加,就是复制本体,因此我们的思路是:先克隆本体,直到本体与要求数量相同(或大于,不过这道题比较特殊,每次克隆只加一个本体,因此不会超过,而且如果超过了,那么答案就是错误的,输出No),然后再克隆克隆体,直到克隆体的数量大于等于要求的克隆体数量,最后再比较克隆体和本体数量是否与要求的克隆体和本体数量相同,根据情况输出Yes或No即可。

#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

ll a, b;

int main()
{
	cin >> a >> b;
	ll ben = 1, ke = 0;
    if((a == 0 && b >= 2) || b == 0 || (b == 1 && a != 0))
    {
        cout << "No";
        return 0;
    }
    if(a == b - 1)
    {
		cout << "Yes";
		return 0;
	}
	while(ben < b)
	{
		ben ++;
		ke ++;
	}
	if(ben > b)
	{
		cout << "No";
		return 0;
	}
	while(ke < a)
	{
		ke += 2;
	}
	if(ke > a)
	{
		cout << "No";
		return 0;
	}
	cout << "Yes";
	return 0;
}

题目描述

The difference between the versions is the limit of operations.

Alice is a cute girl who has a lot of dolls.

There are 4⋅n dolls playing rock-paper-scissors. They are divided into two teams: Team A and Team B. Each team contains 2⋅n dolls.

A total of 2⋅n rounds of the game will be played. In the i-th round, the i-th doll in Team A will play against the i-th doll in Team B. If the doll in Team A wins, Team A will get 1 point. If it loses, Team A will lose 1 point. If it ties, Team A will not get points.

Alice knows all the dolls' choices in this game. To be precise, she uses two arrays a and b to represent the choices of the dolls in the two teams. ai​ means the choice of the i-th doll in Team A, and bi​ means the choice of the i-th doll in Team B. In this question, we use 1 for rock, 2 for scissors, and 3 for paper.

Now for each team, Alice wants to change the choices of at most nn dolls to make the score of Team A as high as possible.

Find the maximum score of Team A and its construction method. If there are multiple answers print any of them (you still have to maximize the score of Team A).

输入格式

Each test contains multiple testcases. The first line contains an integer T, the number of test cases.

For each test case, the first line contains one integer n.

Then two lines follow, containing an array a of length 2⋅n and an array b of length 2⋅n, respectively.

输出格式

For each test case, print three lines.

The first line contains one integer, the maximum score of Team A.

The second line contains an array a′ of length 2⋅n, which represents the a array after Alice's modification. For integers 1 to 2⋅n, if ai​=ai′​, then it means you have modified the choice of one player in Team A.

The third line contains an array b′ of length 2⋅n, which represents the b array after Alice's modification. For integers 1 to 2⋅n, if bi​=bi′​, then it means you have modified the choice of one player in Team B.

题意翻译

AB 每队 2n 人正在玩石头剪刀布。A 队第 i 个人出 ai​,B 队第 i 个人出 bi​。编号相同的人会对战。若 A 队赢则加一分,平不得分,输扣一分。你可以至多改变每队 n 个人的出拳方案,使得 A 队的得分最高。输出得分的最大值和任意一组构造方案。

本题中,我们用 1 代表石头,2 代表剪刀,3 代表布。

输入输出样例

输入 #1复制

2
1
1 2
1 2
2
2 3 1 3
1 2 2 1

输出 #1复制

2
1 1
2 2
4
3 1 1 3
1 2 2 1

说明/提示

Explanation

For the first test case, we can change a2​ to 1 and b1​ to 2. Then Team A can get 2 points. It can be proved that this is the maximum score that Team A can get.

For the second test case, we can change a1​ to 3 and a2​ to 1.

Constraints

1≤T,n≤10^5; 1≤ai​,bi​≤3. The sum of n over all test cases ≤10^5.

这题我用的模拟,首先看A队,只要他们有输的局,就把他们输的局改赢(即改变A队的出拳),然后如果还有剩余的修改机会,就把平局改赢,然后看B队,进行同A队一样的操作(让A队赢),最后得出来的,就是答案了。

#include <bits/stdc++.h>

using namespace std;

int fx[4] = {0, 2, 3, 1}; //克制表, 对应:空、石头、剪刀、布
int dx[4] = {0, 3, 1, 2}; //被克制表

int main()
{
	ios::sync_with_stdio(false);
	int T;
	cin >> T;
	for(int i = 0;i < T;i ++)
	{
		int n;
		cin >> n;
		int a[2 * n + 1] = {0};
		int b[2 * n + 1] = {0};
		for(int j = 0;j < 2 * n;j ++)
		{
			cin >> a[j];
		}
		for(int j = 0;j < 2 * n;j ++)
		{
			cin >> b[j];
		}
		int chance = n;
		for(int j = 0;j < 2 * n && chance;j ++)
		{
			if(dx[a[j]] == b[j] && chance)
			{
				b[j] = fx[a[j]];
				chance --;
			}
		}
		for(int j = 0;j < 2 * n && chance;j ++)
		{
			if(fx[a[j]] != b[j])
			{
				b[j] = fx[a[j]];
				chance --;
			}
		}
		chance = n;
		for(int j = 0;j < 2 * n && chance;j ++)
		{
			if(fx[b[j]] == a[j] && chance)
			{
				a[j] = dx[b[j]];
				chance --;
			}
		}
		for(int j = 0;j < 2 * n && chance;j ++)
		{
			if(dx[b[j]] != a[j])
			{
				a[j] = dx[b[j]];
				chance --;
			}
		}
		int score = 0;
		for(int j = 0;j < 2 * n;j ++)
		{
			if(fx[a[j]] == b[j]) score ++;
			else if(dx[a[j]] == b[j]) score --;
		}
		cout << score << endl;
		for(int j = 0;j < 2 * n;j ++)
		{
			cout << a[j] << " ";
		}
		cout << endl;
		for(int j = 0;j < 2 * n;j ++)
		{
			cout << b[j] << " ";
		}
		cout << endl;		
	}
	return 0;
}

这题也可以直接改A队前n个为赢的,B队后n个为输的, 因为每队总共2*n个队员,因此最后修改的就是2*n对比赛,修改完毕后结果都是A队胜利,分数最大。


好啦,这就是今天的全部了。

明日把题目补一下,可以更好地去理解。听说CodeForces又有比赛了,去看看吧。

明日放假前最后一天了,好好做做题吧。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ISansXI

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值