首页 技术 正文
技术 2022年11月14日
0 收藏 513 点赞 3,283 浏览 2587 个字

给定一个平面图和一个源点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;
}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:8,944
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,469
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,283
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,099
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,729
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,766