Bzoj 1066 Lizard

Source: Internet
Author: User

Network flow.

Map: First split each pillar into two points.

The in point of each pillar points outward to an edge with a capacity of column height.

The out point of each pillar is connected to the point at which a column can be reached, and a capacity is a positive infinity edge.

The point of Origin is connected to one edge of each column that has an initial lizard.

Each pillar that jumps out of the map will have a positive infinity edge to the sink point.

Running the maximum flow is the number of lizards that can escape.

1#include <cstring>2#include <cstdio>3#include <algorithm>4#include <iostream>5#include <cmath>6#include <queue>7 using namespacestd;8 Const intdian=8005;9 Const intbian=160005;Ten Const intinf=0x3f3f3f3f; One intH[dian],nxt[bian],ver[bian],val[bian],ch[dian]; A Charmapp[ -][ -],map[ -][ -]; - Charlala[ -]; - intN,m,d,tot,ans; the ints,t; - voidAddintAaintBbintcc) { -tot++;ver[tot]=bb;nxt[tot]=h[aa];val[tot]=cc;h[aa]=tot; -tot++;ver[tot]=aa;nxt[tot]=h[bb];val[tot]=0; h[bb]=tot; + } - intBhintCanintBbintcc) { +     return(aa-1) *m+bb+cc*n*m; A } at BOOLTell () { -memset (ch,-1,sizeof(CH)); -queue<int>Q; - Q.push (S); -ch[s]=0; -      while(!Q.empty ()) { in         intt=Q.front (); - Q.pop (); to          for(intI=h[t];i;i=Nxt[i]) +             if(ch[ver[i]]==-1&&Val[i]) { - Q.push (Ver[i]); thech[ver[i]]=ch[t]+1; *             } $     }Panax Notoginseng     returnch[t]!=-1; - } the intZengintAintb) { +     if(a==T) A         returnb; the     intR=0; +      for(intI=h[a];i&&b>r;i=Nxt[i]) -         if(ch[a]+1==ch[ver[i]]&&Val[i]) { $             intT=zeng (Ver[i],min (b-r,val[i])); $val[i]-=t,r+=t,val[i^1]+=T; -         } -     if(!R) thech[a]=-1; -     returnR;Wuyi } the intDinic () { -     intR=0, T; Wu      while(Tell ()) -          while(t=Zeng (S,inf)) Aboutr+=T; $     returnR; - } - intMain () { -tot=1; Ascanf"%d%d%d",&n,&m,&d); +s=2*n*m+1, t=2*n*m+2; the      for(intI=1; i<=n;i++) -scanf"%s", mapp[i]+1); $      for(intI=1; i<=n;i++) the          for(intj=1; j<=m;j++) themap[i][j]=mapp[i][j]-'0'; the      for(intI=1; i<=n;i++) the          for(intj=1; j<=m;j++) -             if(Map[i][j]) { inAdd (BH (i,j,0), BH (i,j,1), map[i][j]); the                  for(intk=i-d;k<=i+d;k++) the                      for(intl=j-d;l<=j+d;l++) About                         if(k>=1&&k<=n&&l>=1&&l<=m&& (k!=i| | L!=J) &&abs (k-i) *abs (k-i) +abs (l-j) *abs (l-j) <=d*d&&Map[k][l]) theAdd (BH (i,j,1), BH (k,l,0), INF); the             } the      for(intI=1; i<=n;i++) +          for(intj=1; j<=m;j++) -             if(Min (Min (i,n+1-i), Min (j,m+1-J)) <=d&&Map[i][j]) theAdd (BH (i,j,1), t,inf);Bayi      for(intI=1; i<=n;i++){ thescanf"%s", lala+1); the          for(intj=1; j<=m;j++) -             if(lala[j]=='L'){ -ans++; theAdd (S,BH (I,j,0),1); the             } the     } theprintf"%d", ans-dinic ()); -     return 0; the}

Attention:

The size of the array should be counted well.

Read-in is in string form.

Distance is Euclidean distance.

Bzoj 1066 Lizard

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.