NCPC2017D(位运算+bfs)

题目链接:http://codeforces.com/group/Us3rfLfgWv/contest/101572

真的是巧。。打场cf做了里面的2道题就知道这题该怎么做了。。

http://codeforces.com/contest/986/problem/C

http://codeforces.com/contest/986/problem/A

其实,给定的m个数其实都在2^n内。。所以只要建个包含这2^n个结点的图,然后对每个点,往变换一次的点连长度为1的边即可。。然后问题就转化为求一个点使它到这m个点的路径的最大值d最小。。

那么就很简单了。。因为在这m个点上的d是n,然后以这m个点为中心往外扩散分别取最大值,这样可以算出每个点的最大值。。所以bfs一遍就完了。。



/**
 *          ┏┓    ┏┓
 *          ┏┛┗━━━━━━━┛┗━━━┓
 *          ┃       ┃  
 *          ┃   ━    ┃
 *          ┃ >   < ┃
 *          ┃       ┃
 *          ┃... ⌒ ...  ┃
 *          ┃              ┃
 *          ┗━┓          ┏━┛
 *          ┃          ┃ Code is far away from bug with the animal protecting          
 *          ┃          ┃   神兽保佑,代码无bug
 *          ┃          ┃           
 *          ┃          ┃        
 *          ┃          ┃
 *          ┃          ┃           
 *          ┃          ┗━━━┓
 *          ┃              ┣┓
 *          ┃              ┏┛
 *          ┗┓┓┏━━━━━━━━┳┓┏┛
 *           ┃┫┫       ┃┫┫
 *           ┗┻┛       ┗┻┛
 */ 
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<queue>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#define inc(i,l,r) for(int i=l;i<=r;i++)
#define dec(i,l,r) for(int i=l;i>=r;i--)
#define link(x) for(edge *j=h[x];j;j=j->next)
#define mem(a) memset(a,0,sizeof(a))
#define ll long long
#define eps 1e-12
#define succ(x) (1<<x)
#define lowbit(x) (x&(-x))
#define sqr(x) ((x)*(x))
#define mid (x+y>>1)
#define NM 5000005
#define nm 5000005
#define pi 3.1415926535897931
const ll inf=1000000007;
using namespace std;
ll read(){
    ll x=0,f=1;char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=-1;ch=getchar();}
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();
    return f*x;
}



int n,m,_x,_y,d[NM],ans;
queue<int>q;
int main(){
    n=read();m=read();
    inc(i,1,n){
	_x=0;
	inc(i,1,m)scanf("%1d",&_y),_x=_x*2+_y;
	q.push(_x);d[_x]=1;
    }
    while(!q.empty()){
	int t=q.front();q.pop();
	inc(i,1,m)if(!d[succ(i-1)^t])d[succ(i-1)^t]=d[t]+1,q.push(succ(i-1)^t);
	ans=t;
    }
    dec(i,m,1)printf("%d",!!(succ(i-1)&ans));putchar('\n');
    return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值