CF1546B. AquaMoon and Stolen String(异或思维+枚举)

传送门

思路:

其实是个假交互题,思路也很好想,只是我少看了一句话以为\(O(nm)\)的算法过不了罢了。
利用异或的思想,将所有的字符串的每一位出现的字母个数都统计一下,一定可以两两成对抵消掉,所以那个出现了奇数次的字母就是这一位的答案。
输入输出好像也没有什么用到交互的地方,不刷新缓冲区也可以过。

代码:

#pragma GCC optimize(2)
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll>PLL;
typedef pair<int, int>PII;
typedef pair<double, double>PDD;
#define I_int ll
inline ll read()
{
    ll x = 0, f = 1;
    char ch = getchar();
    while(ch < '0' || ch > '9')
    {
        if(ch == '-')f = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9')
    {
        x = x * 10 + ch - '0';
        ch = getchar();
    }
    return x * f;
}
#define read read()
#define closeSync ios::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define multiCase int T;cin>>T;for(int t=1;t<=T;t++)
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define repp(i,a,b) for(int i=(a);i<(b);i++)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define perr(i,a,b) for(int i=(a);i>(b);i--)
ll ksm(ll a, ll b, ll p)
{
    ll res = 1;
    while(b)
    {
        if(b & 1)res = res * a % p;
        a = a * a % p;
        b >>= 1;
    }
    return res;
}
const int inf = 0x3f3f3f3f;
#define PI acos(-1)

const int maxn=2e5+100;

string s[maxn];
int a[26];

void solve(){
	string res;
	int n=read,m=read;
	rep(i,1,n+n-1){
		cin>>s[i];
	}
	fflush(stdout);
	rep(i,0,m-1){
		memset(a,0,sizeof a);
		rep(j,1,2*n-1){
			a[s[j][i]-'a']++;
		}
		rep(k,0,25)
			if(a[k]&1){
				res+=k+'a';
				break;
			}
	}
	cout<<res<<endl;
	//puts("");
	fflush(stdout);
	
}

int main(){
	int _=read;
	while(_--){
		solve();
	}
	
	return 0;
}
/*
abcdef
uuuuuu
*kekeke
ekekek
xyzklm

xbcklf
eueueu
ayzdem
ukukuk
*/

posted @ 2021-07-12 12:13  OvO1  阅读(82)  评论(0编辑  收藏  举报