贪心算法:先排序,再枚举最小带宽(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. markdown转成word或者pdf

    利用typora软件 1.登陆官网下载软件 官网地址:https://typora.io/ 点击download 根据自己的电脑下载64位或者32位 2.安装软件 安装界面如下: 3.转换 3.1首先 ...

  2. php函数的巧妙应用

    直接切入正题: 1.extract();函数从数组中把变量导入到当前的符号表中 对于数组中的每个元素,键名用于变量名,键值用于变量值. 第二个参数 type 用于指定当某个变量已经存在,而数组中又有同 ...

  3. Qt多线程实现思路二

    建立一个继承于Qobject的类myThread 在类myThread中定义线程处理函数不必是思路一里的run(); 在窗口类中开辟一个自定义线程myThread的指针对象myT = new myTh ...

  4. python3练习100题——056

    题目:画图,学用circle画圆形. 可以用turtle.circle画图. import turtle turtle.setup(0.6,0.6) turtle.pensize(3) turtle. ...

  5. appium知识点

    1 appium元素获取技巧 # 就是页面滑动 driver.swipe(x1, y1, x1, y2, t) # 拿到所有跟元素有关的标签,其实是个列表 driver.find_elements_b ...

  6. 一直报找不到function,然后又不为null。最后发现是个数组。哭死。

    今天写代码,报找不到function.然后又不为空.最后发现是类型不对.因为是数组,所以不能用node.function(),而应该用nodeArr[0].function.错用前者会找不到funct ...

  7. 22.01.Cluster

      1. 클러스터링 iris 데이터셋 확인¶ In [2]: from sklearn import cluster from sklearn import datasets iris = dat ...

  8. caffe+win10+git使用sh文件

    在windows下是否可以执行sh文件呢,搜了一下,可以安装了git就可以执行,当然这不是唯一答案. 然后联想到caffe下有一些.sh文件可以尝试,就用create_mnist.sh尝试把. cre ...

  9. php Allowed memory size of 134217728 bytes exhausted

    报错:PHP Fatal error: Allowed memory size of 134217728 bytes exhausted (tried to allocate 72 bytes) in ...

  10. 文本中自动出现的 &#8203

    文本中自动出现的 &#8203   所借鉴原页面地址:https://blog.csdn.net/judyc/article/details/53097142 因判断容器内字符长度来做其它处理 ...