Poj 1087 A Plug For UNIX

2Y
1WA于以为插销只是一个字符
2Y 0ms
Zoo 的隐藏boss读的题
自己建的模,还不错
虚拟总源点,总汇点
然后离散化所有的插座代号
有的插座作为汇点
有的电器作为源点
转换器的边流量为INF
以上
#include<stdio.h>
#include<queue>
#include<vector>
#include<algorithm>
#include<string.h>
using namespace std;
#define N 510
#define INF (int)1e9
int G[N][N];
#define FOR(i,a,b) for(i=a;i<=b;i++)
int ft[N];
bool visit[N];
int p,q,r,n;
bool EK(int src,int des){
	queue<int>Q;while(!Q.empty())Q.pop();
	int i;
	FOR(i,0,n+1)visit[i]=0;
	Q.push(src);visit[src]=0;
	while(!Q.empty()){
		int tp=Q.front();Q.pop();
		FOR(i,0,n+1){
			if(!visit[i]&&G[tp][i]){
				ft[i]=tp;
				Q.push(i);
				visit[i]=1;
				if(i==des)return 1;
				}
			}
		}
	return 0;
	}
int FF(int src,int des){
	int res=0;
	while(1){
		if(!EK(src,des))break;
		int run=INF,tp=des;
		while(tp!=src){
			run=min(run,G[ft[tp]][tp]);
			tp=ft[tp];
			}
		tp=des;
		while(tp!=src){
			G[ft[tp]][tp]-=run;
			G[tp][ft[tp]]+=run;
			tp=ft[tp];
			}
		res+=run;
		}
	return res;
	}
struct pak{
	char s[99];
	bool operator <  (const pak &tp)const{return strcmp(s,tp.s)<0;}
	bool operator == (const pak &tp)const{return strcmp(s,tp.s)==0;}
	}tp;
vector<pak>X,Y,Z1,Z2,L;
vector<pak>::iterator iter;
int main(){
	while(scanf("%d",&p)!=EOF){
		int i,j,k,x,y,w;
		X.clear();Y.clear();Z1.clear();Z2.clear();L.clear();
		FOR(i,1,p){
			scanf("%s",tp.s);
			X.push_back(tp);
			L.push_back(tp);
			}
		scanf("%d",&q);
		FOR(i,1,q){
			scanf("%s",tp.s);
			scanf("%s",tp.s);
			Y.push_back(tp);
			L.push_back(tp);
			}
		scanf("%d",&r);
		FOR(i,1,r){
			scanf("%s",tp.s);
			Z1.push_back(tp);L.push_back(tp);
			scanf("%s",tp.s);
			Z2.push_back(tp);L.push_back(tp);
			}
		sort(L.begin(),L.end());
		L.erase(unique(L.begin(),L.end()),L.end());
		n=L.size();
		FOR(i,0,n+1)FOR(j,0,n+1)G[i][j]=0;
		FOR(i,0,X.size()-1){
			iter=lower_bound(L.begin(),L.end(),X[i]);
			x=iter-L.begin()+1;
			G[x][n+1]+=1;
			}
		FOR(i,0,Y.size()-1){
			iter=lower_bound(L.begin(),L.end(),Y[i]);
			y=iter-L.begin()+1;
			G[0][y]+=1;
			}
		FOR(i,0,Z1.size()-1){
			iter=lower_bound(L.begin(),L.end(),Z1[i]);
			x=iter-L.begin()+1;
			iter=lower_bound(L.begin(),L.end(),Z2[i]);
			y=iter-L.begin()+1;
			G[x][y]=INF;
			}
		printf("%d\n",q-FF(0,n+1));
		}
	return 0;
	}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值