HDU 2732 Leapin ' lizards (split + max Stream)

Source: Internet
Author: User

The title means that there are some lizards in a maze, and how many of these lizards can not escape anyway. The title is given only one row n, and the furthest distance to jump is D. Each lizard has an initial position, the title guarantees that there are some pillars in these positions, but when it leaves a pillar, the height of the column will be lowered by 1m, and the maximum number of questions can be skipped.

The point at which each pillar is to be split, after each point is removed, a capacity is attached to the edge of the column height of the point at which it is located. Connect a 1-edged edge from the origin, and then find each point that can be directly out of the way, connecting the points to the sink with infinite capacity. The capacity of each pillar and the point it can reach is also infinite.


Leapin ' lizards Time limit:2000/1000 MS (java/others) Memory limit:32768/32768 K (java/others)
Total submission (s): 1254 Accepted Submission (s): 524


Problem Descriptionyour platoon of wandering Lizards has entered a strange the The labyrinth. As you is looking around for hidden treasures, one of the rookies steps in an innocent-looking stone and the the "s floor Suddenly disappears! Each lizard in your platoon are left standing on a fragile-looking pillar, and a fire begins to rage below ... Leave no lizard behind! Get as many lizards as possible out of the the-the-same, and report the number of casualties.
The pillars in the class is aligned as a grid, with each pillar one unit away from the pillars to it east, west, north an D South. Pillars at the edge of the grid is one unit away from the edge of the The (safety). Not all pillars necessarily has a lizard. A Lizard is able to leap onto any unoccupied pillar the is within D units of he current one. A lizard standing on a pillar within leaping distance of the edge of the the-the-the-all leap to safety ... but there ' s a C Atch:each pillar becomes weakened after each jump, and would soon collapse and no longer be usable by other lizards. Leaping onto a pillar does not cause it to weaken or collapse; Only leaping off of it causes it to weaken and eventually collapse. Only one lizard-pillar at any given time.
Inputthe input file would begin with a line containing a single integer representing the number of test cases, which are at Most 25. Each test case would begin with a line containing a single positive an integer n representing the number of rows in the map, F Ollowed by a single non-negative integer d representing the maximum leaping distance for the lizards. Both maps would follow, each as a map of characters with one row per line. The first map would contain a digit (0-3) in each position representing the number of jumps the pillar in that position wil L Sustain before collapsing (0 means there is no pillar there). The second map would follow, with a ' L ' for every position where a lizard are on the pillar and a '. ' For every empty Pilla R. There'll never be a lizard to a position where there is no pillar. Each input map was guaranteed to be a rectangle of size n x m, where 1≤n≤20 and 1≤m≤20. The leaping distance is
Always 1≤d≤3.
Outputfor each input case, print a single line containing the number of lizards this could not escape. The format should follow the samples provided below.
Sample Input
1111111111111llllllllllll3 2000000111000000......LLL ... 3 1000000111000000......LLL ... 5 20000000002000000003211000200000000000000..................LLLL ......... .....

