Codeforces 101572 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的更多相关文章
- Distinctive Character
Distinctive Character Sol bfs寻找最优解. 考虑一开始把他给的状态加进队列里,这些状态的答案都是0. 每次枚举不同的一位拓展,同时要保证这个新状态没有出现过. 效率O(2^ ...
- Codeforces 888C: K-Dominant Character(水题)
You are given a string s consisting of lowercase Latin letters. Character c is called k-dominant iff ...
- Gym - 101572D Distinctive Character bfs 思维
题目传送门 题目大意: 给出n个01串,让你构造一个字符串,使这个字符串和这些字符串中相似程度最高 尽可能低.如果两个字符串对应位置相同,则相似程度加一. 思路: 每一个01串更改自己的一部分后,都可 ...
- 2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017)
A. Airport Coffee 设$f_i$表示考虑前$i$个咖啡厅,且在$i$处买咖啡的最小时间,通过单调队列优化转移. 时间复杂度$O(n)$. #include<cstdio> ...
- 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; ...
- 模拟赛小结:2017-2018 ACM-ICPC Nordic Collegiate Programming Contest (NCPC 2017)
比赛链接:传送门 本场我们队过的题感觉算法都挺简单的,不知道为啥做的时候感觉没有很顺利. 封榜后7题,罚时1015.第一次模拟赛金,虽然是北欧的区域赛,但还是有点开心的. Problem B Best ...
- 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 ...
- codeforces Gym 101572 I 有向图最小环路径
题目链接 http://codeforces.com/gym/101572 题意 一共n个文件 存在依赖关系 根据给出的依赖关系 判断是否存在循环依赖 ,不存在的话输出SHIP IT,存在的话 ...
- 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 ...
随机推荐
- 阿里云centos远程连接mysql
首先在服务器管理控制台设置防火墙规则 添加规则 使用root登录到mysql 添加一个用户名,权限为%的远程连接用户 grant all on *.* to 'yuancheng'@'%' ident ...
- account_log,pay_log,user_account 三个表的用途与区别
mysql> DESC zbphp.com_account_log; +--------------+-----------------------+------+-----+--------- ...
- python简说(二十四)发送网络请求
一.get,post请求import requestsurl='http://127.0.0.1:8999/api/upload'# data = {'username':'testuser1','p ...
- python简说(五)操作文件
f = open('users.txt',encoding='utf-8') #读文件的时候,必须存在在才可以读 文件对象,或者文件句柄res = f.read()print(res)f.close( ...
- Linux下的查找技巧
Find知识点: -mtime ——修改时间 -ctime ——创建时间 -atime ——访问时间 mtime 举例说明: -mtime n : n为数字,意思为在n天之前的“一天之内”被更改过内容 ...
- linux 压缩工具
gzip gunzip zcat bzip2 bunzip2 bzcat xz unxz xzcat a: gzip 用法 # gzip file 压缩文件 不会保留源文件 直接生成 file.g ...
- C# 反射小结
废话不多说,直接上代码. 1.typeof(类名):它是一个运算符 eg_1:Type type = typeof(int) ; eg_2:public class Student { Type ty ...
- ODAC(V9.5.15) 学习笔记(四)TCustomDADataSet(5)
7.其他 名称 类型 说明 FindKey 类似于BDE的相关功能,在当前数据集中查找指定的记录 FindNearest 移动游标到最符合查找要求的第一条记录处 FindMacro 当前数据集中是否存 ...
- Python3 tkinter基础 Checkbutton anchor for生成多个控件并西对齐
Python : 3.7.0 OS : Ubuntu 18.04.1 LTS IDE : PyCharm 2018.2.4 Conda ...
- POJ 2226 Muddy Fields(最小点覆盖)题解
题意:一片r*c的地,有些地方是泥地,需要铺地板.这些地板宽1,长无限,但只能铺在泥地上不能压到其他地方,问你铺满所有泥地最少几块 思路:我们把一行中连续的泥地看成整体,并把所有横的整体里的点编成一个 ...