【贪心】Communication System POJ 1018
来源:互联网 发布:java中二分法查找 编辑:程序博客网 时间:2024/06/05 22:34
题目链接:http://poj.org/problem?id=1018
题目大意:有n种通讯设备,每种有mi个制造商,bi、pi分别是带宽和价格。在每种设备中选一个制造商让最小带宽B与总价格P的比值B/P最大。
解法是枚举最小带宽B,每种设备在带宽大于B的制造商中找价格最小的,最后取比值最大的。
详见代码:
#include<cstdio>#include<cmath>#include<cstring>#include<algorithm>using namespace std;int n,m,d[105][105],p[105][105],Min,Max,t;int main(){scanf("%d",&t);while(t--){memset(d,0,sizeof d);memset(p,0,sizeof p);Min=0xffff;Max=0;scanf("%d",&n);for(int i=1;i<=n;i++){scanf("%d",&d[i][0]);for(int j=1;j<=d[i][0];j++){scanf("%d%d",&d[i][j],&p[i][j]);Max=Max<d[i][j]?d[i][j]:Max;Min=Min>d[i][j]?d[i][j]:Min;}}double ans=0;for(int i=Min;i<=Max;i++){int sum=0;for(int j=1;j<=n;j++){int mx=0xffff;for(int k=1;k<=d[j][0];k++)if(d[j][k]>=i&&mx>p[j][k])mx=p[j][k];sum+=mx;}if(ans<i*1.0/sum) ans=i*1.0/sum;}printf("%.3lf\n",ans);}}
阅读全文
1 0
- 【贪心】Communication System POJ 1018
- poj 1018 Communication System(枚举+贪心)
- POJ 1018 Communication System 贪心+枚举
- poj 1018 Communication System 枚举 VS 贪心
- poj 1018 Communication System (枚举+贪心)
- POJ 1018 Communication System (枚举+贪心)
- poj 1018 Communication System 【动态规划】||【贪心】
- poj 1018 Communication System (dp | 贪心)
- 【POJ 1018】Communication System(dp|贪心)
- POJ 1018 Communication System(贪心+优化)
- 1018 Communication System - 贪心
- POJ 1018 Communication System(搜索/贪心/动归)
- poj 1018 Communication System
- POJ 1018 Communication System
- poj 1018 Communication System
- POJ 1018 Communication System
- POJ 1018 Communication System
- POJ 1018 Communication System
- poj 3253 Fence Repair(优先队列)
- Android实现固定比例的ImageView
- 微信支付开发demo文件是干什么的简单说明
- KMP算法
- 数据挖掘RapidMiner工具使用----决策树案例分析
- 【贪心】Communication System POJ 1018
- 认识Docker(vmware+centos7+docker)
- Java之for循环优化方式-
- InputStream与OutputStream的使用例子
- liuxn防火墙
- java学习篇1-Java开发环境
- 前端学习(四)node核心模块url
- BZOJ1060 [ZJOI2007]时态同步
- springboot如何使用Freemarker模版引擎