贪心算法:先排序,再枚举最小带宽(B),每次更新当前最小花费(P)和以及答案(ans)

#include <cstdio>
#include <algorithm>
using namespace std; struct data {int b,p;} a[][];
int m[],B[]; bool cmp(const data &A,const data &B) {
if(A.b==B.b)return A.p > B.p;
return A.b < B.b;
} int main() {
int t,n;
for(scanf("%d",&t);t--;) {
scanf("%d",&n);
int i_B=;
for(int i=; i<=n; i++) {
scanf("%d",&m[i]);
for(int j=; j<=m[i]; j++) {
scanf("%d%d",&a[i][j].b,&a[i][j].p);
B[++i_B]=a[i][j].b;
}
sort(a[i]+,a[i]+m[i]+,cmp);
}
sort(B+,B+i_B+);
double ans=;bool flag;
for(int i=; i<=i_B; i++) { //枚举B的值
if(B[i]==B[i+] && i<i_B) continue;//剪枝
int sum_p=,min_p;
for(int j=; j<=n; j++) {
flag=true,min_p=;
for(int k=; k<=m[j]; k++)
if(a[j][k].b>=B[i] && a[j][k].p<min_p)
min_p=a[j][k].p,flag=false;
if(flag) break;
sum_p+=min_p;
}
if(flag) break;
ans=max(ans,(double)B[i]/sum_p);
}
printf("%.3f\n",ans);
}
return ;
}

C++-POJ1018-Communication System的更多相关文章

  1. POJ1018 Communication System

      Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26738   Accepted: 9546 Description We ...

  2. Communication System(dp)

    Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25006 Accepted: 8925 ...

  3. poj 1018 Communication System

    点击打开链接 Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21007   Acc ...

  4. poj 1018 Communication System 枚举 VS 贪心

    Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21631   Accepted:  ...

  5. POJ 1018 Communication System(贪心)

    Description We have received an order from Pizoor Communications Inc. for a special communication sy ...

  6. F - Communication System

    We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...

  7. POJ 1018 Communication System (动态规划)

    We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...

  8. POJ 1018 Communication System(树形DP)

    Description We have received an order from Pizoor Communications Inc. for a special communication sy ...

  9. poj 1018 Communication System (枚举)

    Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 22380   Accepted:  ...

  10. Communication System(动态规划)

    个人心得:百度推荐的简单DP题,自己做了下发现真得水,看了题解发现他们的思维真得比我好太多太多, 这是一段漫长的锻炼路呀. 关于这道题,我最开始用DP的思路,找子状态,发现自己根本就不会找DP状态数组 ...

随机推荐

  1. C# WPF Bing地图展示

    微信公众号:Dotnet9,网站:Dotnet9,问题或建议,请网站留言: 如果您觉得Dotnet9对您有帮助,欢迎赞赏 内容目录 实现效果 业务场景 编码实现 本文参考 源码下载 1.实现效果 Bi ...

  2. ng-简介

    Angular 是什么 Angular(读音['æŋgjʊlə])是一套用于构建用户界面的 JavaScript 框架.由 Google 开发和维护,主要被用来开发单页面应用程序. 类似于 Vue.j ...

  3. Python、Django、Celery中文文档分享

    1.Python:链接:https://pan.baidu.com/s/12uzxbI-nMkpF7aMa966bTQ 密码:i1x9 2.Django:链接:https://pan.baidu.co ...

  4. P3759 [TJOI2017]不勤劳的图书管理员 [树套树]

    树套树是什么啊我不知道/dk 我只知道卡常数w // by Isaunoya #pragma GCC optimize(2) #pragma GCC optimize(3) #pragma GCC o ...

  5. 网站后门shell-----eval

    我们先来看看网站被攻击的代码: <?php error_reporting(E_ERROR); unlink('user.php'); unlink('../member/login.php') ...

  6. gulp常用插件之gulp-postcss使用

    更多gulp常用插件使用请访问:gulp常用插件汇总 ** gulp-postcss**这是一款通过多个插件通过管道传递CSS,但是仅解析一次CSS. 更多使用文档请点击访问gulp-postcss工 ...

  7. KiKi's K-Number HDU - 2852 树状数组+二分

    #include<iostream> #include<cstring> using namespace std; ; int tr[N]; int lowbit(int x) ...

  8. Java基于SSM在线学习系统设计与实现

                 Spring+SpringMVC+MyBatis+Bootstrap+Vue开发在线学习系统 本课题的主要内容是开发基于Java EE的在线学习平台,使用MVC经典开发模式. ...

  9. WPF实现高仿统计标题卡

    飘哇~~~,在家数瓜子仁儿,闲来无事,看东看西,也找点儿,最近正在看看WPF动画,光看也是不行,需要带着目的去学习,整合知识碎片,恰巧,看到Github中一个基于Ant Designer设计风格的后台 ...

  10. 第三章:使用ListView展示数据

    一.ImageList:存储图像集合 Images 存储的所有图像 ImageSize 图像的大小 ColorDepth 颜色数 TransparentColor 被视为透明的颜色 先设置ColorD ...