D - Distinctive Character

思路:bfs

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

代码:

  1. #pragma GCC optimize(2)
  2. #pragma GCC optimize(3)
  3. #pragma GCC optimize(4)
  4. #include<bits/stdc++.h>
  5. using namespace std;
  6. #define fi first
  7. #define se second
  8. #define pi acos(-1.0)
  9. #define LL long long
  10. //#define mp make_pair
  11. #define pb push_back
  12. #define ls rt<<1, l, m
  13. #define rs rt<<1|1, m+1, r
  14. #define ULL unsigned LL
  15. #define pll pair<LL, LL>
  16. #define pii pair<int, int>
  17. #define piii pair<pii, int>
  18. #define mem(a, b) memset(a, b, sizeof(a))
  19. #define fio ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
  20. #define fopen freopen("in.txt", "r", stdin);freopen("out.txt", "w", stout);
  21. //head
  22.  
  23. const int N = 1e5 + ;
  24. queue<int> q;
  25. int dis[N*];
  26. int main() {
  27. fio;
  28. int n, k, ans;
  29. string s;
  30. cin >> n >> k;
  31. mem(dis, -);
  32. for (int i = ; i <= n; i++) {
  33. cin >> s;
  34. int now = ;
  35. for (int j = ; j < k; j++) if(s[j] == '') now |= <<j;
  36. q.push(now);
  37. dis[now] = ;
  38. ans = now;
  39. }
  40. int mx = ;
  41. while(!q.empty()) {
  42. int now = q.front();
  43. q.pop();
  44. for (int i = ; i < k; i++) {
  45. int nxt = now^(<<i);
  46. if(dis[nxt] == -) {
  47. dis[nxt] = dis[now] + ;
  48. q.push(nxt);
  49. if(dis[nxt] > mx) {
  50. mx = dis[nxt];
  51. ans = nxt;
  52. }
  53. }
  54. }
  55. }
  56. for (int i = ; i < k; i++) {
  57. if(ans & (<<i)) cout << ;
  58. else cout << ;
  59. }
  60. cout << endl;
  61. return ;
  62. }

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. 阿里云centos远程连接mysql

    首先在服务器管理控制台设置防火墙规则 添加规则 使用root登录到mysql 添加一个用户名,权限为%的远程连接用户 grant all on *.* to 'yuancheng'@'%' ident ...

  2. account_log,pay_log,user_account 三个表的用途与区别

    mysql> DESC zbphp.com_account_log; +--------------+-----------------------+------+-----+--------- ...

  3. python简说(二十四)发送网络请求

    一.get,post请求import requestsurl='http://127.0.0.1:8999/api/upload'# data = {'username':'testuser1','p ...

  4. python简说(五)操作文件

    f = open('users.txt',encoding='utf-8') #读文件的时候,必须存在在才可以读 文件对象,或者文件句柄res = f.read()print(res)f.close( ...

  5. Linux下的查找技巧

    Find知识点: -mtime ——修改时间 -ctime ——创建时间 -atime ——访问时间 mtime 举例说明: -mtime n : n为数字,意思为在n天之前的“一天之内”被更改过内容 ...

  6. linux 压缩工具

    gzip gunzip zcat bzip2 bunzip2 bzcat xz unxz xzcat a:  gzip 用法 # gzip file  压缩文件 不会保留源文件 直接生成 file.g ...

  7. C# 反射小结

    废话不多说,直接上代码. 1.typeof(类名):它是一个运算符 eg_1:Type type = typeof(int) ; eg_2:public class Student { Type ty ...

  8. ODAC(V9.5.15) 学习笔记(四)TCustomDADataSet(5)

    7.其他 名称 类型 说明 FindKey 类似于BDE的相关功能,在当前数据集中查找指定的记录 FindNearest 移动游标到最符合查找要求的第一条记录处 FindMacro 当前数据集中是否存 ...

  9. Python3 tkinter基础 Checkbutton anchor for生成多个控件并西对齐

             Python : 3.7.0          OS : Ubuntu 18.04.1 LTS         IDE : PyCharm 2018.2.4       Conda ...

  10. POJ 2226 Muddy Fields(最小点覆盖)题解

    题意:一片r*c的地,有些地方是泥地,需要铺地板.这些地板宽1,长无限,但只能铺在泥地上不能压到其他地方,问你铺满所有泥地最少几块 思路:我们把一行中连续的泥地看成整体,并把所有横的整体里的点编成一个 ...