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& ...
随机推荐
- PAT 1077 互评成绩计算(20)(代码+思路)
1077 互评成绩计算(20 分) 在浙大的计算机专业课中,经常有互评分组报告这个环节.一个组上台介绍自己的工作,其他组在台下为其表现评分.最后这个组的互评成绩是这样计算的:所有其他组的评分中,去掉一 ...
- geoserver中除了使用kml来查询数据以外,还可以使用csql或ecsql
package com.geoserver; import java.io.IOException; import java.util.ArrayList; import java.util.Hash ...
- Windows游戏找不到了怎么办?
大家有的时候,可能是不慎操作,或是某些新装的Windows,会发现那些经典的游戏不见了,那它们去哪了呢?是长腿跑了?还是Windows偷工减料?都不是,让巩固来教你们把他们找出来! 1.在开 ...
- C++加速程序的全局执行函数
static int wing=[]() { std::ios::sync_with_stdio(false); cin.tie(NULL); ; }(); C++的cin和cout在输入输出时,会先 ...
- 2018.09.15 vijos1053Easy sssp(最短路)
传送门 貌似可以最短路时同时判定负环啊. 但我不想这样做. 于是写了一个dfs版的判环,bfs版的求最短路. 代码: #include<iostream> #include<ccty ...
- 61 origin授控于MATLAB
官方教程:http://www.originlab.com/forum/topic.asp?TOPIC_ID=22339 学习自白东升老师originPRO8.0教程. 我用的是origin pro2 ...
- MapGIS Mobile开发
1. 先将Android开发环境配置好(包括Java + Eclipse + Android SDK) 2. 加载API类库(运行MapGIS 10 AndroidSDK.exe可以加载Mobile框 ...
- hdu 4981
中位数是否大于平均数 水题 #include <cstdio> #include <cstdlib> #include <cmath> #include <c ...
- C++实现wc.exe程序
github项目地址:https://github.com/insomniali/wc 基本功能 wc.exe -c file 统计文件file的字符数 [实现] wc.exe -w fil ...
- mod_pagespeed
https://github.com/pagespeed/mod_pagespeed.git https://developers.google.com/speed/pagespeed/module/ ...