Bzoj 3232: Enclosure Game "score plan + min cut"

Source: Internet
Author: User

Array opening small causes tttttle ...
is the fractional plan, set SM for all lattice values and, after two out of mid, with the smallest cut to judge, that is, Judge Sm-dinic () >=0
This minimum cut is more like a maximum-weight closed sub-graph, the map is s like all points of the point even flow for the lattice value of the edge (equivalent to the maximum right of the closed sub-graph in the positive point), and then consider the edge, two adjacent to the lattice, if a selection of the middle of this side has a negative contribution, so two adjacent lattice between two edge right for mid * Edge of the right side, note is two, to connect with each other, and then all the points on the border as the edge of the edge of the mid* edge of the border, equivalent to pretend to have a layer of points all marked as T, and then run the minimum cut judgment can be

#include <iostream> #include <cstdio> #include <cstring> #include <queue>using namespace std; const int N=105;const double eps=1e-6,inf=1e9;int n,m,h[n*n],cnt,s,t,id[n][n],tot,le[n*n];d ouble a[n][n],b[n][n],c[n    ][n],sm;struct qwe{int ne,to; Double VA;}    e[n*n*n];void Add (int u,int v,double W) {cnt++;    E[cnt].ne=h[u];    E[cnt].to=v;    E[cnt].va=w; h[u]=cnt;}    void ins (int u,int v,double W) {Add (u,v,w); Add (v,u,0);}    BOOL BFs () {queue<int>q;    memset (le,0,sizeof (le));    Le[s]=1;    Q.push (s);        while (!q.empty ()) {int U=q.front ();        Q.pop (); for (int i=h[u];i;i=e[i].ne) if (e[i].va>eps&&!le[e[i].to]) {Le[e[i].to]=le                [U]+1;            Q.push (e[i].to); }} return le[t];} Double dfs (int u,double f) {if (u==t| |!    f) return F;    Double us=0;   for (int i=h[u];i&&us<f;i=e[i].ne) if (e[i].va>eps&&le[e[i].to]==le[u]+1) {         Double T=dfs (E[i].to,min (e[i].va,f-us));            e[i].va-=t;            e[i^1].va+=t;        us+=t;    } if (us<eps) le[u]=0; return us;}    int Dinic () {double re=0;    while (BFS ())) Re+=dfs (S,inf); return re;}    BOOL OK (double W) {memset (h,0,sizeof (h));    cnt=1,s=0,t=n*m+1;    for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) ins (s,id[i][j],a[i][j]);    for (int j=1;j<=m;j++) ins (id[1][j],t,w*b[0][j]), INS (Id[n][j],t,w*b[n][j]);    for (int i=1;i<=n;i++) ins (id[i][1],t,w*c[i][0]), INS (id[i][m],t,w*c[i][m]); for (int i=1;i<n;i++) for (int j=1;j<=m;j++) Add (Id[i][j],id[i+1][j],w*b[i][j]), add (Id[i+1][j],id[i]    [J],w*b[i][j]); for (int i=1;i<=n;i++) for (int j=1;j<m;j++) Add (Id[i][j],id[i][j+1],w*c[i][j]), add (Id[i][j+1],id[i]    [J],w*c[i][j]); Return sm-dinic () >eps;}    int main () {scanf ("%d%d", &n,&m); for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) scanf ("%lf", &a[i][j]), id[i][j]=++tot,sm+=a[i][j];    for (int. i=0;i<=n;i++) for (int j=1;j<=m;j++) scanf ("%lf", &b[i][j]);    for (int. i=1;i<=n;i++) for (int j=0;j<=m;j++) scanf ("%lf", &c[i][j]);    Double l=0,r=n*m*100,ans=0;        while (r-l>1e-5) {double mid= (l+r)/2;        if (OK (mid)) L=mid,ans=mid;    else R=mid;    } printf ("%.3f\n", ans); return 0;}

Bzoj 3232: Enclosure Game "score plan + min cut"

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.