#include<iostream>
#include<stdio.h>
#include<string>
#define MAXN 105
using namespace std;
struct unix
{
string s1;
string s2;
};
bool ck[MAXN];
int _m[MAXN][MAXN];
int match[MAXN];
string rec[MAXN];
unix dev[MAXN];
unix adap[MAXN];
bool mark_adap[MAXN];
int hungary(int a,int b);
int a;
int b;
int c; void For_adap(int i);
void make_map();
int main()
{
//freopen("acm.acm","r",stdin);
int i;
int j;
int u;
int v;
int edge;
cin>>a;
for(i = ; i < a; ++ i)
{
cin>>rec[i];
}
cin>>b;
for(i = ; i < b; ++ i)
{
cin>>dev[i].s1;
cin>>dev[i].s2;
}
cin>>c;
for(i = ; i < c; ++ i)
{
cin>>adap[i].s1;
cin>>adap[i].s2;
}
memset(_m,,sizeof(_m));
make_map();
//for(i = 0; i < b; ++ i)
//{
// for(j = 0; j < a; ++ j)
//. {
//\ if(_m[i][j] == 1)
// cout<<dev[i].s1<<"---->"<<rec[j]<<endl;
// }
//}
cout<<b-hungary(b,a)<<endl;
} void make_map()
{
int i;
int j;
for(i = ; i < b; ++ i)
{
memset(mark_adap,false,sizeof(mark_adap));
for(j = ; j < a; ++ j)
{
if(dev[i].s2 == rec[j])
_m[i][j] = ;
}
For_adap(i);
}
} void For_adap(int i)
{
int j;
int k;
string tem;
for(j = ; j < c; ++ j)
{
if(dev[i].s2 == adap[j].s1 && !mark_adap[j])
{
mark_adap[j] = true;
for(k = ; k < a; ++ k)
{
if(rec[k] == adap[j].s2)
{
_m[i][k] = ;
}
}
tem = dev[i].s2;
dev[i].s2 = adap[j].s2;
For_adap(i);
dev[i].s2 = tem;
}
}
} ///////////////////////////////////////////////////
//hungary—by myself
///////////////////////////////////////////////////
bool search(int a,int b,int x)
{
int i;
int t;
for ( i = ; i < b ; i++)
if (_m[x][i] && ! ck[i])
{
ck[i] = true;
t = match[i];
match[i] = x;
if (t == - || search(a,b,t))
return true;
match[i] = t;
}
return false;
} int hungary(int a,int b)
{
memset(match,-,sizeof(match));
int max_match = ;
int i;
for ( i = ; i < a ; i++)
{
memset(ck,false,sizeof(ck));
if (search(a,b,i)) max_match++;
}
return max_match;
}

关注我的公众号,当然,如果你对Java, Scala, Python等技术经验,以及编程日记,感兴趣的话。

技术网站地址: vmfor.com

POJ 1087的更多相关文章

  1. POJ 1087 A Plug for UNIX / HDU 1526 A Plug for UNIX / ZOJ 1157 A Plug for UNIX / UVA 753 A Plug for UNIX / UVAlive 5418 A Plug for UNIX / SCU 1671 A Plug for UNIX (网络流)

    POJ 1087 A Plug for UNIX / HDU 1526 A Plug for UNIX / ZOJ 1157 A Plug for UNIX / UVA 753 A Plug for ...

  2. poj 1087 A Plug for UNIX 【最大流】

    题目连接:http://poj.org/problem? id=1087 题意: n种插座 ,m个电器,f组(x,y)表示插座x能够替换插座y,问你最多能给几个电器充电. 解法:起点向插座建边,容量1 ...

  3. (网络流 模板)A Plug for UNIX -- poj -- 1087

    链接: http://poj.org/problem?id=1087 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82835#probl ...

  4. kuangbin专题专题十一 网络流 POJ 1087 A Plug for UNIX

    题目链接:https://vjudge.net/problem/POJ-1087 题目:有n个插座,插座上只有一个插孔,有m个用电器,每个用电器都有插头,它们的插头可以一样, 有k个插孔转化器, a ...

  5. poj 1087 最大流

    没啥好说的,慢慢建图 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 Out ...

  6. poj 1087 A Plug for UNIX

    题目描述:现在由你负责布置Internet联合组织首席执行官就职新闻发布会的会议室.由于会议室修建时被设计成容纳全世界各地的新闻记者,因此会议室提供了多种电源插座用以满足(会议室修建时期)各国不同插头 ...

  7. 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 ...

  8. poj 1087.A Plug for UNIX (最大流)

    网络流,关键在建图 建图思路在代码里 /* 最大流SAP 邻接表 思路:基本源于FF方法,给每个顶点设定层次标号,和允许弧. 优化: 1.当前弧优化(重要). 1.每找到以条增广路回退到断点(常数优化 ...

  9. C - A Plug for UNIX - poj 1087(最大流)

    题目大意:这个题意有些蛋疼,看了很大会才明白什么意思,有N个插座,这些插座都是有类型的只能给这种类型的电器充电,下面接着给了M种电器,和电器的插头类型,还有K种转换器,可以把一种类型转换成另一种,转换 ...

  10. POJ 1087 A Plug for UNIX (网络流,最大流)

    题面 You are in charge of setting up the press room for the inaugural meeting of the United Nations In ...

随机推荐

  1. 521. Longest Uncommon Subsequence I

    static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); class Solution { publ ...

  2. test 测试spring容器类

  3. python操作数据库-安装

    首先是下载软件: 链接:http://pan.baidu.com/s/1nvp1imX 密码:6i0x 之后就是一系列设置. 安装教程:自行百度就行.需要注意的是设置my.ini时,需要加上这些东西( ...

  4. wordpaster更新说明

    官方网站:http://www.ncmem.com/ 产品首页:http://www.ncmem.com/webapp/wordpaster/index.aspx 在线演示:FCKEditor2x示例 ...

  5. 下拉菜单  - - css

    <!DOCTYPE html> <html> <head> <meta charset="utf-8" /> <title&g ...

  6. jQueryUI datepicker 报错: TypeError: inst is undefined

    前提:要引用的js等都引用好了 调用日期控件的input: <input id="starttime" name="starttime" class=&q ...

  7. Hdu1978 How many ways 2017-01-18 14:32 40人阅读 评论(0) 收藏

    How many ways Time Limit : 3000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total ...

  8. bootstrap 问题

    less; sass: css预处理:可以直接使用.css,也可以修改.less,生成定制化的css CDN: 服务,使用这个效果会更好.theme一般不引入,jquery一般在js之前引入. 使用b ...

  9. PHP Functions - arsort()

    <?php $characters = array('a','b','c','d','e','f'); arsort($characters); print_r($characters); /* ...

  10. [Delphi]带进度条的ListView

    带进度条的ListView unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, C ...