codeforces C. Ternary XOR

在这里插入图片描述

题目

题意:

你有一个由 0 , 1 , 2 0,1,2 0,1,2组成的 c i c_i ci序列, c i = ( a i + b i c_i=(a_i+b_i ci=(ai+bi所以求 m a x ( a , b ) max(a,b) max(a,b)的最小值是多少。

思路:

我们针对每一个位置分析:

  • c i = 0 c_i=0 ci=0时,那么这个位置的最小肯定就是两个都是 0 0 0的了
  • c i = 1 c_i=1 ci=1时,这个时候肯定要把最大的给其中的一个,所以一个是 1 1 1,一个是 0 0 0,所以就标记一下,之后如果出现 c i c_i ci的时候直接就可以往小的堆了。
  • c i = 2 c_i=2 ci=2时,假如在之前有出现因为 1 1 1的标记的时候,那么直接把 2 2 2往小的堆,假如没有标记,那么只能用分成两个 1 1 1了。
#include <iostream>
#include <cstring>
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <deque>
#include <stack>
using namespace std;
typedef long long ll;
typedef vector<int> vec;
typedef pair<int, int> pii;
template <class T>
inline void read(T &ret) {
    char c;
    int sgn;
    if (c = getchar(), c == EOF) return ;
    while (c != '-' && (c < '0' || c > '9')) c = getchar();
    sgn = (c == '-') ? -1:1;
    ret = (c == '-') ? 0:(c - '0');
    while (c = getchar(), c >= '0' && c <= '9') ret = ret * 10 + (c - '0');
    ret *= sgn;
    return ;
}
inline void out(int x) {
    if (x > 9) out(x / 10);
    putchar(x % 10 + '0');
}
int main() {
    ios::sync_with_stdio(false);
    int T;
    cin >> T;
    string s;
    while (T--) {
        int n;
        string t = "", tt = "";
        cin >> n >> s;
        bool flag = false;
        for (int i = 0; i < n; i++) {
            if (s[i] == '0') {
                t += '0';
                tt += '0';
            } else if (s[i] == '1') {
                if (!flag) t += '1', tt += '0', flag = true;
                else tt += '1', t += '0';
            } else if (s[i] == '2') {
                if (!flag) t += '1',tt += '1';
                else tt += '2', t += '0';
            }
        }
        cout <<t << endl << tt << endl;
    }
    return 0;
}

您提供的链接是Codeforces的一个问题,问题编号为104377。Codeforces是一个知名的在线编程竞赛平台,经常举办各种编程比赛和训练。Gym是Codeforces的一个扩展包,用于组织私人比赛和训练。您提供的链接指向了一个问题的页面,但具体的问题内容和描述无法通过链接获取。如果您有具体的问题或需要了解关于Codeforces Gym的更多信息,请提供更详细的信息。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* [http://codeforces.com/gym/100623/attachments E题](https://blog.csdn.net/weixin_30820077/article/details/99723867)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *2* [http://codeforces.com/gym/100623/attachments H题](https://blog.csdn.net/weixin_38166726/article/details/99723856)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] - *3* [CodeforcesPP:Codeforces扩展包](https://download.csdn.net/download/weixin_42101164/18409501)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v92^chatsearchT3_1"}}] [.reference_item style="max-width: 33.333333333333336%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值