TZOJ 1911 A Plug for UNIX(最大流)
描述
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(最大流)的更多相关文章
- 【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 ...
- 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 —— 最大流
题目链接:https://vjudge.net/problem/POJ-1087 A Plug for UNIX Time Limit: 1000MS Memory Limit: 65536K T ...
- POJ A Plug for UNIX (最大流 建图)
Description You are in charge of setting up the press room for the inaugural meeting of the United N ...
- UVa 753 A Plug for UNIX (最大流)
题意:给定 n 种插座,m种设备,和k个转换器,问你最少有几台设备不能匹配. 析:一个很裸的网络流,直接上模板就行,建立一个源点s和汇点t,源点和每个设备连一条边,每个插座和汇点连一条边,然后再连转换 ...
- ZOJ1157, POJ1087,UVA 753 A Plug for UNIX (最大流)
链接 : http://acm.hust.edu.cn/vjudge/problem/viewProblem.action? id=26746 题目意思有点儿难描写叙述 用一个别人描写叙述好的. 我的 ...
- hdu 1087 A Plug for UNIX 最大流
题意:http://www.phpfans.net/article/htmls/201012/MzI1MDQw.html 1.在一个会议室里有n种插座,每种插座一个: 2.每个插座只能插一种以及一个电 ...
- 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 ...
- 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 ...
随机推荐
- 深度学习原理与框架-Tensorflow基本操作-Tensorflow中的变量
1.tf.Variable([[1, 2]]) # 创建一个变量 参数说明:[[1, 2]] 表示输入的数据,为一行二列的数据 2.tf.global_variables_initializer() ...
- Python基本数据类型以及字符串
基本数据类型 数字 int ,所有的功能,都放在int里 a1 = 123 a1 = 456 ...
- jquery接触初级-----juqery选择器实例
jquery 选择器用于触发事件,可以少写很多js代码,一般来说,基本的特效功能都能够完成 这里列举一个简单的jquery写的例子: 要求:有两种情况: 1.产品最初状态显示简约形式的品牌,即显示部分 ...
- 4:list 列表
list:列表.数组.array . list 是有序的,list的定义以 [] 为标识.如:list1 = ['name1', 'name2', 'name3'] 元素可以是任何类型的,如字符串.数 ...
- Python操作远程服务器paramiko模块介绍
paramiko模块是基于Python实现的SSH远程安全连接,可以提供在远程服务器上执行命令.上传文件到服务器或者从指定服务器下载文件的功能. paramiko模块安装方法 paramiko模块不是 ...
- [福大2018高级软工教学]团队Beta阶段成绩汇总
一.作业地址: https://edu.cnblogs.com/campus/fzu/AdvancedSoftwareEngineerning2018/homework/2465 二.Beta阶段作业 ...
- js版RSA算法
// RSA, a suite of routines for performing RSA public-key computations in// JavaScript.//// Requires ...
- flume 详细介绍
http://blog.csdn.net/a2011480169/article/details/51544664 配有详细的例子. http://www.cnblogs.com/gongxijun/ ...
- hdu3826-Squarefree number-(欧拉筛+唯一分解定理)
Squarefree number Time Limit: 10000/3000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Other ...
- 基础的正则表达式与re模块(2)
一.元字符 字符组是元字符中的一个.在字符组中所有的字符都可以匹配任意一个字符位置上能出现的内容,如果在字符串中有任意一个字符是字符组中的内容,那么就是匹配上的项. [0-9] [a-z] ...