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
Input
Output
输出一个整数,表示参与伏击的狼的最小数量.
Sample Input
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
可以拿这道题练练手
- #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;
- }
S-T平面图的更多相关文章
- [BZOJ1997][HNOI2010] 平面图判定
Description Input Output 是的..BZOJ样例都没给. 题解(from 出题人): 如果只考虑简单的平面图判定,这个问题是非常不好做的. 但是题目中有一个条件— ...
- 【BZOJ 3051】【UOJ #57】【WC 2013】平面图
http://www.lydsy.com/JudgeOnline/problem.php?id=3051 http://uoj.ac/problem/57 这道题需要平面图转对偶图,点定位,最小生成树 ...
- bzoj3051: [wc2013]平面图
Description Input Output 扫描线求出平面图的对偶图然后求最小生成树,用并查集按秩合并,以便查询两点间路径最大权 #include<stdio.h> #include ...
- 【BZOJ-2007】海拔 最小割 (平面图转对偶图 + 最短路)
2007: [Noi2010]海拔 Time Limit: 20 Sec Memory Limit: 552 MBSubmit: 2095 Solved: 1002[Submit][Status] ...
- 【BZOJ-4423】Bytehattan 并查集 + 平面图转对偶图
4423: [AMPPZ2013]Bytehattan Time Limit: 3 Sec Memory Limit: 128 MBSubmit: 144 Solved: 103[Submit][ ...
- HDU3870 Catch the Theves(平面图最小割转最短路)
题目大概说给一个n×n的方格,边有权值,问从求(1,1)到(n,n)的最小割. 点达到了160000个,直接最大流不好.这题的图是平面图,求最小割可以转化成求其对偶图的最短路,来更高效地求解: 首先源 ...
- BZOJ 1001 [BeiJing2006] 狼抓兔子(平面图最大流)
题目大意 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的.而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个网格的地形: ...
- BZOJ-1001 狼抓兔子 (最小割-最大流)平面图转对偶图+SPFA
1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MB Submit: 14686 Solved: 3513 [Submit][ ...
- BZOJ 2007 海拔(平面图最小割-最短路)
题目链接:http://61.187.179.132/JudgeOnline/problem.php?id=2007 题意:给出一个n*n的格子,那么顶点显然有(n+1)*(n+1)个.每两个相邻顶点 ...
- LA 3263 (平面图的欧拉定理) That Nice Euler Circuit
题意: 平面上有n个端点的一笔画,最后一个端点与第一个端点重合,即所给图案是闭合曲线.求这些线段将平面分成多少部分. 分析: 平面图中欧拉定理:设平面的顶点数.边数和面数分别为V.E和F.则 V+F- ...
随机推荐
- 对posintion属性的简单认识,对于还在纠结的同学们,有一定的帮助
position的四个属性值: relative ,absolute ,fixed,static 下面分别讲述这四个属性,以简单代码表示 <div id="parent" ...
- JS 中屏幕、浏览器和文档的高度、宽度和距离
1.各种对象 window.screen - 屏幕,window - 窗口,document.documentElement & document.body.parentNode - 文档,d ...
- youtube高清视频下载方法
youtube下载方法有多种, 但都不支持1080P以上的高清下载, 今天找到一种支持1080P的, 记录一下 步骤1: 百度搜: Dooseen tubedown 下载该软件, 并安装, 一直下一步 ...
- xampp服务器搭建和使用
1.安装完XAMPP后会出现Apache端口被占用的问题,一下方法解决 错误信息如下: Error: Apache shutdown unexpectedly. 9:37:01 [Apache] T ...
- JAVA基础学习之路(九)[2]String类常用方法
字符与字符串: 1.将字符数组变为字符串(构造方法) public String(char[] value) Allocates a new String so that it represents ...
- JavaScript学习笔记(五)——类型、转换、相等、字符串
第六章 类型 相等 转换等 一.类型 1 typeof(); typeof是一个内置的JavaScript运算符,可用于探测其操作数的类型. 例: <script language=" ...
- libCurl 初步认识 - cur easy
cur easy接口简洁明了,主接口4个,辅接口5个. 主接口 初始化 + 配参数 + 执行 + 销毁 初始化 CURL* curl_easy_init() 获得CURL句柄,返回值需要判空. 配参数 ...
- [咸恩静][Coffee House]
歌词来源:http://music.163.com/#/song?id=5400159 하루의 시작은 향긋한 커피 [ha-lu-e xi-ja-geun hyang-geu-Tan Keo-Pi] ...
- We are writing to let you know we have removed your selling privileges
Hello, We are writing to let you know we have removed your selling privileges, canceled your listin ...
- ASP.NET Web API - 使用 Castle Windsor 依赖注入
示例代码 项目启动时,创建依赖注入容器 定义一静态容器 IWindsorContainer private static IWindsorContainer _container; 在 Applica ...