贪心算法:先排序,再枚举最小带宽(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. 使用faker 生成测试数据

    测试数据生成 faker基础使用 from faker import Faker f=Faker(locale='zh_CN') print(f.name()) address 地址 person 人 ...

  2. C++中的IO类(iostream, fstream, stringstream)小结(转)

    原文地址:https://blog.csdn.net/stpeace/article/details/44763009

  3. LVM实现将2块磁盘总空间“合二为一”并挂载到同一目录

    需求场景 将MySQL主机的2块18T的数据盘空间全部"合并"后挂载到/mysql_data目录下,要求文件系统格式化为xfs:已有关键信息梳理如下: 需要挂载的数据盘 /dev/ ...

  4. Networking POJ - 1287 最小生成树板子题

    #include<iostream> #include<algorithm> using namespace std; const int N=1e5; struct edge ...

  5. 杭电oj 1087——super jump!jump!jump(java实现)

    question:Super Jumping! Jumping! Jumping! 意思就是找一串数字中的和最大子串 思路:创建另一个数组,每一项是路径数组对应项之前最大子串的和,然后遍历此数组找出最 ...

  6. loj6277 数列分块入门题1

    裸题分块. #include <bits/stdc++.h> using namespace std; ],b[],n,m,t1,t2,t3,t4,sq; int main(){ ios: ...

  7. 销量下跌、质量问题不断,小鹏G3“维权门”之后的日子不好过

    编辑 | 于斌 出品 | 于见(ID:mpyujian) 小鹏汽车何时能站上国内新能源汽车行业C位?这是于见之前提出过的问题.随着上个月小鹏汽车终于发布了2020款小鹏G3,从该款产品的用户反馈及销量 ...

  8. 立即关机C++源码

    #include<windows.h> using namespace std; int main(){ system("shutdown /p"); return 0 ...

  9. Python自定义任务发邮件提醒

    前言 在工作中,有时会有一些定期需要执行的任务或在将来某一天需要执行的任务,为避免疏漏,设计个小工具,发邮件提醒自己去处理. 方案简介 1.建立一个Excel文件,里面定义好待提醒的任务 2.建立一个 ...

  10. javascript入门(1)

    目录 Javascript认识(1) JavaScript 常见事宜 JavaScript介绍 Javascript内容 Javascript书写位置 变量 变量是什么 变量的命名规则 变量提升 数据 ...