描述

You are in charge of setting up the press room for the inaugural meeting of the United Nations Internet eXecutive (UNIX), which has an international mandate to make the free flow of information and ideas on the Internet as cumbersome and bureaucratic as possible.
Since the
room was designed to accommodate reporters and journalists from around
the world, it is equipped with electrical receptacles to suit the
different shapes of plugs and voltages used by appliances in all of the
countries that existed when the room was built. Unfortunately, the room
was built many years ago when reporters used very few electric and
electronic devices and is equipped with only one receptacle of each
type. These days, like everyone else, reporters require many such
devices to do their jobs: laptops, cell phones, tape recorders, pagers,
coffee pots, microwave ovens, blow dryers, curling
irons, tooth
brushes, etc. Naturally, many of these devices can operate on batteries,
but since the meeting is likely to be long and tedious, you want to be
able to plug in as many as you can.
Before the meeting begins, you
gather up all the devices that the reporters would like to use, and
attempt to set them up. You notice that some of the devices use plugs
for which there is no receptacle. You wonder if these devices are from
countries that didn't exist when the room was built. For some
receptacles, there are several devices that use the corresponding plug.
For other receptacles, there are no devices that use the corresponding
plug.
In order to try to solve the problem you visit a nearby parts
supply store. The store sells adapters that allow one type of plug to be
used in a different type of outlet. Moreover, adapters are allowed to
be plugged into other adapters. The store does not have adapters for all
possible combinations of plugs and receptacles, but there is
essentially an unlimited supply of the ones they do have.

输入

The
input will consist of one case. The first line contains a single
positive integer n (1 <= n <= 100) indicating the number of
receptacles in the room. The next n lines list the receptacle types
found in the room. Each receptacle type consists of a string of at most
24 alphanumeric characters. The next line contains a single positive
integer m (1 <= m <= 100) indicating the number of devices you
would like to plug in. Each of the next m lines lists the name of a
device followed by the type of plug it uses (which is identical to the
type of receptacle it requires). A device name is a string of at most 24
alphanumeric
characters. No two devices will have exactly the same
name. The plug type is separated from the device name by a space. The
next line contains a single positive integer k (1 <= k <= 100)
indicating the number of different varieties of adapters that are
available. Each of the next k lines describes a variety of adapter,
giving the type of receptacle provided by the adapter, followed by a
space, followed by the type of plug.

输出

A line containing a single non-negative integer indicating the smallest number of devices that cannot be plugged in.

样例输入

4
A
B
C
D
5
laptop B
phone C
pager B
clock B
comb X
3
B X
X A
X D

样例输出

1

题意

n个插头,m个插座,k个交换器,输出最少多少插头没有插入插座

题解

插头连源点S流量为字符重复的次数,插座连汇点T流量为字符出现的次数,连交换器边流量INF,跑最大流即可

这里用哈希建图比较方便,然后交换器边是后面的指向前面的

代码

 #include<bits/stdc++.h>
using namespace std; const int maxn=1e5+;
const int maxm=2e5+;
int n,m,S,T;
int deep[maxn],q[];
int FIR[maxn],TO[maxm],CAP[maxm],COST[maxm],NEXT[maxm],tote; void add(int u,int v,int cap)
{
TO[tote]=v;
CAP[tote]=cap;
NEXT[tote]=FIR[u];
FIR[u]=tote++; TO[tote]=u;
CAP[tote]=;
NEXT[tote]=FIR[v];
FIR[v]=tote++;
}
bool bfs()
{
memset(deep,,sizeof deep);
deep[S]=;q[]=S;
int head=,tail=;
while(head!=tail)
{
int u=q[++head];
for(int v=FIR[u];v!=-;v=NEXT[v])
{
if(CAP[v]&&!deep[TO[v]])
{
deep[TO[v]]=deep[u]+;
q[++tail]=TO[v];
}
}
}
return deep[T];
}
int dfs(int u,int fl)
{
if(u==T)return fl;
int f=;
for(int v=FIR[u];v!=-&&fl;v=NEXT[v])
{
if(CAP[v]&&deep[TO[v]]==deep[u]+)
{
int Min=dfs(TO[v],min(fl,CAP[v]));
CAP[v]-=Min;CAP[v^]+=Min;
fl-=Min;f+=Min;
}
}
if(!f)deep[u]=-;
return f;
}
int maxflow()
{
int ans=;
while(bfs())
ans+=dfs(S,<<);
return ans;
}
void init()
{
tote=;
memset(FIR,-,sizeof FIR);
}
int N,M,K,tot=;
map<string,int>has;
string s,s1;
int main()
{
init();
S=,T=;
cin>>N;
for(int i=;i<=N;i++)
{
cin>>s;
if(!has[s])has[s]=tot++;
add(S,has[s],);
}
cin>>M;
for(int i=;i<=M;i++)
{
cin>>s1>>s;
if(!has[s])has[s]=tot++;
add(has[s],T,);
}
cin>>K;
for(int i=;i<=K;i++)
{
cin>>s>>s1;
if(!has[s])has[s]=tot++;
if(!has[s1])has[s1]=tot++;
add(has[s1],has[s],<<);
}
printf("%d\n",M-maxflow());
return ;
}

