HDU 2732 Leapin ' lizards (split + max Stream)

Source: Internet
Author: User

HDU 2732 Leapin ' lizards

Topic links

Test instructions: There are some lizards in a maze, there is a jumping force to indicate how far to jump to the pillars, and then each pillar up to a certain number of hops, to find out how many of these lizards can not escape anyway.

Idea: The pillar to build a map to run the maximum flow can be, or quite obvious

Code:

#include <cstdio> #include <cstring> #include <cmath> #include <queue> #include <algorithm >using namespace Std;const int maxnode = 805;const int MAXEDGE = 500005;typedef int type;const Type INF = 0x3f3f3f3f;st ruct Edge {int u, v; Type cap, Flow; Edge () {}edge (int u, int v, type cap, type flow) {This->u = U;this->v = V;this->cap = Cap;this->flow = flow;} };struct dinic {int n, m, S, t; Edge edges[maxedge];int first[maxnode];int Next[maxedge];bool Vis[maxnode]; Type d[maxnode];int cur[maxnode];vector<int> cut;void init (int n) {this->n = N;memset (First,-1, sizeof (first)) ; m = 0;} void Add_edge (int u, int v, Type cap) {Edges[m] = Edge (U, V, cap, 0); Next[m] = first[u];first[u] = M++;edges[m] = Edge (V, U, 0, 0); Next[m] = first[v];first[v] = m++;} BOOL BFs () {memset (Vis, false, sizeof (VIS));queue<int> Q; Q.push (s);d [s] = 0;vis[s] = True;while (! Q.empty ()) {int u = q.front (); Q.pop (); for (int i = first[u]; I! = 1; i = Next[i]) {edge& e = edges[I];if (!VIS[E.V] && e.cap > E.flow) {vis[e.v] = true;d[e.v] = D[u] + 1; Q.push (E.V);}}} return vis[t];} Type DFS (int u, Type a) {if (U = = T | | a = = 0) return A;  Type flow = 0, f;for (int &i = Cur[u]; i = 1; i = Next[i]) {edge& e = edges[i];if (D[u] + 1 = d[e.v] && (f = DFS (e.v, Min (A, e.cap-e.flow))) > 0) {e.flow + = F;edges[i^1].flow = F;flow + F;a = f;if (A = = 0) break;} return flow;} Type maxflow (int s, int t) {this->s = s; this->t = t; Type flow = 0;while (BFS ()) {for (int i = 0; i < n; i++) Cur[i] = First[i];flow + = DFS (s, INF);} return flow;} void Mincut () {cut.clear (); for (int i = 0; i < m; i + = 2) {if (vis[edges[i].u] &&!vis[edges[i].v]) Cut.push_bac K (i);}}} gao;const int N = 25;int T, n, m;double D;char str[n];int main () {int cas = 0;scanf ("%d", &t), while (t--) {scanf ("%d%l F ", &n, &d); Gao.init (n * * 2 + 2); int s = n * * 2, t = n * * 2 + 1;for (int i = 0; i < n; i++) {scanf ( "%s", str); m = strlen (str); for (iNT J = 0; J < M; J + +) {if (str[j]! = ' 0 ') Gao.add_edge (i * m + j, I * m + j + N * m, Str[j]-' 0 '); if (i-d < 0 | | i + d >= N | | J- D < 0 | | J + D >= m) Gao.add_edge (i * m + j + N * m, T, INF);}}  int tot = 0;for (int i = 0; i < n; i++) {scanf ("%s", str), M = strlen (str), for (int j = 0; J < m; J + +) {if (str[j] = = ' L ') {Tot++;gao.add_edge (S, I * m + j, 1);}} for (int i = 0, i < n; i++) {for (int j = 0; J < m; J + +) {for (int x = 0; x < n; + +) {for (int y = 0; y < m;  y++) {int dx = i-x;int dy = j-y;double dis = sqrt (DX * DX * 1.0 + dy * dy); if (Dis > D) continue;gao.add_edge (I * m + j + N * m, x * m + y, INF);}}}} printf ("Case #%d:", ++cas); int ans = Tot-gao. Maxflow (S, t), if (ans = = 0) printf ("no"), Else printf ("%d", ans), if (ans <= 1) printf ("Lizard was"), Else printf ("Liza RDS were ");p rintf (" left behind.\n ");} return 0;}


HDU 2732 Leapin ' lizards (split + 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.