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的二进制数.为了防止他的奶酪免受病毒侵袭,他 ...
随机推荐
- java基础—网络编程
一.网络基础概念 首先理清一个概念:网络编程 != 网站编程,网络编程现在一般称为TCP/IP编程.
- mysql grant 用户权限说明
mysql grant 用户权限说明 Mysql 有多个个权限?经常记不住,今天总结一下,看后都能牢牢的记在心里啦!! 很明显总共28个权限:下面是具体的权限介绍:转载的,记录一下: 一.权限表 my ...
- Java基础面试操作题: 线程问题,写一个死锁(原理:只有互相都等待对方放弃资源才会产生死锁)
package com.swift; public class DeadLock implements Runnable { private boolean flag; DeadLock(boolea ...
- 洛谷 P1147 连续自然数和
洛谷 P1147 连续自然数和 看到dalao们的各种高深方法,本蒟蒻一个都没看懂... 于是,我来发一篇蒟蒻友好型的简单题解 #include<bits/stdc++.h> using ...
- nodejs开发过程中遇到的一些插件记录
1.chalk Github:https://github.com/chalk/chalk 终端样式定制插件,可自定义输出日志的样式. 1.semver 管网:https://semver.o ...
- SimpleDateFormat优化写法
在一个读取数据库数据导出到excel文件的例子当中,每次处理一个时间信息的时候,就需要创建一个SimpleDateFormat实例对象,然后再丢弃这个对象.大量的对象就这样被创建出来,占用大量的内存和 ...
- 第十四届华中科技大学程序设计竞赛决赛同步赛 Beautiful Land
It’s universally acknowledged that there’re innumerable trees in the campus of HUST.Now HUST got a b ...
- UVa 10723 LCS变形 Cyborg Genes
题解转自: UVA 10723 Cyborg Genes - Staginner - 博客园 首先这个题目肯定是按最长公共子序列的形式进行dp的,因为只有保证消去的一部分是最长公共子序列才能保证最后生 ...
- Java程序的结构和执行
目录 Java程序的结构 Java程序的执行 source code -- compiler -- class file -- JVM compiler JVM Java语法 数据类型 数据的存储 堆 ...
- 20,序列化模块 json,pickle,shelve
序列化模块 什么叫序列化? 将原本的字典,列表等内容转换成一个字符串的过程叫做序列化. 序列化的目的? 数据结构 通过序列化 转成 str. str 通过反序列化 转化成数据结构. json: jso ...