题目链接:https://cn.vjudge.net/contest/68128#problem/C

没理解好题意真的麻烦,一上午就这么过去了。。。。。

具体思路:按照 源点 ->插座->转换器->插头->汇点的方式建图,源点到插座的流量为1,插头到汇点的流量为1,转换器之间如果能相连则赋值为inf.(转换器相连的条件,对于某一个转换器 他可以连下一个的头或者尾,但是这个转换器的方向不能变!!!坑点)

AC代码:

#include<iostream>
#include<string>
#include<cstring>
#include<cmath>
#include<set>
#include<queue>
#include<stdio.h>
#include<stack>
#include<vector>
#include<map>
#include<algorithm>
using namespace std;
# define inf 0x3f3f3f3f
# define maxn 500+10
# define ll long long
int n,m,k;
int dis[maxn][maxn];
char chazuo[maxn][maxn];
char change[maxn][maxn];
char chahead[maxn][maxn];
int vis[maxn],pre[maxn];
struct node
{
char fr[maxn];
char to[maxn];
} a[maxn]; bool bfs(int st,int ed)
{
queue<int>q;
memset(vis,0,sizeof(vis));
vis[st]=1;
pre[st]=st;
q.push(st);
while(!q.empty())
{
int top=q.front();
q.pop();
for(int i=1; i<=n+m+k+2; i++)
{
if(vis[i]==0&&dis[top][i]>0)
{
pre[i]=top;
vis[i]=1;
if(i==ed)return true;
q.push(i);
}
}
}
return false;
}
int EK(int st,int ed)
{
int ans=0;
while(bfs(st,ed))
{
int minn=inf;
for(int i=ed; i!=st; i=pre[i])
{
minn=min(minn,dis[pre[i]][i]);
}
for(int i=ed; i!=st; i=pre[i])
{
dis[pre[i]][i]-=minn;
dis[i][pre[i]]+=minn;
}
ans+=minn;
}
return ans;
}
int main()
{
while(~scanf("%d",&n))
{
memset(dis,0,sizeof(dis));
for(int i=1; i<=n; i++)
{
scanf("%s",chazuo[i]);
}
scanf("%d",&m);
for(int i=1; i<=m; i++)
{
scanf("%*s %s",chahead[i]);
}
scanf("%d",&k);
for(int i=1; i<=k; i++)
{
scanf("%s %s",a[i].fr,a[i].to);
}
for(int i=1; i<=n; i++) //zuo -> chahead
{
for(int j=1; j<=m; j++)
{
if(strcmp(chazuo[i],chahead[j])==0)
{
dis[i][n+k+j]=1;
}
}
}
for(int i=1; i<=n; i++) //zuo -> change
{
for(int j=1; j<=k; j++)
{
if(strcmp(chazuo[i],a[j].fr)==0||strcmp(chazuo[i],a[j].to)==0)
{
dis[i][n+j]=1;
}
}
}
for(int i=1; i<=k; i++) //change-> head
{
for(int j=1; j<=m; j++)
{
if(strcmp(a[i].to,chahead[j])==0||strcmp(a[i].fr,chahead[j])==0)
{
dis[n+i][n+k+j]=1;
}
}
}
for(int i=1; i<=k; i++) // change -> change
{
for(int j=1; j<=k; j++)
{
if(strcmp(a[i].fr,a[j].to)==0)
{
dis[i+n][j+n]=inf;
}
}
}
int st=n+m+k+1;
int ed=st+1;
for(int i=1; i<=n; i++)
{
dis[st][i]=1;
}
for(int i=1; i<=m; i++)
{
dis[n+k+i][ed]=1;
}
int ans=EK(st,ed);
printf("%d\n",m-ans);
}
return 0;
}

C - A Plug for UNIX (又是建图坑)的更多相关文章

  1. poj 1087 A Plug for UNIX(字符串编号建图)

    A Plug for UNIX Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 14862   Accepted: 5026 ...

  2. POJ A Plug for UNIX (最大流 建图)

    Description You are in charge of setting up the press room for the inaugural meeting of the United N ...

  3. A Plug for UNIX 分类: POJ 图论 函数 2015-08-10 14:18 2人阅读 评论(0) 收藏

    A Plug for UNIX Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 14786 Accepted: 4994 Desc ...

  4. POJ1087 A Plug for UNIX(网络流)

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

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

  6. TZOJ 1911 A Plug for UNIX(最大流)

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

  7. POJ1087 A Plug for UNIX 2017-02-12 13:38 40人阅读 评论(0) 收藏

    A Plug for UNIX Description You are in charge of setting up the press room for the inaugural meeting ...

  8. POJ1087:A Plug for UNIX(最大流)

    A Plug for UNIX 题目链接:https://vjudge.net/problem/POJ-1087 Description: You are in charge of setting u ...

  9. POJ1087 A Plug for UNIX —— 最大流

    题目链接:https://vjudge.net/problem/POJ-1087 A Plug for UNIX Time Limit: 1000MS   Memory Limit: 65536K T ...

随机推荐

  1. isset与empty 的区别

    isset()与empty()函数的区别,isset()只需要验证一个值是否存在: 而empty()不但需验证这个值是否存在,还需检验它的值是否非空和非0: 注:isset()只检验一个变量是否已经设 ...

  2. vue 组件 单选切换控制模板 v-bind-is

    <!DOCTYPE html><html> <head> <meta charset="UTF-8"> <title>T ...

  3. css中对position的几种定位方式的最佳诠释

    关于元素的position定位的理解,牛客网的hardy给出了一个比较好的理解: 在html中网页可以看成一个立体的空间,一个完整的页面是由很多个页面堆积形成的,如上图所示   CSS中Positio ...

  4. ASP.NET Core 2 学习笔记

    之前的ASP.NET网站,只要把*.html.*.css.*.jpg.*.png.*.js等静态文件放在项目根目录,默认都可以直接被浏览:但ASP.NET Core 小改了浏览静态文件的方式,默认根目 ...

  5. CentOS 7 上安装(LAMP)服务 Linux,Apache,MySQL,PHP

    介绍 LAMP 是现在非常流行的 WEB 环境, 是 Linux,Apache,MySQL,PHP 的缩写.数据存储在 MySQL 中,动态内容由 PHP 处理. 在本指南中,我们将演示如何在 Cen ...

  6. 【大数据】关于Kafka的进一步理解

    前置: 文件host 192.168.11.13 192.168.11.14 192.168.11.30 脚本init_kafka.sh #!/bin/bash source /etc/profile ...

  7. 超计算(Hyper computation)模型

    超计算(Hyper computation)模型 作者:Xyan Xcllet链接:https://www.zhihu.com/question/21579465/answer/106995708来源 ...

  8. 查看Mysql正在执行的事务、锁、等待

    一.关于锁的三张表(MEMORY引擎) ## 当前运行的所有事务 mysql> select * from information_schema.innodb_trx\G; ********** ...

  9. 菜鸡的考场emacs配置

    (setq default-tab-width 4) (setq c-default-style "awk") (setq default-cursor-type 'bar) (e ...

  10. 2018.10.20 2018-2019 ICPC,NEERC,Southern Subregional Contest(Online Mirror, ACM-ICPC Rules)

    i207M的“怕不是一个小时就要弃疗的flag”并没有生效,这次居然写到了最后,好评=.= 然而可能是退役前和i207M的最后一场比赛了TAT 不过打得真的好爽啊QAQ 最终结果: 看见那几个罚时没, ...