2022.1.24(补题)

补题无果(尝试自己写出来)

改了好多次,就是改不对,知道怎么做,但是自己写的代码实现不了,写的有点混乱,看来后面这种题不看题解参考一下还是不行emmmm。

然后这道题对着题解一步步理解了,写了自己的理解。

题目描述

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 exact 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, output three lines.

The first line contains one integer, which is the maximize the score of Team A.

The second line contains an array a'a′ of length 2\cdot n2⋅n, which represents the modified aa array. For integers 11 to 2\cdot n2⋅n, if a_i \ne a'_iai​=ai′​, then it means you have modified the hand shape of one player in Team A.

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

题意翻译

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

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

输入输出样例

输入 #1复制

1
1
1 2
1 2

输出 #1复制

2
1 1
2 2

说明/提示

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.

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 of all test cases \le 10^5≤105.

#include<bits/stdc++.h>
using namespace std;
int t,n,a[200005],b[200005];
int A[200005],B[200005];//把修改后的数存在数组A,B中
bool check(int x,int y)
{
    if(x==1&&y==2)return 1;
    if(x==2&&y==3)return 1;
    if(x==3&&y==1)return 1;
    return 0;
}
bool vis[200005];//记录这一对是否改过
int main()
{
    cin>>t;
    while(t--)
    {
        cin>>n;
        cout<<n*2<<endl;

        int cnt=0,cntx=0,cnty=0;
        for(int i=1; i<=n*2; i++)
        {
            cin>>a[i];
            A[i]=a[i];
            vis[i]=0;
        }

        for(int i=1; i<=n*2; i++)
        {
            cin>>b[i];
            B[i]=b[i];
        }

        for(int i=1; i<=2*n; i++)
        {
            if(check(a[i],b[i]))
                continue;
            else
                cnt++;//a输的局数

            if(cnt%2 == 1)//奇数输局改a
            {
                cntx++;
                A[i]=B[i]-1;
                if(A[i]==0)A[i]=3;
            }
            else if(cnt%2 == 0)//偶数输局改b
            {
                cnty++;
                B[i]=A[i]+1;
                if(B[i]==4)B[i]=1;
            }
            vis[i]=1;//第i局改变过
        }

        //原本没改过的局,我们把ab同时改一次消耗两边各一次改动次数
        for(int i=1; i<=2*n; i++)
        {
            if(vis[i] == 1)
                continue;
            if(cntx<n&&cnty<n)
            {
                A[i]++;
                B[i]++;
                if(A[i]==4)A[i]=1;
                if(B[i]==4)B[i]=1;
                cntx++;
                cnty++;//ab改动次数都加一
            }
            if(cntx==cnty&&cntx==n)
                break;
        }

        //如果b队更改次数还有多
        if(cnty<n)
        {
            for(int i=1; i<=n*2; i++)
            {
                if(vis[i] == 1)
                {
                    for(int j=1; j<=3; j++)
                    {
                        for(int k=1; k<=3; k++)
                            if(j!=a[i]&&k!=b[i]&&check(j,k))
                            {
                                A[i]=j;
                                B[i]=k;
                            }
                    }
                    break;
                }
            }
        }

        for(int i=1; i<=n*2; i++)cout<<A[i]<<" ";
        cout<<endl;
        for(int i=1; i<=n*2; i++)cout<<B[i]<<" ";
        if(t!=0)
            cout<<endl;
    }
    return 0;
}

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值