BZOJ 1001 题解
1001: [BeiJing2006]狼抓兔子
Time Limit: 15 Sec  Memory Limit: 162 MB
Submit: 18876  Solved: 4649
[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
HINT
Source
——————————————————分割线——————————————————
这道题是一道很玄学的题目,我们不能直接求它的最小割,要通过它的对偶图的最短路。那么怎么完成呢?


这时,只需求点1到点14的最短路就行啦。
[ATTENTION]:这道题点数总共有( N - 1 ) * ( M - 1) * 2 + 2 个,本蒟蒻被坑了好久。注意数组大小!!!
推荐一个课件:浅析最大最小定理在信息学竞赛中的应用
/**************************************************************
Problem: 1001
User: shadowland
Language: C++
Result: Accepted
Time:2752 ms
Memory:165356 kb
****************************************************************/ #include "bits/stdc++.h" using namespace std ;
struct Edge { int to , next , val ; } ;
const int maxN = ; Edge e[ maxN ] ;
int head[ maxN ] , Dis[ maxN ] ;
bool vis[ maxN ] ; int N , M , cnt ; inline int INPUT ( ) {
int x = , f = ; char ch = getchar ( ) ;
while ( ch < '' || ch > '' ) { if ( ch == '-')f = - ; ch = getchar ( ) ;}
while ( ch >= '' && ch <= '' ) { x = ( x << ) + ( x << ) + ch - '' ; ch = getchar ( ) ;}
return x * f ;
} inline int Get ( const int x , const int y , const int z ) {
if ( x < || y >=M ) return ( N - ) * ( M - ) * + ;
if ( x >= N || y < ) return ;
return ( ( x - ) * ( M - ) + y ) * + z ;
} inline void Add_Edge ( const int x , const int y , const int _val ) {
e[ ++cnt ].to = y ;
e[ cnt ].val = _val ;
e[ cnt ].next = head[ x ] ;
head[ x ] = cnt ;
} void SPFA ( const int S ) {
memset ( vis , false , sizeof ( vis ) ) ;
memset ( Dis , 0x3f , sizeof ( Dis ) ) ;
queue < int > Q ;
Dis[ S ] = ;
vis[ S ] = true ;
Q.push ( S ) ;
while ( !Q.empty ( ) ) {
int t = Q.front( ) ; Q.pop ( ) ; vis[ t ] = false ;
for ( int i=head[ t ] ; i ; i = e[ i ].next ) {
int temp = e[ i ].to ;
if ( Dis[ temp ] > Dis[ t ] + e[ i ].val ) {
Dis[ temp ] = Dis[ t ] + e[ i ].val ;
if ( !vis[ temp ] ) {
Q.push ( temp ) ;
vis[ temp ] = true ;
}
}
}
}
} void DEBUG_ ( int N , int M ) {
printf ( "\n" ) ;
for ( int i= ; i<=(( N - ) * ( M - ) * + ) ; ++i ) {
printf ( "%d " , Dis[ i ] ) ;
}
}
int main ( ) {
int _val ;
scanf ( "%d %d" , &N , &M ) ;
for ( int i= ; i<=N ; ++i ) {
for ( int j= ; j<M ; ++j ) {
_val = INPUT ( ) ;
Add_Edge ( Get ( i , j , ) , Get ( i - , j , ) , _val ) ;
Add_Edge ( Get ( i - , j , ) , Get ( i , j , ) , _val ) ;
}
}
for ( int i= ; i<N ; ++i ) {
for ( int j= ; j<=M ; ++j ) {
_val = INPUT ( ) ;
Add_Edge ( Get ( i , j - , ) , Get ( i , j , ) , _val ) ;
Add_Edge ( Get ( i , j , ) , Get ( i , j - , ) , _val ) ;
}
}
for ( int i= ; i<N ; ++i ) {
for ( int j= ; j<M ; ++j ) {
_val = INPUT ( ) ;
Add_Edge ( Get ( i , j , ) , Get ( i , j , ) , _val ) ;
Add_Edge ( Get ( i , j , ) , Get ( i , j , ) , _val ) ;
}
}
SPFA ( ) ;
printf ( "%d\n" , Dis[ ( N - ) * ( M - ) * + ] ) ;
//DEBUG_( N , M ) ; return ;
}
2016-10-12 23:35:00
(完)
BZOJ 1001 题解的更多相关文章
- BZOJ 1001 [BeiJing2006] 狼抓兔子(平面图最大流)
		题目大意 现在小朋友们最喜欢的"喜羊羊与灰太狼",话说灰太狼抓羊不到,但抓兔子还是比较在行的.而且现在的兔子还比较笨,它们只有两个窝,现在你做为狼王,面对下面这样一个网格的地形: ... 
- s - t 平面图最大流 (附例题 bzoj 1001)
		以下均移自 周冬的<两极相通-浅析最大最小定理在信息学竞赛中的应用> 平面图性质 1.(欧拉公式)如果一个连通的平面图有n个点,m条边和f个面,那么f=m-n+2 2.每个平面图G都有一个 ... 
- BZOJ 1001 狼抓兔子 (网络流最小割/平面图的对偶图的最短路)
		题目链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1001 算法讨论: 1.可以用最大流做,最大流等于最小割. 2.可以把这个图转化其对偶图,然 ... 
- BZOJ 1001 - 狼抓兔子 - [Dinic最大流][对偶图最短路]
		题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1001 Description现在小朋友们最喜欢的"喜羊羊与灰太狼", ... 
- bzoj一句话题解
		发现好多人都在搞这个...本人也想来试试(Solved刚到70就搞这个靠不靠谱啊喂).会更新的.嗯. 1000-1029 1000 A+B problem (这个还需要一句话吗?). 1001 狼抓兔 ... 
- BZOJ 1001 [BeiJing2006]狼抓兔子 (UVA 1376 Animal Run)
		1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 24727 Solved: 6276[Submit][ ... 
- 【24.58%】【BZOJ 1001】狼抓兔子
		Time Limit: 15 Sec Memory Limit: 162 MB Submit: 19227 Solved: 4726 [Submit][Status][Discuss] Descrip ... 
- BZOJ 1001: [BeiJing2006]狼抓兔子
		1001: [BeiJing2006]狼抓兔子 Time Limit: 15 Sec Memory Limit: 162 MBSubmit: 20029 Solved: 4957[Submit][ ... 
- BZOJ 3732 题解
		3732: Network Description 给你N个点的无向图 (1 <= N <= 15,000),记为:1…N. 图中有M条边 (1 <= M <= 30,000) ... 
随机推荐
- 苹果开发者账号申请时报错提示错误:Legal Entity Name
			he information you entered did not match your profile in the D&B database. Before submitting you ... 
- 在Win7 64位注册ActiveX控件
			首先必须以管理员身份运行cmd.exe,即在cmd.exe右键选择以管理员身份运行. 目前共有两个存在网络盘的文件需要注册,一个dll,一个ocx. 开始时将两个文件都拷贝到c:\wind ... 
- 全局压缩http响应头
			见代码: public class CompressAttribute : ActionFilterAttribute { public override void OnActionExecuting ... 
- 重温WCF之数据契约和序列化(四)
			一.数据契约 1.使用数据协定可以灵活控制哪些成员应该被客户端识别. [DataContract] public class Employee { [DataMember] public string ... 
- 【JAVA网络流之TCP与UDP 】
			一.ServerSocket java.lang.Object |-java.net.ServerSocket 有子类SSLServerSocket. 此类实现服务器套接字.服务器套接字等待请求通过网 ... 
- RTP、RTCP及媒体流同步
			转自:http://blog.163.com/liu_nongfu/blog/static/19079414220139169225333/ 一.流媒体简介 流媒体是指在internet中使用流媒体技 ... 
- PMP 第五章 项目范围管理
			1.范围管理主要是干什么?什么是产品范围?什么是项目范围? 项目范围管理包括确保项目做而且只做成功完成项目所需的全部工作的各过程.管理项目范围主要是在定义和控制哪些工作应该包括在项目内,哪些不应 ... 
- mysql_multi启动数据库
			1.初始化数据库 在$mysql_base目录下,新增加存放data的文件夹,用mysql_install_db命令执行初始化 [root@ora11g scripts]# ./mysql_insta ... 
- Vue入门笔记#过渡
			Vue过渡,可以在元素从DOM中移除,插入时自动调用过渡效果.根据设定,会适时的触发过渡效果. 在使用的目标标签里添加 transition: <div transition="my_ ... 
- SQL连接查询、变量、运算符、分支、循环语句
			连接查询:通过连接运算符可以实现多个表查询.连接是关系数据库模型的主要特点,也是它区别于其它类型数据库管理系统的一个标志. 常用的两个链接运算符: 1.join on 2.union 在关系数据库 ... 
