Bzoj 3232: Enclosure game __ Score Planning

Source: Internet
Author: User

Learned the knowledge of the early forgotten, will not write, but also afraid of writing wrong, decisively reproduced: Cqzhangyu
Code:

#include <cstdio> #include <cstdlib> #include <cstring> #include <iostream> using namespace std;
const double eps=1e-5;
    struct node{int x,y,next,other;
Double C;
}a[2110000];int last[3000],len=0;
int s[3000],h[3000],st,ed;
    void ins (int x,int y,double c) {int k1=++len;
    A[len].x=x;a[len].y=y;a[len].c=c;
    A[len].next=last[x];last[x]=len;
    int K2=++len;
    a[len].x=y;a[len].y=x;a[len].c=0.0;
    A[len].next=last[y];last[y]=len;
A[K1].OTHER=K2;A[K2].OTHER=K1;
    BOOL Bt_h () {memset (h,0,sizeof (h));
    int l=1,r=2;s[l]=st;h[st]=1;
        while (l!=r) {int x=s[l];
            for (int i=last[x];i;i=a[i].next) {int y=a[i].y;
        if (h[y]==0&&a[i].c>0) h[y]=h[x]+1,s[r++]=y;
    } l++;
return h[ed]!=0;
    Double Findflow (int x,double f) {if (x==ed) return F;
    Double t,ans=0.0;
        for (int i=last[x];i;i=a[i].next) {int y=a[i].y; if (h[x]+1==h[y]&&A[I].C&GT;0&AMP;&AMP;ANS&LT;F) {ans+= (T=findflow (Y,min (A[i].c,f-ans)));
        a[i].c-=t;a[a[i].other].c+=t;
    } if (ans==0) h[x]=0;
return ans;
int n,m,num=0;
int a[55][55],ys[55][55],he[55][55],sh[55][55];
    BOOL Check (double X) {memset (last,0,sizeof (last)); len=0;
    Double tot=0;
            for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) {int x=ys[i][j];
            Ins (St,x, (double) a[i][j]);
            tot+= (double) a[i][j];
            INS (X,ys[i-1][j],x*he[i][j]);
            INS (X,ys[i+1][j],x*he[i+1][j]);
            INS (X,ys[i][j-1],x*sh[i][j]);
        INS (x,ys[i][j+1],x*sh[i][j+1]);
    Double ans=0.0;
    while (Bt_h ()) Ans+=findflow (st,999999999.0);
Return tot-ans>0;
    int main () {scanf ("%d%d", &n,&m);
    for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) scanf ("%d", &a[i][j]); for (int i=1;i<=n+1;i++) for (int j=1;j<=m;j++) scanf ("%d",; he[i][j]);
    for (int i=1;i<=n;i++) for (int j=1;j<=m+1;j++) scanf ("%d", &sh[i][j]);
        for (int i=1;i<=n;i++) for (int j=1;j<=m;j++) Ys[i][j]=++num;
    St=0;ed=++num;
    for (int i=1;i<=n;i++) ys[i][0]=ys[i][m+1]=ed;
    for (int i=1;i<=m;i++) ys[0][i]=ys[n+1][i]=ed;
    Double l=0.0,r=2500000;
        while (L+eps<r) {double mid= (l+r)/2;
        if (check (mid)) L=mid;
    else R=mid;
printf ("%.3lf", L); }

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.