打卡信奥刷题(615)用C++信奥P7939[普及组/提高] 「Wdcfr-1」Alice Wins! (easy version)
「Wdcfr-1」Alice Wins! (easy version)
题目背景

题面翻译
AB 每队 2n2n2n 人正在玩石头剪刀布。A 队第 iii 个人出 aia_iai,B 队第 iii 个人出 bib_ibi。编号相同的人会对战。若 A 队赢则加一分,平不得分,输扣一分。你可以至多改变每队 nnn 个人的出拳方案,使得 A 队的得分最高。输出得分的最大值和任意一组构造方案。
本题中,我们用 111 代表石头,222 代表剪刀,333 代表布。
题目描述
The difference between the versions is the limit of operations.
Alice is a cute girl who has a lot of dolls.
There are 4⋅n4\cdot n4⋅n dolls playing rock-paper-scissors. They are divided into two teams: Team A and Team B. Each team contains 2⋅n2\cdot n2⋅n dolls.
A total of 2⋅n2\cdot n2⋅n rounds of the game will be played. In the iii-th round, the iii-th doll in Team A will play against the iii-th doll in Team B. If the doll in Team A wins, Team A will get 111 point. If it loses, Team A will lose 111 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 aaa and bbb to represent the choices of the dolls in the two teams. aia_iai means the choice of the iii-th doll in Team A, and bib_ibi means the choice of the iii-th doll in Team B. In this question, we use 111 for rock, 222 for scissors, and 333 for paper.
Now for each team, Alice wants to change the choices of at most nnn 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 TTT, the number of test cases.
For each test case, the first line contains one integer nnn.
Then two lines follow, containing an array aaa of length 2⋅n2\cdot n2⋅n and an array bbb of length 2⋅n2\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'a′ of length 2⋅n2\cdot n2⋅n, which represents the aaa array after Alice’s modification. For integers 111 to 2⋅n2\cdot n2⋅n, if ai≠ai′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'b′ of length 2⋅n2\cdot n2⋅n, which represents the bbb array after Alice’s modification. For integers 111 to 2⋅n2\cdot n2⋅n, if bi≠bi′b_i \ne b'_ibi=bi′, then it means you have modified the choice of one player in Team B.
样例 #1
样例输入 #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 a2a_2a2 to 111 and b1b_1b1 to 222. Then Team A can get 222 points. It can be proved that this is the maximum score that Team A can get.
For the second test case, we can change a1a_1a1 to 333 and a2a_2a2 to 111.
Constraints
1≤T,n≤105; 1≤ai,bi≤31\le T,n \le 10^5;\ 1\le a_i,b_i \le 31≤T,n≤105; 1≤ai,bi≤3. The sum of nnn over all test cases ≤105\le 10^5≤105.
C++实现
#include
#include
using namespace std;
const int N=200005;
int a[N],b[N],t,n;
int main() {
scanf(“%d”,&t);
while(t–) {
scanf(“%d”,&n);
for(int i=1;i<=n<<1;i++) scanf(“%d”,&a[i]),a[i]–;
for(int i=1;i<=n<<1;i++) scanf(“%d”,&b[i]),b[i]–;
for(int i=1;i<=n;i++) a[i]=(b[i]+2)%3;
for(int i=n+1;i<=n<<1;i++) b[i]=(a[i]+1)%3;
printf(“%d\n”,n<<1);
for(int i=1;i<=n<<1;i++) printf(“%d “,a[i]+1);
puts(””);
for(int i=1;i<=n<<1;i++) printf(“%d “,b[i]+1);
puts(””);
}
return 0;
}

后续
接下来我会不断用C++来实现信奥比赛中的算法题、GESP考级编程题实现、白名单赛事考题实现,记录日常的编程生活、比赛心得,感兴趣的请关注,我后续将继续分享相关内容
更多推荐



所有评论(0)