HDU 2732 leapin 'lizards (max Stream)

Source: Internet
Author: User
Leapin 'lizards

Question link: http://acm.hdu.edu.cn/showproblem.php? PID = 1, 2732

 

It seems difficult to understand the meaning of the question.

The question is that in a n * m maze, each grid has a column. The height of the column is 0 ~ 3. A pillar with a height of 0 cannot stand on the site. (If the height is 0, there is no pillar)

There are some columns on some columns.Lizard, the maximum hop distance at a time is d, and the distance between adjacent grids is 1. It is safe to jump out of the maze.

This distance is the distance from the Manhattan (as if yes ).

A lizard can jump at most from D at a time, but the height of the column in the place where the jump is made is reduced by one. A column can only have one lizard at a time.

Requires at least a few to avoid escaping from the maze.

Let's take a look at the specific meaning of the question. A lot of descriptions are unclear ~~ Good English

This is the largest stream.

To split a point, the capacity of the two points is the height of the column.

Add a source and sink.

 //  ========================================================== ==========================================  // Name: HDU. cpp  //  Author:  //  Version:  //  Copyright: Your copyright notice  //  Description: Hello world in C ++, ANSI-style  //  ========================================================== ==========================================  # Include <Iostream> # Include <String . H> # Include <Stdio. h> # Include <Algorithm> Using   Namespace  STD;  Const   Int Maxn = 2200  ;  Const   Int Maxm = 200020  ;  Const  Int INF = 0x3f3f3f  ;  Struct  Node {  Int  To, next, cap;} edge [maxm];  //  Note: maxm  Int  Tol;  Int  Head [maxn];  Int  Gap [maxn], DIS [maxn], pre [maxn], cur [maxn];  Void Init () {Tol = 0  ; Memset (Head, - 1 , Sizeof  (Head ));}  Void Addedge ( Int U, Int V, Int W, Int RW = 0  ) {Edge [tol]. = V; edge [tol]. Cap = W; edge [tol]. Next = head [u]; head [u] = tol ++; Edge [tol]. = U; edge [tol]. Cap = RW; edge [tol]. Next = head [v]; head [v] = tol ++ ;}  Int SAP ( Int Start, Int End, Int  Nodenum) {memset (DIS,  0 , Sizeof  (DIS); memset (gap,  0 , Sizeof  (GAP); memcpy (cur, Head, Sizeof  (Head ));  Int U = pre [start] = start, maxflow = 0 , Aug =- 1  ; Gap [  0 ] = Nodenum;  While (DIS [start] < Nodenum) {loop:  For ( Int & I = cur [u]; I! =- 1 ; I =Edge [I]. Next ){  Int V = Edge [I].;  If (Edge [I]. Cap & dis [u] = dis [v] + 1  ){  If (Aug =- 1 | Aug> Edge [I]. Cap) Aug = Edge [I]. CAP; Pre [v] = U; u = V; If (V = End) {maxflow + = Aug;  For (U = pre [u]; V! = Start; V = u, u = Pre [u]) {edge [cur [u]. Cap -= Aug; edge [cur [u] ^ 1 ]. Cap + = Aug;} Aug =- 1  ;}  Goto Loop ;}}  Int Mindis = Nodenum;  For ( Int I = head [u]; I! =- 1 ; I = Edge [I]. Next ){  Int V = Edge [I].;  If (Edge [I]. Cap & mindis> Dis [v]) {cur [u] = I; mindis =Dis [v] ;}}  If (-- Gap [dis [u]) = 0 ) Break  ; Gap [dis [u] = Mindis + 1 ] ++ ; U = Pre [u];}  Return  Maxflow ;}  Char G1 [ 30 ] [ 30  ]; Char G2 [ 30 ] [ 30  ];  Int Mat [ 30 ] [ 30  ];  Int  Main (){  //  Freopen ("in.txt", "r", stdin );  //  Freopen ("out.txt", "W", stdout );      Int  T; Int  N, D;  Int Icase = 0  ; Scanf (  "  % D  " ,& T );  While (T -- ) {Icase ++ ; Scanf (  "  % D  " , & N ,&D); Init ();  Int Tol = 0  ;  For ( Int I = 0 ; I <n; I ++ ) Scanf (  "  % S  " ,& G1 [I]);  Int M = strlen (G1 [ 0 ]); Memset (mat,  0 , Sizeof  (MAT ));  For ( Int I = 0 ; I <n; I ++ )  For ( Int J = 0 ; J <m; j ++ )  If (G1 [I] [J]> ' 0  '  ) {Mat [I] [J] = ++ Tol; addedge (  2 * TOL- 1 , 2 * Tol, G1 [I] [J]- '  0  '  );}  Int Start = 0 , End = 2 * Tol +1 , Nodenum = 2 * Tol + 2  ;  //  Split points, plus source points and sink points, a total of 2 x tol + 2 points.          Int Sum = 0 ; //  Total          For ( Int I = 0 ; I <n; I ++ ) {Scanf (  " % S  " ,& G2 [I]);  For ( Int J = 0 ; J <m; j ++ )  If (G2 [I] [J] = '  L  '  ) {Sum ++ ; Addedge (start,  2 * Mat [I] [J]-1 , 1  );}}  For ( Int I = 0 ; I <n; I ++ )  For ( Int J = 0 ; J <m; j ++ )  If  (MAT [I] [J]) {  For (Int X =-D; x <= D; X ++ )  For ( Int Y = ABS (x)-D; y <= D-ABS (x); y ++ ){  Int Newi = I + X;  Int Newj = J + Y;  If (Newi < 0 | Newi> = n | newj < 0 | Newj> = m)Continue  ;  If (MAT [newi] [newj] = 0 ) Continue  ;  If (Newi = I & newj = J) Continue  ; Addedge (  2 * Mat [I] [J], 2 * Mat [newi] [newj]- 1  , INF );} If (I <d | j <d | n-I <= d | M-j <= D) addedge (  2 * Mat [I] [J], end, INF );}  Int Ans = sum- SAP (START, end, nodenum );  If (ANS = 0 ) Printf ( "  Case # % d: No lizard was left behind. \ n  "  , Icase );  Else  If (ANS = 1 ) Printf ( "  Case # % d: 1 lizard was left behind. \ n  "  , Icase );  Else Printf ( "  Case # % d: % d lizards were left behind. \ n  "  , Icase, ANS );}  Return   0  ;} 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.