BZOJ 1001--[BeiJing2006]狼抓兔子(最短路&对偶图)
1001: [BeiJing2006]狼抓兔子
Time Limit: 15 Sec Memory Limit: 162 MB
Submit: 29035 Solved: 7604
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
题目链接:
http://www.lydsy.com/JudgeOnline/problem.php?id=1001
Solution
首先应该会想到网络流。。。然后就做完了
实际上这个做法并不是很优。。。
通过平面图的知识我们可以在图的最左上和最右下建出两个新节点S和T。。。
然后将每个方格看作一个节点,两个节点的公共边作为它们之间的边权。。。
然后跑最短路即可。。效率O(n*m*log(n*m))
代码
#include<iostream>
#include<cstdio>
#include<cstring>
#include<queue>
#include<vector>
#define inf 0x3f3f3f3f
#define LL long long
using namespace std;
int n,m,N,hang;
int cnt;
struct edge{
int r,next;
LL w;
}e[6000010];
int head[2000010];
LL h[2000010];
bool c[2000010];
priority_queue<pair<LL,int>,vector<pair<LL,int> >,greater<pair<LL,int> > >q;
void insert(int u,int v,LL w){
cnt++;
//cout<<cnt<<endl;
e[cnt].r=v;
e[cnt].next=head[u];
e[cnt].w=w;
head[u]=cnt;
}
void dijkstra(){
memset(h,inf,sizeof(h));
q.push(make_pair(0,0));
h[0]=0;
while(!q.empty()){
int now=q.top().second;
LL s=q.top().first;
q.pop();
//cout<<now<<" "<<s<<" "<<head[now]<<endl;
if(c[now]==1) continue; if(now==N+1){
printf("%lld\n",h[N+1]);return;
} c[now]=1;
for(int i=head[now];i>0;i=e[i].next){
int H=s+e[i].w;
if(H<h[e[i].r]){
h[e[i].r]=H;
q.push(make_pair(H,e[i].r));
}
}
//cout<<1<<endl;
}
}
int main(){
int l,r;
LL ans=inf,x;
cnt=0;
scanf("%d%d",&n,&m);
if(n==1||m==1){
if(n>m) swap(n,m);
for(int i=1;i<m;i++){
scanf("%lld",&x);
if(x<ans) ans=x;
}
printf("%lld\n",ans);
return 0;
}
hang=(m-1)<<1;
N=hang*(n-1);
for(int i=1;i<=n;i++)
for(int j=1;j<m;j++){
scanf("%lld",&x);
if(i==1) insert(0,j<<1,x);
else if(i==n) insert(hang*(n-2)+j*2-1,N+1,x);
else{
l=hang*(i-2)+j*2-1;
r=hang*(i-1)+j*2;
insert(l,r,x);
insert(r,l,x);
}
}
for(int i=1;i<n;i++)
for(int j=1;j<=m;j++){
scanf("%lld",&x);
if(j==1)insert(hang*(i-1)+1,N+1,x);
else if(j==m)insert(0,hang*i,x);
else{
l=hang*(i-1)+(j-1)*2;
r=l+1;
insert(l,r,x);
insert(r,l,x);
}
}
for(int i=1;i<n;i++)
for(int j=1;j<m;j++){
scanf("%lld",&x);
l=hang*(i-1)+j*2;
r=l-1;
insert(l,r,x);
insert(r,l,x);
}
//for(int i=0;i<=N+1;i++) cout<<head[i]<<endl;
dijkstra();
return 0;
}
This passage is made by Iscream-2001.
BZOJ 1001--[BeiJing2006]狼抓兔子(最短路&对偶图)的更多相关文章
- BZOJ 1001: [BeiJing2006]狼抓兔子(最短路)
平面图的最小割转化为对偶图的最短路(资料:两极相通——浅析最大最小定理在信息学竞赛中的应用) ,然后DIJKSTRA就OK了. ------------------------------------ ...
- [bzoj 1001][Beijing2006]狼抓兔子 (最小割+对偶图+最短路)
Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的, 而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一 ...
- BZOJ 1001 [BeiJing2006] 狼抓兔子(平面图最大流)
题目大意 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的.而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个网格的地形: ...
- BZOJ 1001: [BeiJing2006]狼抓兔子
1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 20029 Solved: 4957[Submit][ ...
- BZOJ 1001 [BeiJing2006]狼抓兔子 (UVA 1376 Animal Run)
1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 24727 Solved: 6276[Submit][ ...
- BZOJ 1001: [BeiJing2006]狼抓兔子【最大流/SPFA+最小割,多解】
1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 23822 Solved: 6012[Submit][ ...
- BZOJ 1001: [BeiJing2006]狼抓兔子 最小割
题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1001 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓 ...
- 【刷题】BZOJ 1001 [BeiJing2006]狼抓兔子
Description 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的,而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个 ...
- BZOJ 1001: [BeiJing2006]狼抓兔子(s-t平面图+最短路求最小割)
http://www.lydsy.com/JudgeOnline/problem.php?id=1001 题意: 思路:这道题目是最小割题目,但是吧你直接套用Dinic是会超时的. 这里有种很奇妙的做 ...
- bzoj 1001 [BeiJing2006]狼抓兔子——最小割转最短路
题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1001 #include<cstdio> #include<cstring& ...
随机推荐
- 如何区分USB 2.0 和USB 3.0插口
USB3.0的速度是USB2.0的十倍,并且比USB2.0更加节能,同时,还能向下兼容USB2.0.那么,我们怎么区分USB2.0 和 USB 3.0呢. 电脑(有USB2.0和USB3.0的插口) ...
- Golang之(if)流程控制
(if)我能坚持做好一只地鼠,慢慢的刨坑,讲洞挖的深一点…… package main import ( "fmt" ) func testIf1() { num := //var ...
- chrome 调试工具的使用
Elements chrome devtools 中 Elements panel 是审查 dom 元素和 css 的, 可以实时修改 dom/css. windows: ctrl + shift + ...
- JVM家族史考【转】
说起Java虚拟机,许多Java程序员都会潜意识地把它与Sun(虽然太阳已然西落,但永远值得被记忆) HotSpot虚拟机等同看待,也许还有一些程序员会注意到BEA JRockit和IBM J9,但大 ...
- 客户被绑,蒙眼,惊问:“想干什么?” 对方不语,鞭笞之,客户求饶:“别打,要钱?” 又一鞭,“十万够不?” 又一鞭,“一百万?” 又一鞭。客户崩溃:“你们TMD到底要啥?” “要什么?...
1. 客户被绑,蒙眼,惊问:“想干什么?” 对方不语,鞭笞之,客户求饶:“别打,要钱?” 又一鞭,“十万够不?” 又一鞭,“一百万?” 又一鞭.客户崩溃:“你们TMD ...
- 2018.09.25 poj3070 Fibonacci(矩阵快速幂)
传送门 矩阵快速幂板题,写一道来练练手. 这一次在poj做题总算没忘了改万能库. 代码: #include<iostream> #include<cstdio> #define ...
- foreach循环赋值问题
foreach ($list as $key=>$val){ $data=array();//这一个一定要加上不然循环后,modify_one,modify_two都会赋值 if ($val[' ...
- java判断字符串是否为数字,包括负数
/** * 判断是否为数字,包含负数情况 * @param str * @return */ private boolean isNumeric(String str){ Boolean flag = ...
- IDEA如何初始化Git本地仓库,并提交到远程仓库
本文转载自:http://blog.csdn.net/two_people/article/details/77008593 1. 首先在远程仓库上新建一个项目,码云和github都可以,我这里使用的 ...
- nexus 下载及安装
一.下载 nexus maven http://www.sonatype.org/ http://www.sonatype.org/nexus/ http://www.sonatype.org/nex ...