TZOJ 1911 A Plug for UNIX(最大流)的更多相关文章

  1. 【poj1087/uva753】A Plug for UNIX(最大流)

    A Plug for UNIX   Description You are in charge of setting up the press room for the inaugural meeti ...

  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 —— 最大流

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

  4. POJ A Plug for UNIX (最大流 建图)

    Description You are in charge of setting up the press room for the inaugural meeting of the United N ...

  5. UVa 753 A Plug for UNIX (最大流)

    题意:给定 n 种插座,m种设备,和k个转换器,问你最少有几台设备不能匹配. 析:一个很裸的网络流,直接上模板就行,建立一个源点s和汇点t,源点和每个设备连一条边,每个插座和汇点连一条边,然后再连转换 ...

  6. ZOJ1157, POJ1087,UVA 753 A Plug for UNIX (最大流)

    链接 : http://acm.hust.edu.cn/vjudge/problem/viewProblem.action? id=26746 题目意思有点儿难描写叙述 用一个别人描写叙述好的. 我的 ...

  7. hdu 1087 A Plug for UNIX 最大流

    题意:http://www.phpfans.net/article/htmls/201012/MzI1MDQw.html 1.在一个会议室里有n种插座,每种插座一个: 2.每个插座只能插一种以及一个电 ...

  8. uva753 A Plug for UNIX 网络流最大流

    C - A Plug for UNIX    You are in charge of setting up the press room for the inaugural meeting of t ...

  9. poj 1087 C - A Plug for UNIX 网络流最大流

    C - A Plug for UNIXTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudge/contes ...

随机推荐

  1. clientX,screenX,pageX,offsetX的异同

    pageX/pageY: 鼠标相对于整个页面的X/Y坐标.注意,整个页面的意思就是你整个网页的全部,比如说网页很宽很长,宽2000px,高3000px,那pageX,pageY的最大值就是它们了. 特 ...

  2. java swing 制作一个登陆界面,亲测有效

    一.介绍 Swing 是一个为Java设计的GUI工具包. Swing是JAVA基础类的一部分. Swing包括了图形用户界面(GUI)器件如:文本框,按钮,分隔窗格和表. Swing提供许多比AWT ...

  3. American Football Vocabulary!

    American Football Vocabulary! Share Tweet Share You’ll learn all about the vocabulary of American fo ...

  4. Kotlin语言编程技巧集

    空语句 Kotlin 语言中的空语句有 {} Unit when (x) { 1 -> ... 2 -> ... else -> {} // else -> Unit } Wh ...

  5. docker的完整解决方案2

    这个解决方案很简单 使用docker自带的swarm 首先初始化集群 docker swarm init 然后其余节点加入集群,这个就不说,太简单了 集群初始化后,可以查看下集群状态 docker n ...

  6. shell字符串基本操作

    shell脚本中一切变量皆字符串,所以必须掌握字符串的常用处理方法.比如获取字符串长度.获取字符串指定位置字符.替换字符串中的指定字符或者删除某些字符等操作. 1.字符串操作列表 (1)var=val ...

  7. 一个简单的dropdown(CSS+jquery)

    by 司徒正美 .dropdown{ position: relative; } .dropdown div{ position: relative; width:200px; height:30px ...

  8. SQL中ISNULL的问题。

    今天在写SQL代码的时候写了个 ISNULL(变量1,变量2),返回的结果居然是 "*" ,这个星号,郁闷了很久. 代码大意如下: ) declare @str2 int sele ...

  9. arcgis_SDE安装步骤

    弄了将近一个星期的Oracle和ArcSDE终于让我给弄好了!下面把过程跟大家分享一下: 首先是Oracle10gR2的安装,在Oracle的官方网站上可以下到Oracle10gR2的安装程序,安装过 ...

  10. cv2对图像进行旋转和放缩变换

    旋转: def get_image_rotation(image): #通用写法,即使传入的是三通道图片依然不会出错 height, width = image.shape[:2] center = ...