【二分+最小树形图】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
写这题各种犯逗,简直感动不能多说。
- #include<cstdio>
- #include<algorithm>
- #include<cstring>
- using namespace std;
- const int maxn=,maxm=1e4+;
- struct edge{
- int v,u,b,c;
- bool operator<(const edge&a)
- const{return b<a.b;}
- }E[maxm],e[maxm];
- int in[maxn],pre[maxn],vis[maxn],id[maxn];
- int N,M,C;
- int work(int n,int m,int lim){
- memcpy(e,E,sizeof(e));
- long long ret=;
- int root=;
- if(!lim) lim=;
- while(){
- memset(in,,sizeof(in));
- int inf=in[];
- for(int i=lim;i<=m;i++){
- int u=e[i].u,v=e[i].v;
- if(u!=v&&e[i].c<in[v]){
- in[v]=e[i].c;
- pre[v]=u;
- }
- }
- for(int i=;i<=n;i++)
- if(i!=root&&in[i]==inf) return ;
- in[root]=;
- int cnt=;
- memset(id,,sizeof(id));
- memset(vis,,sizeof(vis));
- for(int i=;i<=n;i++){
- ret+=in[i];
- if(!vis[i]){
- int u=i;
- while(u!=root&&!vis[u]){
- vis[u]=i;
- u=pre[u];
- }
- if(vis[u]==i){
- ++cnt;
- int v=u;
- do{
- id[v]=cnt;
- v=pre[v];
- }while(v!=u);
- }
- }
- }
- if(!cnt) break;
- for(int i=;i<=n;i++)
- if(!id[i]) id[i]=++cnt;
- for(int i=lim;i<=m;i++){
- int v=e[i].v;
- e[i].u=id[e[i].u];
- e[i].v=id[e[i].v];
- if(e[i].u!=e[i].v)
- e[i].c-=in[v];
- }
- n=cnt;
- root=id[root];
- }
- if(ret<=C) return ;
- return ;
- }
- int main(){
- int T;
- scanf("%d",&T);
- while(T--){
- scanf("%d%d%d",&N,&M,&C);
- for(int i=;i<=M;i++){
- scanf("%d%d%d%d",&E[i].u,&E[i].v,&E[i].b,&E[i].c);
- E[i].u++,E[i].v++;
- }
- sort(E+,E+M+);
- int l=,r=M;
- while(l<r){
- int mid=(l+r+)>>;
- if(work(N,M,mid)) l=mid;
- else r=mid-;
- }
- if(!l) printf("streaming not possible.\n");
- else printf("%d kbps\n",E[l].b);
- }
- return ;
- }
【二分+最小树形图】UVA11865 比赛网络的更多相关文章
- UVA 11865 Stream My Contest (二分+最小树形图)
题意:给定一个网络,一个服务器,其他的是客户机,有 m 条连线,每条有一个带宽和花费(单向边),让你用不超过 c 的花费,使得 0 到 所有的机器都能到达,并且使得最小带宽最大. 析:很明显是二分题, ...
- 【UVA 11865】 Stream My Contest (二分+MDST最小树形图)
[题意] 你需要花费不超过cost元来搭建一个比赛网络.网络中有n台机器,编号0~n-1,其中机器0为服务器,其他机器为客户机.一共有m条可以使用的网线,其中第i条网线的发送端是机器ui,接收端是机器 ...
- HDU 4966 GGS-DDU(最小树形图)
n个技能,每个技能有0-a[i]的等级,m个课程,每个课程需要前置技能c[i]至少达到lv1[i]等级,效果是技能d[i]达到lv2[i]等级,花费w[i]. 输出最小花费使得全技能满级(初始全技能0 ...
- UVA 11865 Stream My Contest(最小树形图)
题意:N台机器,M条有向边,总资金C,现要到搭建一个以0号机(服务器)为跟的网路,已知每条网线可以把数据从u传递到v,其带宽为d,花费为c,且d越大,传输速度越快,问能够搭建的传输速度最快的网络d值是 ...
- POJ 3164 Command Network ( 最小树形图 朱刘算法)
题目链接 Description After a long lasting war on words, a war on arms finally breaks out between littlek ...
- 最小树形图(poj3164)
Command Network Time Limit: 1000MS Memory Limit: 131072K Total Submissions: 12834 Accepted: 3718 ...
- bzoj4349: 最小树形图
最小树形图模板题…… 这种\(O(nm)\)的东西真的能考到么…… #include <bits/stdc++.h> #define N 60 #define INF 1000000000 ...
- hdu 4966 GGS-DDU (最小树形图)
比较好的讲解:http://blog.csdn.net/wsniyufang/article/details/6747392 view code//首先为除根之外的每个点选定一条入边,这条入边一定要是 ...
- hdu3072 强连通+最小树形图
题意:有一个人他要把一个消息通知到所有人,已知一些通知关系:A 能通知 B,需要花费 v,而又知道,如果某一个小团体,其中的成员相互都能直接或间接通知到,那么他们之间的消息传递是不需要花费的,现在问这 ...
随机推荐
- python 内置标准库socketserver模块的思考
socketserver模块简化了编写网络服务器的任务, 在很大程度上封装了一些操作, 你可以看成是事件驱动型的设计, 这很不错.它定义了两个最基本的类--服务器类 BaseServer, 请求处理类 ...
- Form 和 Input 对象
更改表单的 action 属性 <html> <head> <script type="text/javascript"> function c ...
- Java编程语言下Selenium 利用Robot自己编写截屏方法
import java.awt.Robot; import java.awt.event.KeyEvent; import java.util.concurrent.TimeUnit; import ...
- git merge 与 git rebase
git merge git rebase merge V.S. rebase 参考材料 写在开始: 对merge和rebase的用法总有疑惑,好像两个都能完成"获取别的branch的comm ...
- Android两级导航菜单栏的实现--FragmentTabHost结合ViewPager与Android 开源项目PagerSlidingTabStrip
http://www.cnblogs.com/aademeng/articles/6119737.html 转载注:简单总结一下,外层Tab用TabHost,类层Tab用Viepager+Framen ...
- Flipping Parentheses~Gym 100803G
Description A string consisting only of parentheses '(' and ')' is called balanced if it is one of t ...
- Python 30分钟入门指南
Python 30分钟入门指南 为什么 OIer 要学 Python? Python 语言特性简洁明了,使用 Python 写测试数据生成器和对拍器,比编写 C++ 事半功倍. Python 学习成本 ...
- 安装vmware tool时出错
背景: 我想要在win10系统和vmware的ubuntu之间实现磁盘共享,从而实现文件共享.百度到可以通过安装vmware tools实现,所以着手安装vmware tools 问题: 安装vmwa ...
- php数据导出excel
/** * 导出数据为excel表格 *@param $data 一个二维数组,结构如同从数据库查出来的数组 *@param $title excel的第一行标题,一个数组,如果为空则没有标题 *@p ...
- PHP中的 $_SERVER 函数说明详解
用php在开发软件的时候,我们经常用到 $_SERVER[]这个函数,今天就来讲下这个数组的值,方便以后使用: A: $_SERVER['ARGC'] #包含传递给程序的 命令行参数的个数(如果运行在 ...