POJ 3308 paratroopers min cut min. right cover

Source: Internet
Author: User
Tags log log

Title Link: http://poj.org/problem?id=3308

Test instructions

There is a m*n diagram with paratroopers on some of the points above.

You can set some guns on each row or column, and by shooting, this row or the paratroopers of this column will be wiped out. The setup of each gun has a cost, if multiple guns are set, then the cost is to set the product of each gun.

Ask how much the minimum cost is to eliminate all paratroopers.

Ideas:

At least the paratroopers at each point will be wiped out with that column or the gun set in that line, so you can apply a point-covered model. Think of a paratrooper as an edge, and the edge must be at least one point to cover.

The final cost of the topic is the product of all the costs, so it can be converted with log log (x) +log (y) = log (x*y).

So you can use the minimum point weight coverage model to solve.

Set a super source point S and Super sink point T.

S has an edge to each line, and the capacity is log (the cost of the gun is set on these lines).

Each column is connected to the T with an edge, and the capacity is log (the cost of the gun is set in these columns).

For each paratrooper location (x, y), the x is connected to Y with an edge and the capacity is INF.

Then the minimum cut is asked. The answer is exp (maximum flow).

To pay attention to the problem of accuracy, esp open 1e-8, because 4 decimal places reserved. When using g++, double precision is%f, and double precision is%lf when using C + +.

1 //#include <bits/stdc++.h>2#include <iostream>3#include <cstring>4#include <cstdio>5#include <cmath>6#include <queue>7#include <vector>8 using namespacestd;9 structEdgeTen { One     int  from, to;Doublecap, flow; AEdge (intFintTDoubleCDoubleFL) -     { -          from= f; to = t; Cap = C; Flow =FL; the     } - }; - #defineMAXN 110 - #defineINF 100000 + #defineEPS 1e-8 - intN, m, S, T; +Vector <Edge>edges; AVector <int>G[MAXN]; at intD[MAXN], CUR[MAXN], VIS[MAXN]; - voidAddedge (int  from,intTo,Doublecap) - { -Edges.push_back (Edge ( from, to, Cap,0)); -Edges.push_back (Edge to, from,0,0)); -m =edges.size (); ing[ from].push_back (M-2); -G[to].push_back (M-1); to } + BOOLBFS () - { thememset (Vis,0,sizeof(Vis)); *D[s] =0; Vis[s] =1; $Queue <int>Q; Q.push (s);Panax Notoginseng      while(!q.empty ()) -     { the         intx =Q.front (); Q.pop (); +          for(inti =0; I < g[x].size (); i++) A         { theEdge &e =Edges[g[x][i]]; +             if(!vis[e.to] && e.cap >E.flow) -             { $D[e.to] = D[x] +1; $Vis[e.to] =1; - Q.push (e.to); -             } the         } -     }Wuyi     returnVis[t]; the } - DoubleDfsintXDoublea) Wu { -     if(x = = T | | fabs (a) < EPS)returnA; About     DoubleFlow =0, F; $      for(int&i = Cur[x]; I < g[x].size (); i++) -     { -Edge &e =Edges[g[x][i]]; -         if(d[e.to] = = D[x] +1&& (f = dfs (e.to, Min (A, e.cap-e.flow))) >0) A         { +E.flow + =F; theedges[g[x][i]^1].flow-=F; -Flow + =F; $A-=F; the             if(Fabs (a) < EPS) Break; the         } the     } the     returnflow; - } in DoubleMaxflow () the { the     DoubleFlow =0; About      while(BFS ()) the     { thememset (cur,0,sizeof(cur)); theFlow + =DFS (s, INF); +     }  -     returnflow; the }Bayi intT, M, N, L; the intMain () the { -     //freopen ("In.txt", "R", stdin); -     //freopen ("OUT.txt", "w", stdout); thescanf"%d", &T); the      while(t--) the     { thescanf"%d%d%d", &m, &n, &L); - edges.clear (); thes =0; t = n+m+1; n = n+m+2; the          for(inti = s; I <= t; i++) g[i].clear (); the         DoubleVal;94          for(inti =1; I <= M; i++) the         { thescanf"%LF", &val); the Addedge (S, I, log (val));98         } About          for(inti =1; I <= N; i++) -         {101scanf"%LF", &val);102Addedge (i+M, T, log (val));103         }104          for(inti =1; I <= L; i++) the         {106             intA, B; scanf"%d%d", &a, &b);107Addedge (A, B +M, INF);108         }109         DoubleFlow =Maxflow (); theprintf"%.4lf\n", exp (flow));111     } the     return 0;113}

POJ 3308 paratroopers min cut min. right cover

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.