贪心算法:先排序,再枚举最小带宽(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. Win10桌面菜单弹出cmd解决办法

    现象 Win10右键菜单打开弹出命令提示符 原有个性化.显示设置.网络和Internet设置无法使用 解决 注册表定位到HKEY_CURRENT_USER\Software\Classes\ ms-s ...

  2. ZooKeeper启动报错:My id 3 not in the peer list

    错误描述: 解决方法:查看zookeeper-3.4.2/conf目录下 编辑zoo.cfg文件 发现第三行有问题修改

  3. numpy包学习笔记

    导入 import numpy as np argsort() numpy中的排序函数 返回的是数组中从小到大的索引值 from numpy import * test=[5,2,3,4,1] pri ...

  4. Maven修改test/rsource的output folder报错Test source folder 'src/test/java'... is not also used for main s

    eclipse新建maven项目时候,只出来三个文件夹,然后大都督手动添加了缺失的src/test/resource 的文件夹,最后想修改一下 Output folder的路径为 (原来是     d ...

  5. Hdu1042 N! (阶乘高精度模板)

    Problem Description Given an integer N(0 ≤ N ≤ 10000), your task is to calculate N!   Input One N in ...

  6. dva-loading 实践用法

    dva 中页面过渡效果封装的很好,下面介绍常用的两个 js 库. 之前对 dva-loading 理解存在误区,认为只要在 index.js 中配置一下就没事了,事实上 dva-loading 只是提 ...

  7. Codeforces 1304E. 1-Trees and Queries 代码(LCA 树上两点距离判奇偶)

    https://codeforces.com/contest/1304/problem/E #include<bits/stdc++.h> using namespace std; typ ...

  8. POI导出PPT

    1.null <!-- https://mvnrepository.com/artifact/org.apache.poi/poi --> <dependency> <g ...

  9. python 3 可迭代对象与迭代器

    1,可迭代对象 内部含有__iter__方法的对象是可迭代对象 遵循可迭代协议 dir() 检查对象含有什么方法 dir()会返回一个列表,这个列表中含有该对象的以字符串的形式所有方法名.这样我们就可 ...

  10. 155.XSS攻击原理

    XSS攻击: XSS(Cross Site Script)攻击叫做跨站脚本攻击,他的原理是用户使用具有XSS漏洞的网站的时候,向这个网站提交一些恶意代码,当用户在访问这个网站的某个页面的时候,这个恶意 ...