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 ...
随机推荐
- Golang的值类型和引用类型的范围、存储区域、区别
常见的值类型和引用类型分别有哪些? 值类型:基本数据类型 int 系列, float 系列, bool, string .数组和结构体struct,使用这些类型的变量直接指向存在内存中的值,值类型的变 ...
- P2590 [ZJOI2008]树的统计(树链剖分)
P2590 [ZJOI2008]树的统计 虽然是入门树剖模板 但是我终于1A了(大哭) 懒得写啥了(逃 #include<iostream> #include<cstdio> ...
- Java中的Volatile和synchronized的区别
Synchronized和Volatile四个不同点: 1.粒度不同,前者锁对象和类 ,后者针对变量2.syn阻塞,volatile线程不阻塞3.syn保证三大特性,volatile不保证原子性4.s ...
- python简说(十九)操作redis
一.关系型数据库 mysql.oracle.sql server sql语句来操作数据,数据是存在磁盘上的 非关系型数据库.NOSQL,redis,memcache key = vaule 1.数据是 ...
- python简说(十二)time模块
1.时间戳 print(int(time.time())) 2.取当前格式化好的时间 time.strftime('%Y-%m-%d %H:%M:%S') 3.时间戳转为格式化好的时间 time1 = ...
- LVS群集配置
第一步:网络环境配置内网网段:10.0.0.0/24DR:10.0.0.254rs1:10.0.0.1rs2:10.0.0.2nfs:10.0.0.3 第二步:nfs和web服务搭建 nfs服务器:安 ...
- PyCharm笔记之搭建Python开发环境
新建一个空helloworld项目,然后新建一个main.py文件: 此时还无法运行,因为没有配置项目的入口脚本,通过下图的步骤指定一个: 在scrip框里填入你的入口脚本 之后就可以点击绿色的播放按 ...
- 网络存储结构简明分析—DAS、NAS和SAN 三者区别
存储的总体分类 主流存储结构 网络存储结构大致分为三种:直连式存储(DAS:Direct Attached Storage).存储区域网络(SAN:Storage Area Network ...
- noip模拟【array】
array by ysy [题目描述] 给定一个长度为n的数列,每次你可以进行以下操作之一: (1)将一个数+a: (2)将一个数-a: (3)将一个数+b: (4)将一个数-b: 你需要将所有数全部 ...
- 比酒量|2012年蓝桥杯B组题解析第三题-fishers
(5')比酒量 有一群海盗(不多于20人),在船上比拼酒量.过程如下:打开一瓶酒,所有在场的人平分喝下,有几个人倒下了.再打开一瓶酒平分,又有倒下的,再次重复...... 直到开了第4瓶酒,坐着的已经 ...