D - Distinctive Character

思路:bfs

使最大的匹配数最小,转换一下,就是使最小的不匹配数最大,用bfs找最大的距离

代码:

#pragma GCC optimize(2)
#pragma GCC optimize(3)
#pragma GCC optimize(4)
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pi acos(-1.0)
#define LL long long
//#define mp make_pair
#define pb push_back
#define ls rt<<1, l, m
#define rs rt<<1|1, m+1, r
#define ULL unsigned LL
#define pll pair<LL, LL>
#define pii pair<int, int>
#define piii pair<pii, int>
#define mem(a, b) memset(a, b, sizeof(a))
#define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
//head const int N = 1e5 + ;
queue<int> q;
int dis[N*];
int main() {
fio;
int n, k, ans;
string s;
cin >> n >> k;
mem(dis, -);
for (int i = ; i <= n; i++) {
cin >> s;
int now = ;
for (int j = ; j < k; j++) if(s[j] == '') now |= <<j;
q.push(now);
dis[now] = ;
ans = now;
}
int mx = ;
while(!q.empty()) {
int now = q.front();
q.pop();
for (int i = ; i < k; i++) {
int nxt = now^(<<i);
if(dis[nxt] == -) {
dis[nxt] = dis[now] + ;
q.push(nxt);
if(dis[nxt] > mx) {
mx = dis[nxt];
ans = nxt;
}
}
}
}
for (int i = ; i < k; i++) {
if(ans & (<<i)) cout << ;
else cout << ;
}
cout << endl;
return ;
}

Codeforces 101572 D - Distinctive Character的更多相关文章

  1. Distinctive Character

    Distinctive Character Sol bfs寻找最优解. 考虑一开始把他给的状态加进队列里,这些状态的答案都是0. 每次枚举不同的一位拓展,同时要保证这个新状态没有出现过. 效率O(2^ ...

  2. Codeforces 888C: K-Dominant Character(水题)

    You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff ...

  3. Gym - 101572D Distinctive Character bfs 思维

    题目传送门 题目大意: 给出n个01串,让你构造一个字符串,使这个字符串和这些字符串中相似程度最高 尽可能低.如果两个字符串对应位置相同,则相似程度加一. 思路: 每一个01串更改自己的一部分后,都可 ...

  4. 2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017)

    A. Airport Coffee 设$f_i$表示考虑前$i$个咖啡厅,且在$i$处买咖啡的最小时间,通过单调队列优化转移. 时间复杂度$O(n)$. #include<cstdio> ...

  5. 2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017) Solution

    A - Airport Coffee 留坑. B - Best Relay Team 枚举首棒 #include <bits/stdc++.h> using namespace std; ...

  6. 模拟赛小结:2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017)

    比赛链接:传送门 本场我们队过的题感觉算法都挺简单的,不知道为啥做的时候感觉没有很顺利. 封榜后7题,罚时1015.第一次模拟赛金,虽然是北欧的区域赛,但还是有点开心的. Problem B Best ...

  7. Educational Codeforces Round 32 Problem 888C - K-Dominant Character

    1) Link to the problem: http://codeforces.com/contest/888/problem/C 2) Description: You are given a ...

  8. codeforces Gym 101572 I 有向图最小环路径

    题目链接 http://codeforces.com/gym/101572 题意  一共n个文件  存在依赖关系 根据给出的依赖关系   判断是否存在循环依赖 ,不存在的话输出SHIP IT,存在的话 ...

  9. Codeforces Round #599 (Div. 2) B2. Character Swap (Hard Version) 构造

    B2. Character Swap (Hard Version) This problem is different from the easy version. In this version U ...

随机推荐

  1. host元素的属性autoDeploy和reloadable的区别

    web.xml文件的修改会触发AutoDeploy,受host节的autoDeploy配置值的影响. class类文件修改会触发Reload操作,受reloadable配置值的影响. 而autoDep ...

  2. 【题解】 Luogu P4145 上帝造题的七分钟2 / 花神游历各国

    原题传送门 这道题实际和GSS4是一样的,只是输入方式有点区别 GSS4传送门 这道题暴力就能过qaq(这里暴力指线段树) 数据比较水 开方修改在线段树中枚举叶节点sqrt 查询区间和线段树基本操作 ...

  3. 【题解】Luogu CF1051F The Shortest Statement

    原题传送门:CF1051F The Shortest Statement 题目大意,给你一个稀疏图,q次查询,查询两点之间距离 边数减点小于等于20 这不是弱智题吗,23forever dalao又开 ...

  4. redhat6.4 gcc g++ rpm方式安装步骤

    centos源 包包自行下载 [root@localhost gcc]# rpm -ivh ppl-0.10.2-11.el6.x86_64.rpm warning: ppl-0.10.2-11.el ...

  5. android官方开发教程解释(一)

    最近准备系统学一下android开发,这里不会照搬原文,只会针对教程中一些难以理解的部分进行解释,我只是个菜鸟. 在教程第一章——入门基础里面,讲解android主题的那个小节,大概会有以下的代码: ...

  6. 【4OpenCV】OpenCV和RTSP的综合研究

    一.RTSP是什么?用来干什么? RTSP(Real Time Streaming Protocol),RFC2326,实时流传输协议,是TCP/IP协议体系中的一个应用层协议,由哥伦比亚大学.网景和 ...

  7. 关于msf反弹后门的免杀Tips

    msf是一个很强大的工具,我经常会在渗透用它来反弹shell,不过它生成的反弹后门会被不少杀软kill,这篇文章只是讲讲我在msf中一个简单的免杀小技巧 思路 我以前接触过一款python的远控,其实 ...

  8. [转]抓取当前登录用户登录密码的工具:mimipenguin

    Github项目地址 前有Mimikatz,今有mimipenguin,近日国外安全研究员huntergregal发布了工具mimipenguin,一款Linux下的密码抓取神器,可以说弥补了Linu ...

  9. Asp.Net 之 DropDownList的使用

    这里不细说,直接上案例 <td style="width: 30px;" align="right"> 年月: </td> <td ...

  10. C#DataTable 使用GroupBy方法的lamda 表达式和Linq语句写法

    https://www.cnblogs.com/johnblogs/p/6006867.html DataTable ds = new DataTable(); //1.lamda 表达式写法(推荐) ...