题目大意:题目说了一大堆,其实都是废话......让人有些不知所云,其实就是给了一些电厂,和一些消费点,然后里面有一些路线什么的,求出消费点可以最多消费的电量是多少。
输入大意:

分析:懂了题意就是一个模板。。。还不用拆点什么的,不过输入的时候不太明白为什么scanf("(%d,%d)%d")这种输入不好使了,只得用字符串直接读的。

下面是AC代码。
#include<stdio.h>
#include<string.h>
#include<queue>
#include<stack>
#include<algorithm>
#include<math.h>
using namespace std; const int MAXN = ;
const int oo = 1e9+; int G[MAXN][MAXN], layer[MAXN]; void In(char s[])
{
    scanf("%s", s);     for(int i=; s[i]; i++)
    {
        if(s[i]==',' || s[i]=='(' || s[i]==')')
            s[i] = ' ';
    }
} bool bfs(int start, int End)
{
    int used[MAXN] = {};
    queue<int> Q;Q.push(start);     memset(layer, , sizeof(layer));
    used[start] = layer[start] = ;     while(Q.size())
    {
        int u = Q.front();Q.pop();         if(u == End)return true;         for(int i=; i<=End; i++)
        {
            if(!used[i] && G[u][i])
            {
                used[i] = true;
                layer[i] = layer[u] + ;
                Q.push(i);
            }
        }
    }     return false;
}
int dfs(int u, int MaxFlow, int End)
{
    if(u == End)return MaxFlow;     int uFlow = ;     for(int i=; i<=End; i++)
    {
        if(G[u][i] && layer[u] == layer[i]-)
        {
            int flow = min(MaxFlow-uFlow, G[u][i]);
            flow = dfs(i, flow, End);
            G[u][i] -= flow;
            G[i][u] += flow;
            uFlow += flow;             if(uFlow == MaxFlow)
                break;
        }
    }     return uFlow;
}
int dinic(int start, int End)
{
    int MaxFlow = ;     while(bfs(start, End) == true)
        MaxFlow += dfs(start, oo, End);     return MaxFlow;
} int main()
{
    int N, NP, NC, M;     while(scanf("%d%d%d%d", &N, &NP, &NC, &M) != EOF)
    {
        int i, u, v, flow, start=N, End=start+;
        char s[];         memset(G, , sizeof(G));         while(M--)
        {///线路
            In(s);
            sscanf(s, "%d%d%d", &u, &v, &flow);             G[u][v] += flow;
        }         for(i=; i<=NP; i++)
        {///输入发电站,与源点相连
            In(s);
            sscanf(s, "%d%d", &u, &flow);
            G[start][u] = flow;
        }
        for(i=; i<=NC; i++)
        {///消费点,与汇点相连
            In(s);
            sscanf(s, "%d%d", &u, &flow);
            G[u][End] = flow;
        }         printf("%d\n", dinic(start, End));
    }     return ; 

}

F - Power Network - poj 1459(简单最大流)的更多相关文章

  1. F - Power Network POJ - 1459

    题目链接:https://vjudge.net/contest/299467#problem/F 这个是一个很简单的题目,但是读入很有意思,通过这个题目,我学会了一种新的读入方式. 一个旧的是(%d, ...

  2. Power Network - poj 1459 (最大流 Edmonds-Karp算法)

      Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 24788   Accepted: 12922 Description A ...

  3. Power Network (poj 1459 网络流)

    Language: Default Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Submissions: 23407   ...

  4. Power Network POJ - 1459 [网络流模板]

    http://poj.org/problem?id=1459 嗯,网络流模板...多源点多汇点的图,超级汇点连发电厂,用户连接超级汇点 Status Accepted Time 391ms Memor ...

  5. Power Network POJ - 1459 网络流 DInic 模板

    #include<cstring> #include<cstdio> #define FOR(i,f_start,f_end) for(int i=f_startl;i< ...

  6. Poj(1459),最大流,EK算法

    题目链接:http://poj.org/problem?id=1459 Power Network Time Limit: 2000MS   Memory Limit: 32768K Total Su ...

  7. POJ 2135 简单费用流

    题意:       题意是一个人他要从牧场1走到牧场n然后在走回来,每条路径只走一次,问全程的最短路径是多少. 思路:        这个题目挺简单的吧,首先要保证每条边只能走一次,然后还要要求费用最 ...

  8. POJ 1459 Power Network / HIT 1228 Power Network / UVAlive 2760 Power Network / ZOJ 1734 Power Network / FZU 1161 (网络流,最大流)

    POJ 1459 Power Network / HIT 1228 Power Network / UVAlive 2760 Power Network / ZOJ 1734 Power Networ ...

  9. 2018.07.06 POJ 1459 Power Network(多源多汇最大流)

    Power Network Time Limit: 2000MS Memory Limit: 32768K Description A power network consists of nodes ...

随机推荐

  1. python-Pickle序列化

    [Python之旅]第三篇(二):Pickle序列化   python 序列化 pickle 摘要: 说明:关于Pickle的说明     作如下说明: 1 2 3 4 5 6 7 序列化的概念很简单 ...

  2. JS HTML 单引号与双引号

    JS中,单引号和双引号其实没啥区别,看你自己习惯了. 但若双引号中再使用双引号,我们可采取"外双内单"或者"外单内双"的格式,当然如果需要的是双引号本身,则只能 ...

  3. Sublime Text插件之Emmet

    转载:http://www.w3cplus.com/tools/using-emmet-speed-front-end-web-development.html Emmet插件以前被称作为Zen Co ...

  4. Oracle11G 数据库 expdp、impdp使用示例

    expdp 备份数据库.expdp/impdp简单测试 操作系统层面创建目录 [root@Oracle11g ~]# mkdir -p /home/oracle/db_back/ 修改目录的所属用户. ...

  5. 2.常用快捷键.md

    [toc] 1.mian函数补全 在IntelJ中和Eclipse中稍有不同,在Eclipse中,输入main再按Alt+/即可自动补全main函数,但是在IntellJ中则是输入psvm,选中即可 ...

  6. Specified VM install not found: type Standard VM, name jdk1.6.0_05

    重装系统换了jdk,之前jdk用的1.6,现在改成1.7了.但是更新之后发现ant打包用不了了,报错 Specified VM install not found: type Standard VM, ...

  7. win7设置虚拟wifi

    1. cmd,使用管理员权限打开: 2. 设置:netsh wlan set hostednetwork mode=allow ssid=ABCD key=12345678 mode:是否开启虚拟wi ...

  8. 清除div浮动的三种方式

    html: <body> <div class="main"> <div class="first"></div> ...

  9. php 随机显示据今天30天内的任意一天

    function randomDate() { //echo date( "Y-m-d H:m:s", $newtime); //echo date("Y-m-d H:m ...

  10. spring获取properties

    实际项目中,通常将一些可配置的定制信息放到属性文件中(如数据库连接信息,邮件发送配置信息等),便于统一配置管理.例中将需配置的属性信息放在属性文件/WEB-INF/configInfo.propert ...