S-T平面图

给定一个平面图和一个源点S、汇点T都在图中无边界的区域上,这样的图叫S-T平面图

我们把图中每一个独立的面看做一个点,对于每条边e,将它两侧的面连一条边,其中靠近S的一段与S相连,与T相连的一段与T相连

于是这个平面图的最小割就是新图的S-T最短路

1001: [BeiJing2006]狼抓兔子

Time Limit: 15 Sec   Memory Limit: 162 MB
Submit: 24311   Solved: 6138
[ Submit][ Status][ Discuss]

Description

现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的,
而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个网格的地形:

 

左上角点为(1,1),右下角点为(N,M)(上图中N=4,M=5).有以下三种类型的道路 
1:(x,y)<==>(x+1,y) 
2:(x,y)<==>(x,y+1) 
3:(x,y)<==>(x+1,y+1) 
道路上的权值表示这条路上最多能够通过的兔子数,道路是无向的. 左上角和右下角为兔子的两个窝,
开始时所有的兔子都聚集在左上角(1,1)的窝里,现在它们要跑到右下解(N,M)的窝中去,狼王开始伏击
这些兔子.当然为了保险起见,如果一条道路上最多通过的兔子数为K,狼王需要安排同样数量的K只狼,
才能完全封锁这条道路,你需要帮助狼王安排一个伏击方案,使得在将兔子一网打尽的前提下,参与的
狼的数量要最小。因为狼还要去找喜羊羊麻烦.

Input

第一行为N,M.表示网格的大小,N,M均小于等于1000.
接下来分三部分
第一部分共N行,每行M-1个数,表示横向道路的权值. 
第二部分共N-1行,每行M个数,表示纵向道路的权值. 
第三部分共N-1行,每行M-1个数,表示斜向道路的权值. 
输入文件保证不超过10M

Output

输出一个整数,表示参与伏击的狼的最小数量.

Sample Input

3 4
5 6 4
4 3 1
7 5 3
5 6 7 8
8 7 6 5
5 5 5
6 6 6

Sample Output

14


可以拿这道题练练手

#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<algorithm>
#define LL long long int
using namespace std;
const int maxn=5000005,maxm=6000005,INF=2000000000,P=1000000007;

inline int read(){
	int out=0,flag=1;char c=getchar();
	while(c<48||c>57) {if(c=='-') flag=-1;c=getchar();}
	while(c>=48&&c<=57){out=out*10+c-48;c=getchar();}
	return out*flag;
}

int N,M,n;

int head[maxn],nedge=0;
struct EDGE{
	int to,w,next;
}edge[maxm];

inline void build(int a,int b,int w){
	edge[nedge]=(EDGE){b,w,head[a]};
	head[a]=nedge++;
	edge[nedge]=(EDGE){a,w,head[b]};
	head[b]=nedge++;
}

void special(){
	int t=(N==1 ? M:N),Min=INF;
	for(int i=1;i<t;i++) Min=min(Min,read());
	printf("%d\n",Min);
	exit(0);
}

void init(){
	fill(head,head+maxn,-1);
	N=read();
	M=read();
	if(N==1||M==1) special();
	n=(N-1)*(M-1)*3+N+M-N*M;
	for(int i=1;i<=N;i++){
		for(int j=1;j<M;j++){
			if(i==1) build(2*(j-1)+1,n,read());
			else if(i==N) build(2*(i-2)*(M-1)+2*(j-1)+2,0,read());
			else build(2*(i-2)*(M-1)+2*(j-1)+2,2*(i-1)*(M-1)+2*(j-1)+1,read());
		}
	}
	for(int i=1;i<N;i++){
		for(int j=1;j<=M;j++){
			if(j==1) build(2*(i-1)*(M-1)+2,0,read());
			else if(j==M) build(2*i*(M-1)-1,n,read());
			else build(2*(i-1)*(M-1)+2*(j-1)-1,2*(i-1)*(M-1)+2*(j-1)+2,read());
		}
	}
	for(int i=1;i<N;i++)
		for(int j=1;j<M;j++){
			build(2*(i-1)*(M-1)+2*(j-1)+1,2*(i-1)*(M-1)+2*(j-1)+2,read());
		}
}

struct node{
	int u,v;
};

inline bool operator <(const node& a,const node& b){
	return a.v>b.v;
}

int d[maxn];
bool vis[maxn];

void dijkstra(){
	fill(d,d+maxn,INF);
	priority_queue<node> q;
	q.push((node){0,0});
	d[0]=0;
	node u;
	int to;
	while(!q.empty()){
		u=q.top();
		q.pop();
		if(vis[u.u]) continue;
		vis[u.u]=true;
		for(int k=head[u.u];k!=-1;k=edge[k].next){
			if(!vis[to=edge[k].to]&&d[to]>d[u.u]+edge[k].w){
				d[to]=d[u.u]+edge[k].w;
				q.push((node){to,d[to]});
			}
		}
	}
}

void print(){
	printf("%d\n",d[n]);
}

int main(){
	init();
	dijkstra();
	print();
	return 0;
}



转载于:https://www.cnblogs.com/Mychael/p/8282873.html

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值