Distinctive Character
来源:互联网 发布:java bigdecimal最大值 编辑:程序博客网 时间:2024/06/05 19:35
题意:给你n个长度为k的01串,求一个串,让这个串和其他各个串相同位置上相同字符的总数的最大值最小
题解:对于所有的源串,进行bfs,找到能到达的串中,距离这些源串最远的串,这个串就是匹配数目最大值最小的串
#include <iostream>#include <cstdio>#include <cstring>#include <string>#include <algorithm>#include <cmath>#include <map>#include <set>#include <stack>#include <queue>#include <vector>#include <bitset>#include <functional>using namespace std;#define LL long longconst int INF = 0x3f3f3f3f;int n, m;int vis[2000000];char ch[30];void dfs(int k,int p){if (p == 1){printf("%d", k);return;}dfs(k / 2, p - 1);printf("%d", k % 2);}int main(){while (~scanf("%d%d", &n, &m)){int ma = 0, ans;memset(vis, INF, sizeof vis);queue<int>q;for (int i = 1; i <= n; i++){scanf("%s", ch);int k = 0;for (int j = 0; j < m; j++)k = k * 2 + ch[j] - '0';vis[k] = 0, q.push(k);ans = k;}while (!q.empty()){int pre = q.front();q.pop();if (vis[pre] > ma){ans = pre;ma = vis[pre];}for (int i = 0; i < m; i++){int nt = (pre ^ (1 << i));if (vis[nt] != INF) continue;vis[nt] = vis[pre] + 1;q.push(nt);}}dfs(ans,m);printf("\n");}return 0;}
阅读全文
0 0
- Distinctive Character
- Gym 101572D Distinctive Character【思维+Bfs】
- Gym 101572 D- 多源bfs- Distinctive Character
- character
- Character
- Character
- Character
- Character
- Character
- Character
- Character
- Character
- How To Make Game Art With A Distinctive Style
- 【论文笔记】Blocks that Shout:Distinctive Parts for Scene Classification
- Distinctive Image Features from Scale-Invariant Keypoints-SIFT算法译文
- Distinctive Image Features from Scale-Invariant Keypoints 翻译
- Distinctive Image Features from Scale-Invariant Keypoints-SIFT算法译文
- Distinctive Image Features from Scale-Invariant Keypoints-SIFT算法译文
- Flume+Kakfa+Spark Streaming整合(运行WordCount小例子)
- Java 中的 static 使用之静态初始化块
- shell学习二十三--case语句编写mysql启动脚本
- 获取鼠标位置坐标
- python那点事儿
- Distinctive Character
- ccf 201703 4
- js ajax实现
- 第十二周 项目(3)
- 唯快不破:当你在地址栏输入一个URL地址回车后,将会发生什么事情
- Planning mobile robot on Tree (EASY Version) UVA
- 特殊的二街魔方
- 以太坊挖矿软件反抽水-eth 免抽成破解收费小插件 (完美兼容 Claymore 原版内核,长沙矿工,圣骑士,挖矿专家,矿工队长)
- headfirst插入排序