"bzoj1066" [SCOI2007] Lizard network Max stream

Source: Internet
Author: User

"bzoj1066" [SCOI2007] Lizard description

In the grid map of a row C column, there are some highly different pillars, some of which stand on a few lizards, and your task is to get as many lizards as possible to escape the border. The distance of each column in each row is 1, and the lizard's jumping distance is D, that is, the lizard can jump to any one of the columns with a plane distance not exceeding d. The columns are unstable, and each time the lizard jumps, the height of the stone column is reduced by 1 (if it still falls inside the map, the height of the stone column is not changed), and if the column has a height of 1, the lizard disappears after it leaves. Other lizards cannot settle in the future. No two lizards can be found on the same stone column at any one time.

Input

Enter the first behavior three integer r,c,d, which is the size of the map and the maximum jump distance. The following r behavior is the initial state of the carnation, 0 means that there are no columns, and the initial height of the column. The following r behavior is the lizard position, "L" denotes the lizard, "." means no lizards.

Output

The output is only one row, containing an integer, the minimum number of lizards that cannot escape.

Sample INPUT5 8 2
00000000
02000000
00321100
02000000
00000000
........
........
.. Llll.
........
........ Sample Output1hint

100% data satisfies: 1<=r, c<=20, 1<=d<=3

Code

For each pillar, take the idea of dividing a point into two points (which can be abstracted from the bottom to the top), and its connection capacity is limited to the height of the stone column.

The super source is connected to all lizard-like points with a capacity of 1.

The super sink is connected to the bottom of all the points in the map that can jump out, and the capacity is INF.

For any of the two columns in the map, if the spacing is less than D, the bottom of one of the columns is connected to the top of the other pillar, and its connection capacity is INF.

The composition is complete, the rest is running the maximum flow, and then the number of lizards minus the maximum flow is the final result.

#include <cstdio>#include<cmath>#include<cstring>#include<ctime>#include<iostream>#include<algorithm>#include<Set>#include<vector>#include<queue>#include<typeinfo>#include<map>#include<stack>typedefLong Longll;using namespacestd;inline ll Read () {ll x=0, f=1; CharCh=GetChar ();  while(ch<'0'|| Ch>'9')    {        if(ch=='-') f=-1; CH=GetChar (); }     while(ch>='0'&&ch<='9') {x=x*Ten+ch-'0'; CH=GetChar (); }    returnx*F;}//***************************namespacenetflow{Const intmaxn=100000, maxm=500000, inf=1e9;structedge{intV,c,f,nx; Edge () {} Edge (intVintCintFintNX): V (v), C (c), F (f), NX (NX) {}} E[MAXM];intG[maxn],cur[maxn],pre[maxn],dis[maxn],gap[maxn],n,sz;voidInitint_n) {N=_n,sz=0; memset (G,-1,sizeof(g[0])*N);}voidLinkintUintVintc) {E[sz]=edge (V,c,0, G[u]); G[u]=sz++; E[SZ]=edge (U,0,0, G[v]); G[V]=sz++;}intISAP (intSintT) {    //T-S    intmaxflow=0, aug=inf,flag=false, U,v;  for(intI=0; i<n; ++i) cur[i]=g[i],gap[i]=dis[i]=0;  for(Gap[s]=n,u=pre[s]=s; dis[s]<n; flag=false)    {         for(int&it=cur[u]; ~it; it=e[it].nx) {            if(e[it].c>e[it].f&&dis[u]==dis[v=e[it].v]+1)            {                if(AUG&GT;E[IT].C-E[IT].F) aug=e[it].c-e[it].f; PRE[V]=u,u=v; Flag=true; if(u==T) { for(Maxflow+=aug; u!=S;) {E[cur[u=pre[u]]].f+=; E[cur[u]^1].f-=; } the=inf; }                 Break; }        }        if(flag)Continue; intmx=N;  for(intIt=g[u]; ~it; it=e[it].nx) {            if(e[it].c>e[it].f&&dis[e[it].v]<mx) {mx=DIS[E[IT].V]; Cur[u]=it; }        }        if((--gap[dis[u]) = =0) Break; ++gap[dis[u]=mx+1]; U=Pre[u]; }    returnMaxflow;}BOOLBFsintSintT) {    Static intQ[MAXN]; memset (DIS,-1,sizeof(dis[0])*N); Dis[s]=0; q[0]=S;  for(intH=0, t=1, U,v,it; h<t; ++h) { for(U=q[h],it=g[u]; ~it; it=e[it].nx) {            if(dis[v=e[it].v]==-1&&E[it].c>e[it].f) {Dis[v]=dis[u]+1; Q[t++]=v; }        }    }    returndis[t]!=-1;}intDfsintUintTintLow ) {    if(u==t)returnLow ; intret=0, Tmp,v;  for(int&it=cur[u]; ~it&&ret<low; it=e[it].nx) {        if(dis[v=e[it].v]==dis[u]+1&&E[it].c>e[it].f) {            if(Tmp=dfs (V,t,min (low-ret,e[it].c-E[IT].F)))  {ret+=tmp; E[IT].F+=tmp; E[it^1].f-=tmp; }        }    }    if(!ret) dis[u]=-1; returnret;}intDinic (intSintT) {    intmaxflow=0, TMP;  while(BFS (s,t)) {memcpy (cur,g,sizeof(g[0])*N);  while(Tmp=dfs (S,t,inf)) maxflow+=tmp; }    returnMaxflow;}}using namespaceNetFlow;DoubleDistintAintBintXinty) {    returnsqrt ((b-y) * (b-y) + (a-x) * (A-x));}intMain () {intn,m,d; Charmp[ -][ -],mp2[ -][ -]; CIN>>n>>m>>D; Init ( the);  for(intI=1; i<=n; i++) {scanf ("%s", mp[i]+1); }     for(intI=1; i<=n; i++) {scanf ("%s", mp2[i]+1); }     for(intI=1; i<=n; i++)    {         for(intj=1; j<=m; J + +)        {            if((mp[i][j]-'0') >0)            {                 for(inth=i-d; h<=i+d; h++)                {                     for(intk=j-d; k<=j+d; k++)                    {                        if(h==i&&j==k)Continue; if(h<0|| k<0|| h>n+1|| k>m+1)                            Continue; Doubledd=d*1.0; if(Dist (i,j,h,k) >dd)Continue; if(h==0|| k==0|| h==n+1|| k==m+1) Link ((I-1) *m+j+ -, +, INF); ElseLink (i-1) *m+j+ -, (H1) *m+K,inf); }} link ((I-1) *m+j, (I-1) *m+j+ -, mp[i][j]-'0'); }        }    }    intsum=0;  for(intI=1; i<=n; i++)    {         for(intj=1; j<=m; J + +)        {            if(mp2[i][j]=='L') {sum++; Link (999, (I-1) *m+j,1); } }} cout<<sum-dinic (999, +) <<Endl; return 0;}

"bzoj1066" [SCOI2007] Lizard network Max stream

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.