zoukankan      html  css  js  c++  java
  • 【二分+最小树形图】UVA11865 比赛网络

    Description

    During 2009 and 2010 ICPC world finals, the contest was webcasted via world wide web. Seeing this, some contest organizers from Ajobdesh decided that, they will provide a live stream of their contests to every university in Ajobdesh. The organizers have decided that, they will provide best possible service to them. But there are two problems: 1. There is no existing network between universities. So, they need to build a new network. However, the maximum amount they can spend on building the network is C. 2. Each link in the network has a bandwidth. If, the stream’s bandwidth exceeds any of the link’s available bandwidth, the viewers, connected through that link can’t view the stream. Due to the protocols used for streaming, a viewer can receive stream from exactly one other user (or the server, where the contest is organized). That is, if you have two 128kbps links, you won’t get 256kbps bandwidth, although, if you have a stream of 128kbps, you can stream to any number of users at that bandwidth. Given C, you have to maximize the minimum bandwidth to any user.

    Solution

    二分最小带宽,求最小树形图看是否超过C。

    Code

    写这题各种犯逗,简直感动不能多说。

     1 #include<cstdio>
     2 #include<algorithm>
     3 #include<cstring>
     4 using namespace std;
     5 const int maxn=65,maxm=1e4+5;
     6 
     7 struct edge{
     8     int v,u,b,c;
     9     bool operator<(const edge&a)
    10         const{return b<a.b;}
    11 }E[maxm],e[maxm];
    12 int in[maxn],pre[maxn],vis[maxn],id[maxn];
    13 int N,M,C;
    14 
    15 int work(int n,int m,int lim){
    16     memcpy(e,E,sizeof(e));
    17     long long ret=0;
    18     int root=1;
    19     if(!lim) lim=1;
    20     
    21     while(1){
    22         memset(in,127,sizeof(in));
    23         int inf=in[0];
    24         for(int i=lim;i<=m;i++){
    25             int u=e[i].u,v=e[i].v;
    26             if(u!=v&&e[i].c<in[v]){
    27                 in[v]=e[i].c;
    28                 pre[v]=u;
    29             }
    30         }
    31         for(int i=1;i<=n;i++)
    32             if(i!=root&&in[i]==inf) return 0;
    33             
    34         in[root]=0;
    35         int cnt=0;
    36         memset(id,0,sizeof(id));
    37         memset(vis,0,sizeof(vis));
    38         for(int i=1;i<=n;i++){
    39             ret+=in[i];
    40             if(!vis[i]){
    41                 int u=i;
    42                 while(u!=root&&!vis[u]){
    43                     vis[u]=i;
    44                     u=pre[u];
    45                 }
    46                 if(vis[u]==i){
    47                     ++cnt;
    48                     int v=u;
    49                     do{
    50                         id[v]=cnt;
    51                         v=pre[v];
    52                     }while(v!=u);
    53                 }
    54             }
    55         }
    56         
    57         if(!cnt) break;
    58         for(int i=1;i<=n;i++)
    59             if(!id[i]) id[i]=++cnt;
    60         for(int i=lim;i<=m;i++){
    61             int v=e[i].v;
    62             e[i].u=id[e[i].u];
    63             e[i].v=id[e[i].v];
    64             if(e[i].u!=e[i].v)
    65                 e[i].c-=in[v];
    66         }
    67         n=cnt;
    68         root=id[root];
    69     }
    70     if(ret<=C) return 1;
    71     return 0;
    72 }
    73 
    74 int main(){
    75     int T;
    76     scanf("%d",&T);
    77     
    78     while(T--){
    79     scanf("%d%d%d",&N,&M,&C);
    80     for(int i=1;i<=M;i++){
    81         scanf("%d%d%d%d",&E[i].u,&E[i].v,&E[i].b,&E[i].c);
    82         E[i].u++,E[i].v++;
    83     }
    84     sort(E+1,E+M+1);
    85     
    86     int l=0,r=M;
    87     while(l<r){
    88         int mid=(l+r+1)>>1;
    89         if(work(N,M,mid)) l=mid;
    90         else r=mid-1;
    91     }
    92     
    93     if(!l) printf("streaming not possible.
    ");
    94     else printf("%d kbps
    ",E[l].b);
    95     }
    96     return 0;
    97 }
  • 相关阅读:
    装箱与拆箱,数组 糖不苦
    产生乱码的原因 糖不苦
    jQuery 库中的 $() 是什么? 糖不苦
    什么是jQuery 糖不苦
    ATM管理系统 糖不苦
    JS事件委托中同一个标签执行不同操作
    js实现36进制
    js+php+mysql实现的学生成绩管理系统
    两数之和
    函数防抖
  • 原文地址:https://www.cnblogs.com/xkui/p/4566820.html
Copyright © 2011-2022 走看看