当前位置: 代码迷 >> 综合 >> P7939 [B1] Alice Wins(easy version)
  详细解决方案

P7939 [B1] Alice Wins(easy version)

热度:5   发布时间:2023-12-06 07:51:29.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\cdot n4?n dolls playing rock-paper-scissors. They are divided into two teams: Team A and Team B. Each team contains 2\cdot n2?n dolls.

A total of 2\cdot n2?n rounds of the game will be played. In the ii-th round, the ii-th doll in Team A will play against the ii-th doll in Team B. If the doll in Team A wins, Team A will get 11 point. If it loses, Team A will lose 11 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 aa and bb to represent the choices of the dolls in the two teams. a_iai? means the choice of the ii-th doll in Team A, and b_ibi? means the choice of the ii-th doll in Team B. In this question, we use 11 for rock, 22 for scissors, and 33 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 TT, the number of test cases.

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

Then two lines follow, containing an array aa of length 2\cdot n2?n and an array bb of length 2\cdot n2?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'a′ of length 2\cdot n2?n, which represents the aa array after Alice's modification. For integers 11 to 2\cdot n2?n, if a_i \ne a'_iai?=ai′?, then it means you have modified the choice of one player in Team A.

The third line contains an array b'b′ of length 2\cdot n2?n, which represents the bb array after Alice's modification. For integers 11 to 2\cdot n2?n, if b_i \ne b'_ibi?=bi′?, then it means you have modified the choice of one player in Team B.

题意翻译

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

本题中,我们用 11 代表石头,22 代表剪刀,33 代表布。

输入输出样例

输入 #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 a_2a2? to 11 and b_1b1? to 22. Then Team A can get 22 points. It can be proved that this is the maximum score that Team A can get.

For the second test case, we can change a_1a1? to 33 and a_2a2? to 11.

Constraints

1\le T,n \le 10^5;\ 1\le a_i,b_i \le 31≤T,n≤105; 1≤ai?,bi?≤3. The sum of nn over all test cases \le 10^5≤105.

原题在这:传送门

开始的代码太长了,80行,加了好多没必要的条件,删掉后一缩再缩

#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
int main()
{int T,n;cin>>T;for(int i=0;i<T;i++){int a[200100],b[200100];cin>>n;for(int j=1;j<=2*n;j++)  cin>>a[j];for(int j=1;j<=2*n;j++)  cin>>b[j];for(int j=1;j<=n;j++)//改A队 {if(b[j]==1) a[j]=3;if(b[j]==2) a[j]=1;if(b[j]==3) a[j]=2;}for(int j=n+1;j<=2*n;j++)//改B队 {if(a[j]==1) b[j]=2;if(a[j]==2) b[j]=3;if(a[j]==3) b[j]=1;}cout<<2*n;cout<<endl;for(int j=1;j<=2*n;j++){cout<<a[j]<<" ";}cout<<endl;for(int j=1;j<=2*n;j++){cout<<b[j]<<" ";}cout<<endl;}return 0;
}

  相关解决方案