C - A Plug for UNIX - poj 1087(最大流)
题目大意:这个题意有些蛋疼,看了很大会才明白什么意思,有N个插座,这些插座都是有类型的只能给这种类型的电器充电,下面接着给了M种电器,和电器的插头类型,还有K种转换器,可以把一种类型转换成另一种,转换器也是可以串联使用的。

*********************************************************************************************************************
#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std; const int MAXN = ;
const int oo = 1e9+; int G[MAXN][MAXN], layer[MAXN];
char s[MAXN][]; bool canLine(char s1[], char s2[])///判断转接口是否相同
{
if(strcmp(s1, s2) == )
return true;
return false;
}
bool bfs(int start, int End)
{
bool used[MAXN] = {};
queue<int> Q; Q.push(start);
memset(layer, -, sizeof(layer));
layer[start] = , used[start] = true; while(Q.size())
{
int u = Q.front();Q.pop(); if(u == End)return true; for(int i=; i<=End; i++)
{
if(G[u][i] && used[i] == false)
{
used[i] = true;
layer[i] = layer[u] + ;
Q.push(i);
}
}
} return false;
}
int dfs(int u, int MaxFlow, int End)
{
if(u == End)return MaxFlow; int uFlow = ; for(int i=; i<=End; i++)
{
if(G[u][i] && layer[i] == layer[u]+)
{
int flow = min(MaxFlow-uFlow, G[u][i]);
flow = dfs(i, flow, End); G[u][i] -= flow;
G[i][u] += flow; uFlow += flow; if(uFlow == MaxFlow)
break;
}
} return uFlow;
}
int dinic(int start, int End)
{
int MaxFlow = ; while( bfs(start, End) == true )
MaxFlow += dfs(start, oo, End); return MaxFlow;
} int main()
{
int N, M, K; while(scanf("%d", &N) != EOF)
{
int i, j; memset(G, , sizeof(G)); for(i=; i<=N; i++)///插头从1~N
scanf("%s", s[i]); scanf("%d", &M);
for(i=; i<=M; i++)///手机从N~N+M,忽略手机名字
scanf("%*s%s", s[i+N]); scanf("%d", &K);
///Ki是转换头进入的开始点,Kj是转换头出去的开始点,start是源点,End是汇点
int Ki = N+M, Kj = Ki+K, start = Kj+K+, End = start+;
for(i=; i<=K; i++)///转换器的进入从N+M~N+M+K,转换器的出从N+M+K~N+M+2*K
{///把入和出连接
scanf("%s%s", s[Ki+i], s[Kj+i]);
G[Ki+i][Kj+i] = oo;///转换器无限提供
} for(i=; i<=M; i++)
{///建立手机和转换器,插座的关系
for(j=; j<=N; j++)
{///匹配一下手机和插座是否直接可以相连
if( canLine(s[i+N], s[j]) == true)
G[i+N][j] = true;
}
for(j=; j<=K; j++)
{///匹配一下手机和转换器入是否可以相连
if( canLine(s[i+N], s[Ki+j]) == true)
G[i+N][Ki+j] = true;
}
} for(i=; i<=K; i++)
{///建立转换器与转换器或者插座的关系
for(j=; j<=K; j++)
{///匹配转换器出与转换器入,转换器无限提供,直接最大值
if(i!=j && canLine(s[Kj+i], s[Ki+j]) == true)
G[Kj+i][Ki+j] = oo;
}
for(j=; j<=N; j++)
{///匹配转换器出和插座的关系
if(canLine(s[Kj+i], s[j]) == true)
G[Kj+i][j] = true;
}
} for(i=; i<=M; i++)
{///源点与手机的关系
G[start][N+i] = true;
}
for(i=; i<=N; i++)
{///插座与汇点的关系
G[i][End] = true;
} printf("%d\n", M-dinic(start, End));
} return ;
}
C - A Plug for UNIX - poj 1087(最大流)的更多相关文章
- (网络流 模板)A Plug for UNIX -- poj -- 1087
链接: http://poj.org/problem?id=1087 http://acm.hust.edu.cn/vjudge/contest/view.action?cid=82835#probl ...
- C - A Plug for UNIX POJ - 1087 网络流
You are in charge of setting up the press room for the inaugural meeting of the United Nations Inter ...
- A Plug for UNIX POJ - 1087(模板题 没啥好说的。。就用了一个map)
题意: 几种插头,每一种都只有一个,但有无限个插头转换器,转换器(a,b) 意味着 可以把b转换为a,有几个设备,每个设备对应一种插头,求所不能匹配插头的设备数量 这个题可以用二分图做 , 我用的是最 ...
- POJ 1087 最大流裸题 + map
A Plug for UNIX Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 15597 Accepted: 5308 ...
- 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 ...
- poj1087 A Plug for UNIX(网络流最大流)
http://poj.org/problem?id=1087 好久没遇见过这么坑的题了这个题真是挫的够可以的.题目大意:你作为某高管去住宿了,然后宾馆里有几种插座,分别有其对应型号,你携带了几种用电器 ...
- 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 ...
- 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 ...
- 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 ...
随机推荐
- josn 转php
$data = josn_decode(data,[true]); 加true转化为php数组:不加为对象,使用:$data->'字段'.
- AC自动机学习笔记
AC自动机 ----多个模板的字符串匹配 字典树Trie加上失配边构成 插入操作:ac.insert(p[i],i);构造失配函数:ac.getFail();计算文本串T中每个模板串的匹配数:ac.f ...
- C#中的IO流操作(FileStream)
StreamReader和StreamWriter适用于对文本文件的操作,因为它是以字符为单位进行的操作 不用担心编码问题 using (Stream s = new FileStream(@&quo ...
- ASP.NET-FineUI开发实践-12
1.网上找到了行合并的示例,extjs写的,我把它挪过来改了下,FineUI也能用,就是只能放着看,选择和编辑行扩展列没有测试,放出来大家看着用吧. <script> F.ready(fu ...
- javaee后台适合用的编辑器插件
http://pan.baidu.com/s/1bn7D9sr 这个适合用在后台
- C#word(2007)操作类--新建文档、添加页眉页脚、设置格式、添加文本和超链接、添加图片、表格处理、文档格式转化
转:http://www.cnblogs.com/lantionzy/archive/2009/10/23/1588511.html 1.新建Word文档 #region 新建Word文档/// &l ...
- 【USACO 1.1.4】破碎的项链
[题目描述] 你有一条由N个红色的,白色的,或蓝色的珠子组成的项链(3<=N<=350),珠子是随意安排的.这里是 n=29 的二个例子: 1 2 ...
- 【转】POJ题目分类
初级:基本算法:枚举:1753 2965贪心:1328 2109 2586构造:3295模拟:1068 2632 1573 2993 2996 图:最短路径:1860 3259 1062 2253 1 ...
- 不同浏览器对parseInt方法解析的不同
parseInt方法的作用是将字符串转换为数字 当parseInt解析的时候只有0x和非0开头的数字,浏览器解析都一致,例如”0xA1”或 “9”. 只有当开头为0的时候才出现不同.IE,chrome ...
- Java学习----不变的常量
byte: -128~+127 short int:129 long float:1.5f (1.5被系统默认为double) double:4.5d char:'s' '1' boolean:t ...