你作为某高管去住宿了,然后宾馆里有几种插座,分别有其对应型号,你携带了几种用电器(手机,电脑一类的),也有其对应型号;可是不一定用电器就能和插座匹配上,于是宾馆的商店里提供了一些转换器,这些转换器可以将某一型号电源转换成另一型号的。问,你的用电器最少会有多少种无法充电

源点向电器连边,容量为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的更多相关文章

  1. POJ1087 A Plug for UNIX —— 最大流

    题目链接:https://vjudge.net/problem/POJ-1087 A Plug for UNIX Time Limit: 1000MS   Memory Limit: 65536K T ...

  2. POJ1087:A Plug for UNIX(最大流)

    A Plug for UNIX 题目链接:https://vjudge.net/problem/POJ-1087 Description: You are in charge of setting u ...

  3. POJ1087 A Plug for UNIX(网络流)

                                       A Plug for UNIX Time Limit: 1000MS   Memory Limit: 65536K Total S ...

  4. POJ1087 A Plug for UNIX 【最大流】

    A Plug for UNIX Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 13855   Accepted: 4635 ...

  5. 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 ...

  6. [POJ1087]A Plug for UNIX

    题目描述 Description You are in charge of setting up the press room for the inaugural meeting of the Uni ...

  7. poj1087 A Plug for UNIX(网络流最大流)

    http://poj.org/problem?id=1087 好久没遇见过这么坑的题了这个题真是挫的够可以的.题目大意:你作为某高管去住宿了,然后宾馆里有几种插座,分别有其对应型号,你携带了几种用电器 ...

  8. poj1087 A Plug for UNIX & poj1459 Power Network (最大流)

    读题比做题难系列…… poj1087 输入n,代表插座个数,接下来分别输入n个插座,字母表示.把插座看做最大流源点,连接到一个点做最大源点,流量为1. 输入m,代表电器个数,接下来分别输入m个电器,字 ...

  9. 【uva753/poj1087/hdu1526-A Plug for UNIX】最大流

    题意:给定n个插座,m个插头,k个转换器(x,y),转换器可以让插头x转成插头y.问最少有多少个插头被剩下. 题解: 最大流或者二分图匹配.然而我不知道怎么打二分图匹配..打了最大流.这题字符串比较坑 ...

  10. POJ-1087 A Plug for UNIX (网络流)

    思路 电器数1 ~ 100,附带100种接口,注意题目:You notice that some of the devices use plugs for which there is no rece ...

随机推荐

  1. Virtual Judge POJ 1328 Radar Installation

    贪心 #include<algorithm> #include<iostream> #include<cstdio> #include<cmath> u ...

  2. 2019牛客多校第三场H Magic Line 思维

    Magic Line 题意 给出n(偶)个整点 整点范围1000,找出一条直线,把n个点分成均等的两部分 分析 因为都是整数,并且范围比较小,所以直接按x排序找到在中间那一部分,并且把中间那一部分的点 ...

  3. vue项目接入百度地图

    方法一 :使用第三方工具 vue-baidu-map 安装命令: yarn add vue-baidu-map --save 文档地址:https://dafrok.github.io/vue-bai ...

  4. Android学习11

    Android存储概念 File内部存储 通过file=openFileOutput()获得,将数据存储在data/data/+包名+files下面. layout布局文件: <?xml ver ...

  5. OO博客作业-《JML之卷》

    OO第三单元小结 一.JML语言理论基础以及应用工具链情况梳理 一句话来说,JML就是用于对JAVA程序设计逻辑的预先约定的一种语言,以便正确严格高效地完成程序以及展开测试,这在不能容忍细微错误的工程 ...

  6. Debian 系统修改网卡ens33名称为 eth0

    1. 编辑文件 /etc/default/grub 修改下面的值 初始值 GRUB_CMDLINE_LINUX="" 修改后 GRUB_CMDLINE_LINUX="ne ...

  7. PHP中使用CURL实现Get和Post请求方法

    1.cURL介绍 cURL 是一个利用URL语法规定来传输文件和数据的工具,支持很多协议,如HTTP.FTP.TELNET等.最爽的是,PHP也支持 cURL 库.本文将介绍 cURL的一些高级特性, ...

  8. 动态设置 layui select 为选中状态

    // 当前的select的id $('#type').val('你的value值'); //更新全部 layui.form.render();

  9. 《gPRC使用protobuf构建微服务》阅读笔记

    首先我需要去了解一些概念,根据百度百科了解到: l  微服务架构:微服务架构是一项在云中部署应用和服务的新技术.微服务可以在“自己的程序”中运行,并通过“轻量级设备与HTTP型API进行沟通”. l  ...

  10. JS数组删除

    --------------let items=['a','1',0,2,100,null,NaN,undefined,]; -------------要求以上数据执行后输出['1',0,2,100] ...