Sample Output
Case #1:2 lizards were left behind. Case #2: No lizard is left behind. Case #3:3 lizards were left behind. Case #4:1 lizard is left behind.
#include <algorithm> #include <iostream> #include <stdlib.h> #include <string.h> #include < iomanip> #include <stdio.h> #include <string> #include <queue> #include <cmath> #include < stack> #include <map> #include <set> #define EPS 1e-12///#define M 1000100#define ll __int64///#define LL Long long///#define INF 0x7ffffff#define inf 0x3f3f3f3f#define PI 3.1415926535898#define Zero (x) ((Fabs (x) <eps)? 0:x) using namespace Std;const int maxn = 1100;int cnt;int N, m;int Cur[maxn], Head[maxn];int DIS[MAXN], Gap[maxn];int AUG[MAXN    ], pre[maxn];int num[maxn];struct node{int V, W; int next;}    F[2010000];void init () {cnt = 0; Memset (Head,-1, sizeof (head));}    void Add (int u, int v, int w) {f[cnt].v = v;    F[CNT].W = W;    F[cnt].next = Head[u];    Head[u] = cnt++;    F[CNT].V = u;    F[CNT].W = 0;    F[cnt].next = Head[v]; HEAD[V] = cnt++;}    int SAP (int s, int e, int n) {int max_flow = 0, V, u = s;    int ID, Mindis;Aug[s] = INF;    Pre[s] =-1;    memset (dis, 0, sizeof (DIS));    memset (Gap, 0, sizeof (GAP));    Gap[0] = n;        for (int i = 0; I <= N; ++i) Cur[i] = head[i];///initializes the current arc to the first arc while (Dis[s] < n) {bool flag = false;            if (U = = e) {Max_flow + = Aug[e];                for (v = pre[e]; v =-1; v = pre[v])///path backtracking update residual network {id = cur[v];                F[ID].W-= Aug[e];                F[ID^1].W + = Aug[e]; AUG[V]-= aug[e]; Modify the augmented amount, which will be used later if (F[ID].W = = 0) u = V;             Do not fall back to the source point, fall back only to the arc end of the arc with a capacity of 0} for (id = cur[u]; ID! =-1; id = f[id].next)///start with current arc to find the Allow arc {            v = f[id].v;                if (f[id].w > 0 && dis[u] = = Dis[v] + 1)///Find allow ARC {flag = true;                PRE[V] = u;                CUR[U] = ID;                Aug[v] = min (Aug[u], F[ID].W);                U = V;            Break }} if (FlaG = = False) {if (--gap[dis[u] = = 0) break;///gap optimization, the hierarchy tree appears the fault is the end algorithm Mindis = n;            Cur[u] = Head[u];                for (id = head[u]; id =-1; id = f[id].next) {v = f[id].v;                    if (f[id].w > 0 && dis[v] < Mindis) {Mindis = Dis[v]; CUR[U] = ID;            Modify the current arc while modifying the label}} Dis[u] = Mindis + 1;            gap[dis[u]]++; if (U = s) u = pre[u]; Backtrack continues to look for allow arcs}} return max_flow;}  Char MAP1[MAXN][MAXN], map2[maxn][maxn];int VIS[MAXN][MAXN];d ouble dist (int x1, int y1, int x2, int y2) {Double A = x1,    b = y1, c = x2, d = y2; return sqrt ((a-c) * (a-c) + (b-d) * (b-d));}    int main () {int case = 1;    int D;    int K;    CIN >>K;        while (k--) {scanf ("%d%d", &n, &d);        Init ();        memset (Vis, 0, sizeof (VIS));       for (int i = 0; i < n; i++) cin >>map1[i]; for (int j = 0; J < N; j + +) Cin >>map2[j];        int len = strlen (map1[0]);        int k = 0;        for (int i = 0, i < n; i++) for (int j = 0; J < Len; j + +) if (map1[i][j]-' 0 ' > 0) vis[i][j] = ++k;        int S = 0;        int T = 2*k+1;        int en = t+1; for (int i = 0, i < n; i++) {for (int j = 0; J < Len; J + +) {if (map1[i][j                    -' 0 ' > 0} {Add (Vis[i][j], vis[i][j]+k, map1[i][j]-' 0 ');                        for (int II = 0, ii < n; ii++) {for (int JJ = 0; JJ < Len; jj++)                            {if (i = = II && j = = JJ) continue;                            Double s = Dist (i, J, II, JJ);                        if (VIS[II][JJ] && (double) d >= s) Add (Vis[i][j]+k, VIS[II][JJ], INF-10); }}}}} int KK = 0; for (int i = 0, i < n; i++) {for (int j = 0; J < Len; J + +) {if (map2[i][j                    ] = = ' L ') {kk++;                Add (S, Vis[i][j], 1); }}} for (int i = 0, i < n; i++) for (int j = 0; J < Len; j + +) if (        map1[i][j]-' 0 ' > 0) if (i+1<=d | | j+1<=d | | n-i<=d | | len-j<=d) Add (Vis[i][j]+k, T, INF-10);        int ans = SAP (S, T, en);        cout<< "Case #" <<Case++<< ":"; if (Kk-ans = = 0) cout<< "No lizard is left behind."        <<endl; else if (Kk-ans = = 1) cout<< "1 lizard is left behind."        <<endl; else cout<<kk-ans<< "lizards were left behind."    <<endl; } 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.