描述

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. day41-解决粘包问题

    一.socket缓冲区 研究粘包之前先看看socket缓冲区的问题: 二.socket缓存区的详细解释 每个socket被创建后,都会分配两个缓冲区,输入缓冲区和输出缓冲区. write()/send ...

  2. Aop 基础

    基础文献 https://blog.csdn.net/abcd898989/article/details/50809321 简单Demo配置 pom.xml <!-- AOP --> & ...

  3. rtmp推流开源代码备注一下

    https://github.com/runner365/AnyRTC-RTMP https://github.com/runner365

  4. 我要重新开始学习C++了!

    C++实在是博大精深!之前总不想读厚厚的C++ Primer. 然而,现在的水平真的只是初学者!只是因为写的代码太简单,所以没有用到一些特性.可以说还是门外汉! 写笔记!

  5. vue 监听state 任意值变化、监听mutations actions

    // store.watch((state) => state.count + 1, (newCount) => { // console.log(' 监听') // }) // stor ...

  6. Flex_概念

    1.Flex是事件驱动的面向对象应用程序框架和编程语言.Flex应用程序加载完毕后,需要做的就是捕获事件,然后作出响应.    Flex是一个庞大的技术组群中的一员.  2.RIA(Rich Inte ...

  7. OGNL表达式(转载)

    OGNL表达式(转载)   1.什么是OGNL OGNL:Object Graphic Navigation Language(对象图导航语言) 它是Struts2中默认的表达式语言.使用表达式需要借 ...

  8. LeetCode OJ 215. Kth Largest Element in an Array

    Find the kth largest element in an unsorted array. Note that it is the kth largest element in the so ...

  9. [jPlayer]一分钟部署jPlayer

    ---------------------------------------------------------------------------------------------------- ...

  10. week5 03 continus loading news

    1.server-side : Rest API 2. client-side 想要持续不断的下拉获取新闻 有两种做法 一种是在UI 我们调用API 获取所有的新闻 然后在UI 拉下的时候显示新闻 其 ...