poj 2724 Purifying Machine
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 5408 | Accepted: 1575 |
Description
One day, Mike's machine was infected. When Mike found out, he had already done some operations and the cheeses operated by this infected machine were infected too. He cleaned his machine as quickly as he could, and now he needs to clean the infected cheeses with the minimum number of operations. If a cheese is infected, cleaning this cheese with the machine one or more times will make this cheese free from virus again; but if a cheese is not infected, operation on this cheese will make it go bad.
Now given the infected operations Mike has done, you need to find out the minimum number of operations that must be performed to clean all the infected cheeses without making any clean cheese go bad.
Input
Output
Sample Input
3 3
*01
100
011
0 0
Sample Output
2 翻译:mike搞了一台机器专门清洗中毒的奶酪,有一天,机器也中毒了并且开始自顾自的清洗奶酪,被中毒的机器清洗的奶酪也会中毒,mike即时发现了这个问题,修复机器后,想要以最少的操作数,让之前中毒的奶酪回复正常。
思路:如果一个操作带有‘*’,那么机器将会同时清理两个奶酪,那么在最后清理奶酪时,尽量使用带'*'号的操作可以更快的清理完奶酪,若我们建图,并且让中毒奶酪的编号相差1的奶酪连一条边,这些连边的两块奶酪使用‘*’操作来清理1次就行,这相当于找一个最大独立集,集合中每两块奶酪都没有连边,若把集合中的奶酪全部清理了,就相当于把所有中毒奶酪都清洗了;
AC代码:
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<queue>
#include<set>
#include<vector>
#include<cstring>
#include<string>
#include<bitset>
using namespace std;
#define INF 0x3f3f3f3f
const int N_MAX = ;
int V;//点的个数
vector<int>G[N_MAX];
int match[N_MAX];
bool used[N_MAX];
void add_edge(int u, int v) {
G[u].push_back(v);
G[v].push_back(u);
} bool dfs(int v) {
used[v] = true;
for (int i = ; i < G[v].size(); i++) {
int u = G[v][i], w = match[u];
if (w < || !used[w] && dfs(w)) {
match[v] = u;
match[u] = v;
return true;
}
}
return false;
} int bipartite_matching() {
int res = ;
memset(match, -, sizeof(match));
for (int v = ; v < V; v++) {
if (match[v] < ) {
memset(used, , sizeof(used));
if (dfs(v))
res++;
}
}
return res;
} int N, M;
string s[N_MAX];
vector<int>operation;
int main() {
while (scanf("%d%d",&N,&M)&&N) {
//operation.resize(N);
for (int i = ; i < M;i++)
cin >> s[i];
for (int i = ; i < M; i++) {
int x=;
for (int j = ; j < s[i].size();j++) {
if(s[i][j]=='')x += << (N - j - );
}
operation.push_back(x);
for (int j = ; j < s[i].size();j++) {
if (s[i][j] == '*')x += << (N - j - );
}
operation.push_back(x);
}
sort(operation.begin(),operation.end());
operation.erase(unique(operation.begin(),operation.end()),operation.end());
V = operation.size();
for (int i = ; i < V;i++) {
for (int j = i + ; j < V;j++) {
bitset<>bit = operation[i] ^ operation[j];//找找二进制有几位是一样的
if (bit.count() == ) {//只有一位是一样的,可以让机器使用'*'操作,符合连边条件
add_edge(i, j);
}
}
}
printf("%d\n",V-bipartite_matching());
for (int i = ; i < V;i++) {
G[i].clear();
}
operation.clear();
}
return ;
}
poj 2724 Purifying Machine的更多相关文章
- POJ 2724 Purifying Machine(最大独立集)
POJ 2724 Purifying Machine 题目链接 题意:这题题意有点没看懂.看了别人的题解, 给出m串长度为n的01串. 有些串中可能包括,这种串能够表示两个串,为1 和为0. 反复的算 ...
- POJ 2724 Purifying Machine (二分图匹配)
题意 给定m个长度为n的01串(*既表示0 or 1.如*01表示001和101).现在要把这些串都删除掉,删除的方法是:①一次删除任意指定的一个:②如果有两个串仅有一个字符不同,则可以同时删除这两个 ...
- poj 2724 Purifying Machine(二分图最大匹配)
题意: 有2^N块奶酪,编号为00...0到11..1. 有一台机器,有N个开关.每个开关可以置0或置1,或者置*.但是规定N个开关中最多只能有一个开关置*. 一旦打开机器的开关,机器将根据N个开关的 ...
- poj 2724 Purifying Machinef
poj 2724 Purifying Machinef 题意 每一个01串中最多含有一个'*','*'既可表示0也可表示1,给出一些等长的这样的01串,问最少能用多少个这样的串表示出这些串.如:000 ...
- POJ 2724
Purifying Machine Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4014 Accepted: 1127 ...
- TTTTTTTTTTTTTTTTTT POJ 2724 奶酪消毒机 二分匹配 建图 比较难想
Purifying Machine Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5004 Accepted: 1444 ...
- 【poj2724】 Purifying Machine
http://poj.org/problem?id=2724 (题目链接) 题意 Mike有一个机器可以帮助他清理奶酪,每个奶酪由一个n位二进制数表示,机器上一共有n个按钮,每个按钮有1,0,*,其中 ...
- POJ 1276 Cash Machine -- 动态规划(背包问题)
题目地址:http://poj.org/problem?id=1276 Description A Bank plans to install a machine for cash withdrawa ...
- POJ2724:Purifying Machine——题解
http://poj.org/problem?id=2724 描述迈克是奶酪工厂的老板.他有2^N个奶酪,每个奶酪都有一个00 ... 0到11 ... 1的二进制数.为了防止他的奶酪免受病毒侵袭,他 ...
随机推荐
- JDK的安装以及环境变量的配置
一.JDK的安装 1.百度搜索jdk1.8 2.进入网页选择Downloads 3. 选择电脑的版本(x86 32位 x64 64位) 4.下载好后,直接双击即可,一直下一步即可完成安装 二.环境变量 ...
- MarkdownPad 2 Pro 注册码
MarkdownPad 2 Pro 注册码 MarkdownPad 是 Windows 平台上一个功能完善的 Markdown 编辑器. 提供了语法高亮和方便的快捷键功能,给您最好的 Markdown ...
- iOS 开发 Xib 的嵌套使用
最近公司项目需要使用 Xib 中嵌套 Xib来布局界面的, 研究了很久才实现!!! 分享给大家,希望帮助到更多的开发者...... 开发中自定义界面有两种方式 一: 纯代码实现 适合单个极度复杂的界面 ...
- C#MySQL增删改查
首先在项目中添加引用 using MySql.Data.MySqlClient; 连接字符串 private string connString="server=localhost;use ...
- MySQL查询显示连续的结果
#mysql中 对于查询结果只显示n条连续行的问题# 在领扣上碰到的一个题目:求满足条件的连续3行结果的显示 X city built a new stadium, each day many peo ...
- fread()创建文件和file_exists()文件缓存问题
①fread('','w')调用当文件不存在时创建文件,其中参数使用了fread('',"w")导致无法创建文件,修改单引号之后操作正常. ②项目当中新建日志文件,需要判断日志文件 ...
- Linux-缓存服务
Memcached 基本操作 解释 命令 安装 yum install memcached 启动 memcached -d -l -m -p 停止 kill pid 查看某个端口是否通:telnet ...
- destoon 多表联合查询时出现解析错误,parse_str函数解析错误
数据库前缀 wb_ 标签 ,调用文章时获取评论数量 <!--{php $tags=tag("table=article_24 a left join wb_comment_stat ...
- Geode 集群搭建,快速上手使用
Geode 介绍: Geode是一个提供实时.一致访问大型分布式云平台下数据密集型应用的数据管理平台. Geode 通过跨多进程,把内存.CPU.网络资源和可选的本地磁盘汇集起来,来管理应用程序对象及 ...
- LeetCode(165) Compare Version Numbers
题目 Compare two version numbers version1 and version2. If version1 > version2 return 1, if version ...