描述

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. delphi treeview checkbox

    delphi treeview checkbox 最新版Berlin还没有带checkbox的treeview?

  2. 把网卡中断绑定到CPU,最大化网卡的吞吐量(转)

    先来看一下问题, 我们通过 ifconfig 查看接口的名称 为 p15p1, 一般机器为 eth0 再通过命令 ➜ ~ cat /proc/interrupts | head -n 1 && ...

  3. Jmeter的安装与使用

    安装Jmeter之前需要先配置Java环境   当配置完Jmeter运行的环境之后,就可以开始安装Jmeter了. 为什么既要告诉各位"在Linux系统内安装Jmeter",又要告诉各位"在Windo ...

  4. C++指针理解

    指针是C/C++编程中的重要概念之一,也是最容易产生困惑并导致程序出错的问题之一.利用指针编程可以表示各种数据结构,通过指针可使用主调函数和被调函数之间共享变量或数据结构,便于实现双向数据通讯:指针能 ...

  5. Todolist组件

    一.什么是组件? 组件是可复用的 Vue 实例.是页面上的某一部分. 大型项目可以拆分成很多小组件. 二.如何定义(创建)组件? 全局组件:通过Vue.component方法创建的组件是全局组件.其中 ...

  6. 前后台联调,突然所有的接口请求状态为200,但response什么都没有只有一句灰色的英文

    问题解决了,图就下次遇到截图补上: 解决问题的方法,是让后台查看数据库是否锁库,或者更改什么配置文件例如.xml文件,还有就是ip错误:

  7. delphi Drag and Drop sample 鼠标拖放操作实例

    Drag and Drop is a common operation that makes the interface user friendly: a user can drag/drop inf ...

  8. numpy-帮助文档 & 速查表.md

    目录 转相关资料: 速查表 速查代码 转相关资料: 官方手册 易佰教程 gitbook ZMonster's Blog 速查表 速查代码 # -*- coding: utf-8 -*- "& ...

  9. C# windows服务:如何获取服务程序所在的文件夹

    AppDomain.CurrentDomain.BaseDirectory 就这么一句话

  10. 手动安裝TMG2010所需Windows服务和功能

    安装 Forefront TMG 之前,必须运行准备工具,以验证是否已在您的计算机上安装成功安装 Forefront TMG 所需的应用程序.如果在未首先运行准备工具的情况下运行 Forefront ...