• BZOJ 1497: [NOI2006]最大获利( 最大流 )


    下午到周六早上是期末考试...但是我还是坚守在机房....要挂的节奏啊....

    这道题就是网络流 , 建图后就最大流跑啊跑啊跑...

    -------------------------------------------------------------------------

    #include<cstdio>
    #include<cstring>
    #include<algorithm>
    #include<iostream>
     
    #define rep( i , n ) for( int i = 0 ; i < n ; ++i )
    #define Rep( i , n ) for( int i = 1 ; i <= n ; ++i )
    #define clr( x , c ) memset( x , c , sizeof( x ) )
     
    using namespace std;
     
    const int INF = 0x7fffffff;
    const int maxn = 55000 + 5;
     
    struct edge {
    int to , cap;
    edge *next , *rev;
    };
     
    edge* pt;
    edge* head[ maxn ];
    edge EDGE[ 400000 ];
     
    void init() {
    pt = EDGE;
    clr( head , 0 );
    }
     
    inline void add( int u , int v , int d ) {
    pt -> to = v;
    pt -> cap = d;
    pt -> next = head[ u ];
    head[ u ] = pt++;
     
    inline void add_edge( int u , int v , int d ) {
    add( u , v , d );
    add( v , u , 0 );
    head[ u ] -> rev = head[ v ];
    head[ v ] -> rev = head[ u ];
    }
     
    int cnt[ maxn ] , h[ maxn ];
    edge *p[ maxn ] , *cur[ maxn ];
     
    int maxFlow( int S , int T , int N ) {
    clr( cnt , 0 );
    cnt[ 0 ] = N;
    clr( h , 0 );
    int flow = 0 , A = INF , x = S;
    edge* e;
    while( h[ S ] < N ) {
    for( e = cur[ x ] ; e ; e = e -> next ) 
       if( e -> cap > 0 && h[ e -> to ] + 1 == h[ x ] ) break;
       
    if( e ) {
    p[ e -> to ] = cur[ x ] = e;
    A = min( A , e -> cap );
    x = e -> to;
    if( x == T ) {
    while( x != S ) {
       p[ x ] -> cap -= A;
       p[ x ] ->rev -> cap += A;
       x = p[ x ] -> rev -> to;
    }
    flow += A;
    A = INF;
    }
    } else {
    if( ! --cnt[ h[ x ] ] ) break;
    h[ x ] = N;
    for( e = head[ x ] ; e ; e = e -> next )
       if( h[ x ] > h[ e -> to ] + 1 && e -> cap > 0 ) {
        h[ x ] = h[ e -> to ] + 1;
        cur[ x ] = e;
       }
       
    cnt[ h[ x ] ]++;
    if( x != S ) x = p[ x ] -> rev -> to;
    }
    }
    return flow;
    }
     
    int main() {
    init();
    int n , m;
    cin >> n >> m;
    int s = 0 , t = n + m + 1;
    Rep( i , n ) {
    int v;
    scanf( "%d" , &v );
    add_edge( s , i , v );
    }
    int ans = 0;
    Rep( i , m ) {
    int a , b , v;
    scanf( "%d%d%d" , &a , &b , &v );
    ans += v;
    add_edge( a , i + n , INF );
    add_edge( b , i + n , INF );
    add_edge( i + n , t , v );
    }
    cout << ans - maxFlow( s , t , t + 1 ) << " ";
    return 0;
    }

    ------------------------------------------------------------------------- 

    1497: [NOI2006]最大获利

    Time Limit: 5 Sec  Memory Limit: 64 MB
    Submit: 3006  Solved: 1471
    [Submit][Status][Discuss]

    Description

    新的技术正冲击着手机通讯市场,对于各大运营商来说,这既是机遇,更是挑战。THU集团旗下的CS&T通讯公司在新一代通讯技术血战的前夜,需要做太多的准备工作,仅就站址选择一项,就需要完成前期市场研究、站址勘测、最优化等项目。在前期市场调查和站址勘测之后,公司得到了一共N个可以作为通讯信号中转站的地址,而由于这些地址的地理位置差异,在不同的地方建造通讯中转站需要投入的成本也是不一样的,所幸在前期调查之后这些都是已知数据:建立第i个通讯中转站需要的成本为Pi(1≤i≤N)。另外公司调查得出了所有期望中的用户群,一共M个。关于第i个用户群的信息概括为Ai, Bi和Ci:这些用户会使用中转站Ai和中转站Bi进行通讯,公司可以获益Ci。(1≤i≤M, 1≤Ai, Bi≤N) THU集团的CS&T公司可以有选择的建立一些中转站(投入成本),为一些用户提供服务并获得收益(获益之和)。那么如何选择最终建立的中转站才能让公司的净获利最大呢?(净获利 = 获益之和 - 投入成本之和)

    Input

    输入文件中第一行有两个正整数N和M 。第二行中有N个整数描述每一个通讯中转站的建立成本,依次为P1, P2, …, PN 。以下M行,第(i + 2)行的三个数Ai, Bi和Ci描述第i个用户群的信息。所有变量的含义可以参见题目描述。

    Output

    你的程序只要向输出文件输出一个整数,表示公司可以得到的最大净获利。

    Sample Input

    5 5
    1 2 3 4 5
    1 2 3
    2 3 4
    1 3 3
    1 4 2
    4 5 3

    Sample Output

    4

    HINT

    【样例说明】选择建立1、2、3号中转站,则需要投入成本6,获利为10,因此得到最大收益4。【评分方法】本题没有部分分,你的程序的输出只有和我们的答案完全一致才能获得满分,否则不得分。【数据规模和约定】 80%的数据中:N≤200,M≤1 000。 100%的数据中:N≤5 000,M≤50 000,0≤Ci≤100,0≤Pi≤100。

    Source

  • 相关阅读:
    MATLAB accumarray
    函数rand,randn,randi
    bsxfun
    sub2ind函数
    MAX
    & 和 &&
    matlab函数int2str, num2str, str2num
    ASCII对照表
    STM32的ADC配置
    单节锂电池基本知识
  • 原文地址:https://www.cnblogs.com/JSZX11556/p/4534309.html
Copyright © 2020-2023  润新知