POJ1087 A Plug of UNIX
你作为某高管去住宿了,然后宾馆里有几种插座,分别有其对应型号,你携带了几种用电器(手机,电脑一类的),也有其对应型号;可是不一定用电器就能和插座匹配上,于是宾馆的商店里提供了一些转换器,这些转换器可以将某一型号电源转换成另一型号的。问,你的用电器最少会有多少种无法充电
源点向电器连边,容量为1,电器向对应的插座连边,容量为1,对于转换器,在插座与插座之间连边,容量为inf,所有插座向汇点连边,容量为插座的个数~
#include<cstdio>
#include<algorithm>
#include<queue>
#include<cstring>
#include<map>
#include<iostream>
#include<string>
using namespace std;
const int maxn=;
const int inf=1e9;
queue<int> q;
int n;
int g[maxn][maxn];
int pre[maxn];
int flow[maxn];
int maxflow;
int bfs (int s,int t) {
while (!q.empty()) q.pop();
for (int i=;i<=n;i++) pre[i]=-;
pre[s]=;
q.push(s);
flow[s]=inf;
while (!q.empty()) {
int x=q.front();
q.pop();
if (x==t) break;
for (int i=;i<=n;i++)
if (g[x][i]>&&pre[i]==-) {
pre[i]=x;
flow[i]=min(flow[x],g[x][i]);
q.push(i);
}
}
if (pre[t]==-) return -;
else return flow[t];
}
void Edmonds_Karp (int s,int t) {
int increase=;
while ((increase=bfs(s,t))!=-) {
int k=t;
while (k!=s) {
int last=pre[k];
g[last][k]-=increase;
g[k][last]+=increase;
k=last;
}
maxflow+=increase;
}
}
map<string,int> pos;
int main () {
string s1,s2;
int N,M,cnt,st,ed;
while (~scanf("%d",&N)) {
pos.clear();
memset(g,,sizeof(g));
maxflow=;
st=;
ed=;
cnt=;
while (N--) {
cin>>s1;
pos[s1]=cnt;
g[][cnt++]=;
}
scanf ("%d",&M);
for (int i=;i<M;i++) {
cin>>s1>>s2;
if (pos[s1]==) pos[s1]=cnt++;
if (pos[s2]==) pos[s2]=cnt++;
g[pos[s1]][ed]=;
g[pos[s2]][pos[s1]]=;
}
scanf ("%d",&N);
while (N--) {
cin>>s1>>s2;
if (pos[s1]==) pos[s1]=cnt++;
if (pos[s2]==) pos[s2]=cnt++;
g[pos[s2]][pos[s1]]=inf;
}
n=cnt-;
Edmonds_Karp (st,ed);
printf ("%d\n",M-maxflow);
}
return ;
}
POJ1087 A Plug of UNIX的更多相关文章
- POJ1087 A Plug for UNIX —— 最大流
题目链接:https://vjudge.net/problem/POJ-1087 A Plug for UNIX Time Limit: 1000MS Memory Limit: 65536K T ...
- POJ1087:A Plug for UNIX(最大流)
A Plug for UNIX 题目链接:https://vjudge.net/problem/POJ-1087 Description: You are in charge of setting u ...
- POJ1087 A Plug for UNIX(网络流)
A Plug for UNIX Time Limit: 1000MS Memory Limit: 65536K Total S ...
- POJ1087 A Plug for UNIX 【最大流】
A Plug for UNIX Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 13855 Accepted: 4635 ...
- POJ1087 A Plug for UNIX 2017-02-12 13:38 40人阅读 评论(0) 收藏
A Plug for UNIX Description You are in charge of setting up the press room for the inaugural meeting ...
- [POJ1087]A Plug for UNIX
题目描述 Description You are in charge of setting up the press room for the inaugural meeting of the Uni ...
- poj1087 A Plug for UNIX(网络流最大流)
http://poj.org/problem?id=1087 好久没遇见过这么坑的题了这个题真是挫的够可以的.题目大意:你作为某高管去住宿了,然后宾馆里有几种插座,分别有其对应型号,你携带了几种用电器 ...
- poj1087 A Plug for UNIX & poj1459 Power Network (最大流)
读题比做题难系列…… poj1087 输入n,代表插座个数,接下来分别输入n个插座,字母表示.把插座看做最大流源点,连接到一个点做最大源点,流量为1. 输入m,代表电器个数,接下来分别输入m个电器,字 ...
- 【uva753/poj1087/hdu1526-A Plug for UNIX】最大流
题意:给定n个插座,m个插头,k个转换器(x,y),转换器可以让插头x转成插头y.问最少有多少个插头被剩下. 题解: 最大流或者二分图匹配.然而我不知道怎么打二分图匹配..打了最大流.这题字符串比较坑 ...
- POJ-1087 A Plug for UNIX (网络流)
思路 电器数1 ~ 100,附带100种接口,注意题目:You notice that some of the devices use plugs for which there is no rece ...
随机推荐
- AcWing 154. 滑动窗口
https://www.acwing.com/problem/content/156/ #include <iostream> using namespace std; ; int a[N ...
- 工具使用:xmind
概念 心智图,又称脑图.思维导图.灵感触发图.概念地图或思维地图,是一种图像式思维的工具与及一种利用图像式思考辅助工具来表达思维的工具. 详细的可以查看这里(维基百科)还有这里(百度百科) 用了思维导 ...
- anaconda+pytorch安装(无GPU版本)
anaconda+pytorch安装(无GPU版本) 待办 https://blog.csdn.net/nnUyi/article/details/78471326
- js获取后台map格式数据
后台: @RequestMapping("/dictList") @ResponseBody public Map<String, Object> positionLi ...
- Array,String,Set,Map
热爱前端的17号诶 积跬步以致千里 积怠惰以致深渊 博客园 首页 新随笔 联系 管理 随笔 - 58 文章 - 2 评论 - 65 最新数组方法(包括es6) for...of 是 ES6 新引入 ...
- 在x64的Ubuntu系统下安装64bit的交叉编译工具aarch64-linux-gnu-gcc【转】
sudo apt-cache search aarch64 查看哪些版本可以安装: sudo apt--aarch64-linux-gnu 安装一个gcc开头的5版本的支持64bit ARM linu ...
- 《aelf经济和治理白皮书》重磅发布:为DAPP提供治理高效、价值驱动的生态环境
2020年2月17日,aelf正式发布<aelf经济和治理白皮书>,这是aelf继项目白皮书后,在aelf网络经济模型和治理模式方面的权威论述.<aelf经济和治理白皮书>描述 ...
- python学习之 logging包
1,logging包 python的一个包,专门用来写日志的. 官方一共划分了6个等级的log类型,分别对应重要性等级50,40,30,20,10,0: 级别排序:CRITICAL > ERRO ...
- c++中const变量定义与头文件包含的有关问题
在使用C++进行程序开发的时候,有个常识我们很熟悉,就是把类的定义写在.h文件中,把类的具体实现写在.cpp文件中.这毫无疑问是对的.但我们很少去思考为什么要这样做,本文结合自己的学习体会,对头文件及 ...
- Java-POJ1002-487-3279(含c++代码)
Java 的读入还不熟练,解决不了空行的问题,还是只能用c++ A掉,唉~ 之后要把这个坑补掉 解决了,开心(*^▽^*)以下是AC的Java代码 以下是C++代码 #include<cstdi ...