BZOJ1001 [BeiJing2006] Wolf catches rabbits

Source: Internet
Author: User

Topics 1001: [BeiJing2006] Wolf catches rabbits Time limit:15 Sec Memory limit:162 MB
submit:20245 solved:5038
[Submit] [Status] [discuss] Descriptionnow the children's favorite "pleasant goat and grey too wolf", saying that the wolf catch the sheep, but catch the rabbit is still more in line,and now the rabbits are more stupid, they have only two nests, now you as the Wolf King, facing the following a grid of terrain:

The upper- left corner is (n,m) and the lower-right corner is (n=4,m=5). There are three types of roads1: (x, y) <==> (x+1,y)2: (x, y) <==> (x,y+1)3: (x, y) <==> (x+1,y+1)the weight on the road indicates the maximum number of rabbits that can be passed along the road. The top left and bottom right corner are the two nests of rabbits,At the beginning all the rabbits were gathered in the upper left corner of the nest, and now they are going to go to the lower right (n,m) nest, the Wolf King began to ambushthese rabbits. Of course, for the sake of insurance, if the maximum number of rabbits on a road is K, the Wolf King needs to arrange the same number of k wolves,To completely block this road, you need to help the Wolf King to arrange an ambush plan, so that the rabbit clean sweep the premise of participation in thethe number of wolves should be minimal. Because the wolf also to find pleasant sheep and sheep trouble.Inputthe first act n,m. Represents the size of the mesh, n,m are less than or equal to.Next three partsThe first part is a total of n rows, the number of M-1 per row, indicating the weight of the transverse road.The second part of the total N-1 line, the number of M per row, indicating the weight of the longitudinal road.The third part of the total N-1 line, the number of M-1 per row, indicating the weighted value of the oblique road.input file guaranteed not to exceed 10MOutput

Outputs an integer that represents the minimum number of wolves involved in an ambush.

Sample Input3 4
5 6 4
4 3 1
7 5 3
5 6 7 8
8 7 6 5
5 5 5
6 6 6Sample Output -HINT

In 2015.4.16, a new group of data may be stuck in a previously available program.

Solving

A template problem

Start point as source point, end as meeting point

Points in the grid are points in the network

Edge mapping between edge points on a grid

Just run the network stream.

Attached full code

1 /**************************************************************2 problem:10013 user:q7478410824 language:c++5 result:accepted6 time:2056 Ms7 memory:83324 KB8 ****************************************************************/9  Ten#include <iostream> One#include <stdio.h> A#include <stdlib.h> -#include <string.h> - using namespacestd; the Const intinf=0x3f3f3f; -   - structEdge - { +     intnext,v,to; -}e[6000005]; +   A inthead[1000005]; at intN,m,s,t,cnt=1; - Long Longans=0; - inth[1000005],q[1000005]; -   - voidAddedge (intXintYintW//because the original image is a non-directed graph, the inverse edge weights can be set directly to W - { ine[++cnt].to=y;e[cnt].next=head[x];head[x]=cnt;e[cnt].v=W; -e[++cnt].to=x;e[cnt].next=head[y];head[y]=cnt;e[cnt].v=W; to}//It also avoids doubling the number of edges (a reverse edge with a weighted value of 0 is required for each edge), reducing the complexity of time and space +   - BOOLBFS () the { *     intHe=0, tail=1, now; $      for(intI=0; i<=t;i++)Panax Notoginsengh[i]=-1; -q[0]=s;h[s]=0; the      while(he!=tail) +     { Anow=Q[he]; thehe++; +          for(inti=head[now];i!=-1; i=e[i].next) -             if(e[i].v&&h[e[i].to]==-1) $             { $h[e[i].to]=h[now]+1; -q[tail++]=e[i].to; -             } the     } -     returnh[t]!=-1;Wuyi } the   - intDfsintXintf) Wu { -     if(x==t) About        returnF; $     intW,used=0; -      for(inti=head[x];i!=-1; i=e[i].next) -         if(h[e[i].to]==h[x]+1) -         { Aw=f-used; +w=Dfs (E[i].to,min (W,E[I].V)); thee[i].v-=w;e[i^1].v+=W; -used+=W; $             if(used==f) the                returnF; the         } the     if(!used) h[x]=-1; the     returnused; - } in   the voiddinic () the { About      while(BFS ()) theans+=DFS (s,inf); the } the   + intMain () - { the     intw,i,j;Bayiscanf"%d%d",&n,&m); thememset (head,-1,sizeof(head)); thes=1; t=n*m; -      for(i=1; i<=n;i++) -          for(j=1; j<=m-1; j + +) the         { thescanf"%d",&W); theAddedge ((I-1) *m+j, (I-1) *m+j+1, W); the         } -      for(i=1; i<=n-1; i++) the          for(j=1; j<=m;j++) the         { thescanf"%d",&W);94Addedge ((I-1) *m+j,i*m+j,w); the         } the      for(i=1; i<=n-1; i++) the          for(j=1; j<=m-1; j + +)98         { Aboutscanf"%d",&W); -Addedge ((I-1) *m+j,i*m+j+1, W);101         }102 dinic ();103printf"%lld\n", ans);104     return 0; the}

BZOJ1001 [BeiJing2006] Wolf catches rabbits

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.