zoukankan      html  css  js  c++  java
  • 【UVALive

    Description

    The mobile network market in country XYZ used to be dominated by two large corporations, XYZ
    Telecom and XYZ Mobile. The central government recently has realized that radio frequency spectrum
    is a scarce resource and wants to regulate its usage. The spectrum currently in use is divided into
    300,000 channels. Any wireless service provider who wishes to use certain spectrum should apply for
    licenses on these channels. While some services may require use of multiple channels, a single channel
    can not be shared by different services.
    The central government wants to maximize its revenue from the spectrum by putting the channels
    up to an auction. The only two bidders are XYZ Telecom and XYZ Mobile. They are allowed to place
    bids on combinations of channels, through which their services can communicate with the customers.
    Furthermore, the government stipulates that a company can only place at most one bid on a specific
    channel.
    The government can only accept a subset of the bids so none of them would conflict with each
    other. However, officials soon find out that it is a difficult task to determine the winning bids in order
    to maximize the revenue, and they are asking for your help.


    Input
    Standard input will contain multiple test cases. The first line of the input is a single integer T (1 ≤
    T ≤ 10) which is the number of test cases. T test cases follow, each preceded by a single blank line.
    Each test case has two bid description sections, which are for XYZ Telecom and XYZ Mobile,
    respectively. Each section starts with an integer N (1 ≤ N ≤ 3, 000), which is the number of bids that
    follow. The next N lines each contain the description for one bid, the first integer P (1 ≤ P ≤ 1, 000)
    gives the price of that bid, followed by the channel numbers required by this service. A service would
    require at least 1 channel and at most 32 channels. Each channel number is a positive integer and will
    never exceed 300,000.


    Output
    Results should be directed to standard output. Start each case with ‘Case #:’ on a single line, where
    # is the case number starting from 1. Two consecutive cases should be separated by a single blank
    line. No blank line should be produced after the last test case.
    For each test case, print the maximized revenue the government is able to collect by issuing licenses
    on the channels.


    Sample Input

    2
    3
    45 1
    51 2
    62 3
    4
    54 1
    15 2
    33 3
    2 4 5
    5
    20 1
    18 2
    23 4
    54 3 5 6
    17 7
    4
    36 1 2 3
    28 5
    47 4 7
    16 6


    Sample Output
    Case 1:
    169
    Case 2:
    139

    【题意】

      有两家公司都想向政府申请某些资源的使用权,并且他们都提供了一些申请列表,列表中含有申请费用和资源种类,同一家公司的申请列表之间不含有重复的资源。政府只可以完整地接受和拒绝谋一份申请列表,问政府的最大收益是多少。

    【分析】

      对于一组,新建一个点连源点(或汇点),流量为费用,再连向组内的全部点(流量为INF),最后跑一遍最小割即可。

    代码如下:

      1 #include<cstdio>
      2 #include<cstdlib>
      3 #include<cstring>
      4 #include<iostream>
      5 #include<algorithm>
      6 #include<queue>
      7 using namespace std;
      8 #define INF 0xfffffff
      9 #define Maxn 600010
     10 
     11 int st,ed;
     12 struct node
     13 {
     14     int x,y,f,o,next;
     15 }t[Maxn*2];int len;
     16 
     17 int first[Maxn],dis[Maxn],sum;
     18 
     19 int mymin(int x,int y) {return x<y?x:y;}
     20 
     21 void ins(int x,int y,int f)
     22 {
     23     t[++len].x=x;t[len].y=y;t[len].f=f;
     24     t[len].next=first[x];first[x]=len;t[len].o=len+1;
     25     t[++len].x=y;t[len].y=x;t[len].f=0;
     26     t[len].next=first[y];first[y]=len;t[len].o=len-1;
     27 }
     28 
     29 void init()
     30 {
     31     len=0;
     32     memset(first,0,sizeof(first));
     33     st=300001;ed=st+1;sum=0;
     34     int x,now=ed;
     35     char cc;
     36     scanf("%d",&x);getchar();
     37     while(x--)
     38     {
     39         int c,y;
     40         scanf("%d",&c);getchar();
     41         ins(st,++now,c);sum+=c;
     42         while(scanf("%d%c",&y,&cc))
     43         {
     44             ins(now,y,INF);
     45             if(cc=='
    ') break;
     46         }
     47     }
     48     scanf("%d",&x);getchar();
     49     while(x--)
     50     {
     51         int c,y;
     52         scanf("%d",&c);getchar();
     53         ins(++now,ed,c);sum+=c;
     54         while(scanf("%d%c",&y,&cc))
     55         {
     56             ins(y,now,INF);
     57             if(cc=='
    ') break;
     58         }
     59     }
     60 }
     61 
     62 queue<int > q;
     63 bool bfs()
     64 {
     65     while(!q.empty()) q.pop();
     66     memset(dis,-1,sizeof(dis));
     67     q.push(st);dis[st]=0;
     68     while(!q.empty())
     69     {
     70         int x=q.front();q.pop();
     71         for(int i=first[x];i;i=t[i].next) if(t[i].f>0)
     72         {
     73             int y=t[i].y;
     74             if(dis[y]==-1)
     75             {
     76                 dis[y]=dis[x]+1;
     77                 q.push(y);
     78             }
     79         }
     80     }
     81     if(dis[ed]==-1) return 0;
     82     return 1;
     83 }
     84 
     85 int ffind(int x,int flow)
     86 {
     87     if(x==ed) return flow;
     88     int now=0;
     89     for(int i=first[x];i;i=t[i].next) if(t[i].f>0)
     90     {
     91         int y=t[i].y;
     92         if(dis[y]==dis[x]+1)
     93         {
     94             int a=ffind(y,mymin(flow-now,t[i].f));
     95             now+=a;
     96             t[i].f-=a;
     97             t[t[i].o].f+=a;
     98         }
     99     }
    100     if(now==0) dis[x]=0;
    101     return now;
    102 }
    103 
    104 void max_flow()
    105 {
    106     int ans=0;
    107     while(bfs())
    108     {
    109         ans+=ffind(st,INF);
    110     }
    111     printf("%d
    ",sum-ans);
    112 }
    113 
    114 int main()
    115 {
    116     int T,kase=0;
    117     scanf("%d",&T);
    118     while(T--)
    119     {
    120         init();
    121         printf("Case %d:
    ",++kase);
    122         max_flow();
    123         if(T) printf("
    ");
    124     }
    125     return 0;
    126 }
    [LA3487]

      最后一行输出空行报WA也是坑死了。

    2016-05-27 13:22:21

  • 相关阅读:
    css
    js
    css3
    css
    深浅拷贝
    index-数据结构/算法
    es6知识点
    在vscode中配置sass savepath
    计算机基础
    element-ui使用后手记
  • 原文地址:https://www.cnblogs.com/Konjakmoyu/p/5534304.html
Copyright © 2011-2022 走看看