2021年ICPC陕西省赛热身赛 B.CODE(位运算)

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;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Vijurria

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值