1066: [SCOI2007] lizard time limit: 1 Sec Memory Limit: 162 MB
Submit: 2512 Solved: 1238
[Submit] [Status] [Discuss] 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<=4
Source
<a href= "http://www.lydsy.com/JudgeOnline/problemset.php?search=Pku%202711%20Leapin" lizards ' = "style=" COLOR: Blue Text-decoration:none; " >pku 2711 Leapin ' lizards
The minimum value of a lizard that requires the inability to escape is the maximum value of the lizard that can escape. Choose to use the maximum flow , of course focusing on the composition.
For each column, we can split into two points, respectively, into points and out points.
For all columns, from the in point to the out point edge, the capacity is high. This is tantamount to limiting the number of hops for each stone column.
For columns that initially have lizards, the point of origin is connected to the points at the points, with a capacity of 1. Because each pillar has only one lizard.
For any pair of columns that can reach each other, from each other's out point to the point of connection, the capacity is positive infinity. equals to assume that there can be as many lizards as possible to jump over.
For columns that can jump outside the boundary, the edge is connected from the out point to the sink point, and the capacity is positive infinity. Principle Ibid.
#include <iostream> #include <cstdio> #include <cmath> #include <algorithm> #include < cstdlib> #include <cstring> #include <queue> #define F (i,j,n) for (int i=j;i<=n;i++) #define D (I,j,n) for (int i=j;i>=n;i--) #define LL long long#define pa pair<int,int> #define MAXN 1000#define MAXM 100000#define INF 1000000000#define F1 (x, y) ((x-1) *m+y) #define F2 (x, y) ((x-1) *m+y+m*n) using namespace Std;int Cnt=1,ans=0,s,t,n,m,d;int Head[maxn],cur[maxn],dis[maxn],f[25][25];char ch[25];struct edge_type{int next,to,v;} e[maxm];inline void Add_edge (int x,int y,int v) {e[++cnt]= (Edge_type) {head[x],y,v};head[x]=cnt;e[++cnt]= (Edge_type) { head[y],x,0};head[y]=cnt;} inline bool BFs () {Queue<int>q;while (!q.empty ()) Q.pop (), memset (dis,-1,sizeof (dis));d Is[s]=0;q.push (s); (!q.empty ()) {int Tmp=q.front (); Q.pop (); if (tmp==t) return true;for (int i=head[tmp];i;i=e[i].next) if (e[i].v&&dis[e[i].to ]==-1) {Dis[e[i].to]=dis[tmp]+1;q.push (e[i].to);}} return false;} inline int DFS (int x,int f) {int tmp,sum=0;if (x==t) return f;for (int &i=cur[x];i;i=e[i].next) {int y=e[i].to;if (e[i].v&& amp;dis[y]==dis[x]+1) {Tmp=dfs (Y,min (F-SUM,E[I].V)); E[i].v-=tmp;e[i^1].v+=tmp;sum+=tmp;if (sum==f) return sum;}} if (!sum) Dis[x]=-1;return sum;} inline void Dinic () {while (BFS ()) {F (i,1,t) Cur[i]=head[i];ans-=dfs (S,inf);}} inline bool Excape (int x,int y) {return min (min (x,n+1-x), Min (y,m+1-y)) <=d;} inline bool Judge (int x1,int y1,int x2,int y2) {if (x1==x2&&y1==y2) return False;return (F[X1][Y1]&&F[X2] [y2]&& ((x1-x2) * (X1-X2) + (y1-y2) * (y1-y2)) <= (D*d));} int main () {scanf ("%d%d%d", &n,&m,&d); s=2*n*m+1;t=s+1; F (i,1,n) {scanf ("%s", ch); F (j,1,m) f[i][j]=ch[j-1]-' 0 ';} F (i,1,n) {scanf ("%s", ch); F (j,1,m) if (ch[j-1]== ' L ') {Add_edge (S,f1 (I,J), 1); ans++;}} F (i,1,n) f (j,1,m) if (F[i][j]) {Add_edge (F1 (I,J), F2 (i,j), f[i][j]), if (Excape (i,j)) Add_edge (F2 (i,j), t,inf);} F (i,1,n) F (j,1,m) F (Ti,max (1,i-d), Min (n,i+d)) F (Tj,max (1,j-d), Min (m,j+d)) if (judge (I,J,TI,TJ)) add_eDge (F2 (i,j), F1 (TI,TJ), INF);d inic ();p rintf ("%d\n", ans);}
bzoj1066 "SCOI2007" lizard