HDU 5045 Contest (cost stream), hdu5045

Source: Internet
Author: User

HDU 5045 Contest (cost stream), hdu5045

Address: HDU 5045

Finally, I used network stream A in the competition... I used so many network streams once .. Although the question is very simple, I still want to remember it...

My idea for this question is to find m/n charge streams, and calculate the maximum charge flow for the same round for every n of them. Creating a graph is simple. It is the simplest Binary Graph Model.

The Code is as follows:

#include <iostream>#include <cstdio>#include <string>#include <cstring>#include <stdlib.h>#include <math.h>#include <ctype.h>#include <queue>#include <map>#include <set>#include <algorithm>using namespace std;#define LL __int64using namespace std;double mp[20][2000], d[200], cost;const int INF=0x3f3f3f3f;int head[200], source, sink, cnt, flow;int f[200], cur[200], vis[200];struct node{    int u, v, cap, next;    double cost;} edge[100000];void add(int u, int v, int cap, double cost){    edge[cnt].v=v;    edge[cnt].cap=cap;    edge[cnt].cost=cost;    edge[cnt].next=head[u];    head[u]=cnt++;    edge[cnt].v=u;    edge[cnt].cap=0;    edge[cnt].cost=-cost;    edge[cnt].next=head[v];    head[v]=cnt++;}int spfa(){    int i;    for(i=0; i<200; i++)        d[i]=INF;    memset(vis,0,sizeof(vis));    cur[source]=-1;    f[source]=INF;    d[source]=0;    queue<int>q;    q.push(source);    while(!q.empty())    {        int u=q.front();        q.pop();        vis[u]=0;        for(i=head[u]; i!=-1; i=edge[i].next)        {            int v=edge[i].v;            if(d[v]>d[u]+edge[i].cost&&edge[i].cap)            {                d[v]=d[u]+edge[i].cost;                f[v]=min(f[u],edge[i].cap);                cur[v]=i;                if(!vis[v])                {                    vis[v]=1;                    q.push(v);                }            }        }    }    if(d[sink]==INF) return 0;    flow+=f[sink];    cost-=f[sink]*d[sink];    for(i=cur[sink]; i!=-1; i=cur[edge[i^1].v])    {        edge[i].cap-=f[sink];        edge[i^1].cap+=f[sink];    }    return 1;}void mcmf(){    cost=flow=0;    while(spfa()) ;}int main(){    int t, num=0, i, j, k, n, m;    double sum;    scanf("%d",&t);    while(t--)    {        sum=0;        num++;        scanf("%d%d",&n,&m);        for(i=1; i<=n; i++)        {            for(j=1; j<=m; j++)            {                scanf("%lf",&mp[i][j]);            }        }        k=1;        sum=0;        while(k<=m)        {            source=0;            sink=2*n+1;            memset(head,-1,sizeof(head));            cnt=0;            for(i=k; i<k+n&&i<=m; i++)            {                add(i-k+1+n,sink,1,0);                for(j=1; j<=n; j++)                {                    add(j,i-k+1+n,1,-mp[j][i]);                }            }            for(i=1; i<=n; i++)                add(source,i,1,0);            mcmf();            sum+=cost;            //printf("%.2lf    %d\n",sum, k);            k+=n;        }        printf("Case #%d: %.5lf\n",num,sum);    }    return 0;}



Calculate the distance between two points. Question: http: // acmhdueducn/diy/contest_showproblemphp? Pid = 1002 & cid = 12905 & hide = 0

If you submit c ++, submit it to gcc or c.

Acm problem http: // acmhdueducn/contests/contest_showproblemphp? Pid = 1009 & cid = 389 hangdian, what's the idea?

It seems that you can create a vertical line of three edges first. After obtaining the center point, each edge and the center point form three triangles. The three triangles correspond to the three corners of the center vertex to obtain the maximum approximate number, divide by 360 by the maximum common divisor, which is the number of positive polygon edges of the Minimum side. We hope you can achieve this.

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.