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& ...
随机推荐
- 有关gitlab的神秘操作.....version&&domain设置...
在使用gitlab的时候,如果服务器IP变动,之前的domain写入了配置文件了,如下路径: [root@gitlab-server ~]# vim /var/opt/gitlab/gitlab-ra ...
- Linux objdump命令
一.简介 objdump命令是用查看目标文件或者可执行的目标文件的构成的gcc工具. 二.选项 http://my.oschina.net/alphajay/blog/7729 http://man. ...
- Codeforces 612B. Wet Shark and Bishops 模拟
B. Wet Shark and Bishops time limit per test: 2 seconds memory limit per test: 256 megabytes input: ...
- tmux配置与用法整理
tmux常用命令与快捷键 http://www.111cn.net/sys/linux/59058.htm http://www.360doc.com/content/13/0709/13/13047 ...
- 2018.07.07 洛谷 P3939 数颜色(主席树)
P3939 数颜色 题目背景 大样例下发链接:http://pan.baidu.com/s/1c0LbQ2 密码:jigg 题目描述 小 C 的兔子不是雪白的,而是五彩缤纷的.每只兔子都有一种颜色,不 ...
- where /group by/ having/ order by/
1.order by 是 按字段 进行排序.. 字段后面可跟 desc 降序..asc 升序..默认为升序2.group by 是进行分组 查询3.having 和 where 都属于 条件过滤 区别 ...
- xib中快捷键
Alt + 点击视图,实现快速复制 点击视图, + Alt 将鼠标放在另一个视图上,可以显示两视图x 和y方向的距离, 按方向键上下,调节两视图的距离 Command + Shift + G 前往 ...
- 对C++里面 的知识积累:
unique()[去重函数] unique()是C++标准库函数里面的函数,其功能是去除相邻的重复元素(只保留一个),所以使用前需要对数组进行排序 上面的一个使用中已经给出该函数的一个使用方法,对于长 ...
- js 面向对象 定义对象
js面向对象看了很多,却没有完全真正的理解,总是停留在一定的阶段,这次再认真看一下. 面向对象包含两种:定义类或对象:继承机制:都是通过工厂模式,构造函数,原型链,混合方法这四个阶段,原理也一样,只是 ...
- calltree+graphviz 绘出项目函数调用图
install calltree: download from http://linux.softpedia.com/progDownload/calltree-Download-971.html f ...