B . CODE
题目描述
给了一个长度为(2^n)-1的01字符串,每一个字节有可能出错的概率是1/10^20。
字符串s,字符s[i],对于每一个i(i=2^k), s[i]满足: s[i]=⨁(s[j]),j&i=i 。【s[i] = the xor sum of all position j which k−th digit is 1 in binary representation.】
eg:s[3]=1,s[5]=1,s[6]=0,s[7]=1
then
s[1]=s[3]⨁s[5]⨁s[7]=1
s[2]=s[3]⨁s[6]⨁s[7]=0
s[4]=s[5]⨁s[6]⨁s[7]=0
The final message to be sent is 1010101。
求原字符串,可以假设所给的字符串最多只有一个错误。输入
3 3 1010101 1010111 1110101输出
1010101 1010101 1010101
//#include<bits/stdc++.h>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<cstring>
#include<cstdlib>
#include<string>
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<queue>
#include<deque>
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200200;
const int M=5002;
const int mod=998244353;
LL a[N],f[M][M];
LL mp[N];
int b[N];
bool vis[N];
int dx[]={-1,0,0,1},dy[]={0,1,-1,0};
int main()
{
cin.tie(0); cout.tie(0); ios::sync_with_stdio(false);
int T=1;
cin>>T;
int n;
cin>>n;
while(T--)
{
string s;
cin>>s;
int len=s.size();
s=" "+s;
int flag=0;
for(int i=1;i<=len;i<<=1)
{
int sum=0;
for(int j=1;j<=len;j++)
{
if((j&i)==i&&(i!=j))
{
sum^=(s[j]-'0');
}
}
if(sum!=s[i]-'0') flag|=i;
}
if(flag!=0)
{
if(s[flag]=='0') s[flag]='1';
else s[flag]='0';
}
for(int i=1;i<=len;i++) cout<<s[i];
cout<<endl;
}
return 0;
}