博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
POJ 1087 A Plug for UNIX (最大流)
阅读量:5343 次
发布时间:2019-06-15

本文共 4687 字,大约阅读时间需要 15 分钟。

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

Description

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.

Input

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.

Output

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

Sample Input

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

Sample Output

1 分析 建图是比较好想的,源点和插头相连,插头和电器相连,电器和汇点相连,跑最大流就行了。 只是要注意一个地方:后面可能会出现前面没有出现的插座,需要加进去,这样就行了。 对于这种字符串的,还是map比较好用。
#include
#include
#include
#include
#include
#include
using namespace std;//****************************************************//最大流模板Edmonds_Karp算法//初始化:G[][],st,ed//******************************************************const int MAXN = 500;const int INF = 0x3fffffff;int G[MAXN][MAXN];//存边的容量,没有边的初始化为0int path[MAXN],flow[MAXN],st,ed;int n;//点的个数,编号0~n,n包括了源点和汇点queue
q;int bfs(){ int i,t; while(!q.empty()) q.pop();//清空队列 memset(path,-1,sizeof(path));//每次搜索前都把路径初始化成-1 path[st]=0; flow[st]=INF;//源点可以有无穷的流流进 q.push(st); while(!q.empty()){ t=q.front(); q.pop(); if(t==ed) break; for(i=0;i<=n;i++){ if(i!=st&&path[i]==-1&&G[t][i]){ flow[i]=flow[t]
mp;int main(){ int N,M,K; st=0,ed=1; int tol=2; memset(G,0,sizeof(G)); scanf("%d",&N); while(N--){ string s; cin>>s; mp[s]=tol; G[st][tol]=1; tol++; } scanf("%d",&M); for(int i=1;i<=M;i++){ string name,s; cin>>name>>s; if(mp[name]==0) mp[name]=tol++; if(mp[s]==0) mp[s]=tol++; G[mp[name]][ed]=1; G[mp[s]][mp[name]]=1; } scanf("%d",&K); while(K--){ string s1,s2; cin>>s1>>s2; if(mp[s1]==0) mp[s1]=tol++; if(mp[s2]==0) mp[s2]=tol++; G[mp[s2]][mp[s1]]=INF; } n=tol-1; printf("%d\n",M-Edmonds_Karp()); return 0;}

 

 

转载于:https://www.cnblogs.com/wangdongkai/p/5618868.html

你可能感兴趣的文章
HDU 1016 Prime Ring Problem(dfs)
查看>>
C#中结构体与字节流互相转换
查看>>
session和xsrf
查看>>
跟随大神实现简单的Vue框架
查看>>
Linux目录结构
查看>>
LeetCode-Strobogrammatic Number
查看>>
luoguP3414 SAC#1 - 组合数
查看>>
五一 DAY 4
查看>>
(转)接口测试用例设计(详细干货)
查看>>
【译】SSH隧道:本地和远程端口转发
查看>>
win8.1安装Python提示缺失api-ms-win-crt-runtime-l1-1-0.dll问题
查看>>
图片点击轮播(三)-----2017-04-05
查看>>
直播技术细节3
查看>>
《分布式服务架构:原理、设计于实战》总结
查看>>
java中new一个对象和对象=null有什么区别
查看>>
字母和数字键的键码值(keyCode)
查看>>
IE8调用window.open导出EXCEL文件题目
查看>>
Spring mvc初学
查看>>
有意思的代码片段
查看>>
C8051开发环境
查看>>