首页 > 其他分享 >D. XOR Permutations

D. XOR Permutations

时间:2023-03-15 18:48:50浏览次数:36  
标签:XOR ss -- Permutations int cnt1 cnt0 include

D. XOR Permutations

image

注意

多次输入输出不要忘了初始化
注意分析

代码

点击查看代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<cctype>
using namespace std;

#define X first
#define Y second

typedef pair<int,int> pii;
typedef long long LL;
typedef struct ss{
	int cnt1,cnt0;
	string s;
}ss;
ss s[3];
const char nl = '\n';
const int N = 1e6+10;
const int M = 2e5+10;

bool cmp(ss a,ss b){
	return a.cnt1 > b.cnt1;
}

void solve(){
	int t;
	cin >> t;
	while(t -- ){
		cin >> s[0].s >> s[1].s >> s[2].s;
		s[0].cnt1 = 0;
		s[1].cnt1 = 0;
		s[2].cnt1 = 0;	//记得初始化
		for(int i = 0; i <= 9; i ++ ){
			if(s[0].s[i] == '1')s[0].cnt1 ++;
			if(s[1].s[i] == '1')s[1].cnt1 ++;
			if(s[2].s[i] == '1')s[2].cnt1 ++;            
		}
		s[0].cnt0 = 10 - s[0].cnt1;
		s[1].cnt0 = 10 - s[1].cnt1;
		s[2].cnt0 = 10 - s[2].cnt1;
		//结果取“1”的组合有“100”和"111"两种
		//如果希望“1”的个数尽可能地多,我们可以优先取“100”组合
		for(int i = 1; i <= 10; i ++ ){
			sort(s,s+3,cmp);	//每次都排序1数量最多的放前面
			if(s[0].cnt1 > 0 && s[1].cnt0 > 0 && s[2].cnt0 > 0){	//优先“100”组合
				s[0].cnt1 --;
				s[1].cnt0 --;
				s[2].cnt0 --;
				cout << "1";
			}
			else if(s[0].cnt1 > 0 && s[1].cnt1 > 0 && s[2].cnt1 > 0){	//其次"111"组合
				s[0].cnt1 --;
				s[1].cnt1 --;
				s[2].cnt1 --;
				cout << "1";
			}
			else cout << "0";
		}
		cout << nl;
	}
	

}

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0),cout.tie(0);

	solve();
}

标签:XOR,ss,--,Permutations,int,cnt1,cnt0,include
From: https://www.cnblogs.com/J-12045/p/17219566.html

相关文章

  • [CF1788F] XOR, Tree, and Queries
    题目描述Youaregivenatreeof$n$vertices.Theverticesarenumberedfrom$1$to$n$.Youwillneedtoassignaweighttoeachedge.Lettheweight......
  • CF888D Almost Identity Permutations 题解
    CF链接:AlmostIdentityPermutationsLuogu链接:AlmostIdentityPermutations${\scr\color{Aquamarine}{\text{Solution}}}$前言这好像是一道能用数学秒掉的题目但......
  • 线段树维护哈希 | CF213E Two Permutations + CF452F Permutation
    __终于学到了线段树维护xx,嘿嘿,嘿嘿嘿..树树:D做了两题,感觉知识点是维护区间相同不相同可以拿hash做,不连续的区间也可以拿hash维护主要是出得很有想法,太妙了要想得到hh1.......
  • 「解题报告」ARC133D Range XOR
    不会做。考虑拆分成前缀和的形式。设\(w_i=1\oplus2\oplus\cdots\oplusi\),打表容易发现:\[w_i=\begin{cases}i&i\equiv0\pmod4\\1&i\equiv1\pmod......
  • MortalKombat(Xorist家族)勒索软件分析
    目录MortalKombat勒索软件分析startloadConfig_401F87set_lockfile_open_402342walks_4013A8tea_enc_4017ECtea_dec_4018B0WndProc_401AB9right_401216enc_or_dec_40124F总......
  • 如何判断linux 显示服务器是xorg (x11) 还是wayland
    背景大家好,我是Tarzan。在使用Linux操作系统的时候我们需要注意自己的显示服务是xorg还是wayland模式,因为有很多软件或者框架不支持或者兼容性不好,大部分都支持x11,但是w......
  • [AtCoder Regular Contest 156][D. Xor Sum 5]
    题目链接:D-XorSum5题目大意:给定一个长度为\(N(1\leN\le1000)\)的数组\(A(0\leA_i\le1000)\),以及一个正整数\(K(1\leK\le10^{12})\)。现在要在这\(N\)个数......
  • XOR 加密
      #include<stdio.h>#include<stdlib.h>#include<string.h>#defineKEY0x86intmain(){charp_data[16]={"20183125уер╒"};charEncrypt[16]......
  • Substring XOR Queries
    SubstringXORQueriesYouaregivenabinarystring  s ,anda2D integerarray queries where queries[i]=[firsti,secondi] .Forthe ith query,fi......
  • Codeforces Round #851 (Div. 2)-F. XOR, Tree, and Queries-树、异或、并查集
    题目:https://codeforces.com/contest/1788/problem/F题解:(首先他和线性基没什么瓜系)想这个问题大概可以分成几个部分:1、很自然地考虑记\(p_x\)表示从根节点走到x路径......