补题--12 Codeforces Round #658 (Div. 2)

Codeforces Round #658 Div. 2


比赛网址: https://codeforces.com/contest/1382

A

题意:
长度为a的数组和长度为b的数组找到一样的一个输出即可

#include<iostream>
#include<iomanip>
#include<fstream>
#include<cstdlib>
#include<algorithm>
#include<cmath>
#include<string>
#include<cstring>
#include<cstdio>
#include<map>
using namespace std;
typedef long long ll;
ll n,m,tpy,l,r,ans,aas,pos,a[1005],b[1005];
string s;
char c;
map<ll,ll>mp;
int main()
{
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(0);
    int t;
    cin>>t;
    while(t--)
    {
        cin>>n>>m;
        mp.clear();
        ans=0;
        for(int i=1;i<=n;i++)
        {
            cin>>a[i];
            if(!mp.count(a[i])) mp[a[i]]=1;
        }
        for(int i=1;i<=m;i++)
        {
            cin>>b[i];
            if(mp[b[i]]==1)
            { ans=1; aas=b[i]; }
        }
        if(ans)
        {
            cout<<"YES"<<endl;
            cout<<"1 "<<aas<<endl;
        }
        else
        cout<<"NO"<<endl;
    }
    return 0;
}

B

题意:
就是有n堆石头然后每一堆石头都有自己的石头个数a[i],然后两个人每次可以拿任意个数的石头(只在一堆里面),然后到最后一堆没有石头拿的那个人输。
思路:
大致就是谁最后拿最后剩的那个1就有主动权,但首先石头的个数得大于1.
最特殊的也就是全为1,那就看奇偶性。
大概思路就是这样,然后我看了官方的代码真的好简单,我的好长
官方代码:

#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 1e5 + 5;
int t, n, a[N];
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> t;
    while(t--) {
        cin >> n;
        for(int i = 0; i < n; i++) {
            cin >> a[i];
        }
        int k = 0;
        while(k < n && a[k] == 1) {
            k++;
        }
        cout << ((k == n) ^ (k % 2) ? "Second" : "First") << '\n';
    }
}

C1

题意:
就是给的长度相同的两个字符串,然后将第一个改变成第二个。然后输出改变几次,还有每次改变 的位置在哪里。
思路:
肯定就是一个个进行比较然后再找出一个数组记录一下改变的位置,然后输出这个数组的长度就是次数。

#include <iostream>
#include <vector>
using namespace std;
int t, n;
string a, b;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> t;
    while(t--) {
        cin >> n >> a >> b;
        vector<int> ops;
        for(int i = 0; i < n; i++) {
            if(a[i] != b[i]) {
                if(i > 0) ops.push_back(i + 1);
                ops.push_back(1);
                if(i > 0) ops.push_back(i + 1);
            }
        }
        cout << ops.size() << ' ';
        for(int x : ops) {
            cout << x << ' ';
        }
        cout << '\n';
    }
}

C2

题意:
与c1不同的是,在操作中,选择前缀为a,并同时反转前缀中的位(0改变到1和1改变到0)并反转前缀中位的顺序。
思路:
这个相比c1就复杂了。
官方代码:
官方也有解释但是我没太看明白,大致意思就是把a的全部搞成同相位b也是同相位就好了?

#include <bits/stdc++.h>
using namespace std;
int t, n;
string a, b;
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> t;
    while(t--) {
        cin >> n >> a >> b;
        vector<int> ops1, ops2;
        a += '0'; b += '0';
        for(int i = 1; i <= n; i++) {
            if(a[i] != a[i - 1]) ops1.push_back(i);
            if(b[i] != b[i - 1]) ops2.push_back(i);
        }
        ops1.insert(ops1.end(), ops2.rbegin(), ops2.rend());
        cout << ops1.size();
        for(int x : ops1) {
            cout << ' ' << x;
        }
        cout << '\n';
    }
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值