【贪心】Communication System POJ 1018
题目链接: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);
}
}
【贪心】Communication System POJ 1018的更多相关文章
- poj 1018 Communication System 枚举 VS 贪心
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21631 Accepted: ...
- POJ 1018 Communication System(贪心)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- POJ 1018 Communication System(树形DP)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- poj 1018 Communication System
点击打开链接 Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21007 Acc ...
- POJ 1018 Communication System (动态规划)
We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...
- poj 1018 Communication System (枚举)
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22380 Accepted: ...
- poj 1018(枚举+贪心)
通讯系统 We have received an o ...
- Communication System(dp)
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25006 Accepted: 8925 ...
- 2017ecjtu-summer training #11 POJ 1018
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 29218 Accepted: ...
随机推荐
- Prometheus入门到放弃(3)之Grafana展示监控数据
grafana我们这里采用docker方式部署 1.下载镜像 镜像官网地址:https://hub.docker.com/r/grafana/grafana/tags [root@prometheus ...
- MySQL必知必会3
创建和操纵表 创建表 输入 CREATE TABLE customers ( cust_id int NOT NULL AUTO_INCREMENT, cust_name char(50) NOT N ...
- 路由Routers
路由Routers 对于视图集ViewSet,我们除了可以自己手动指明请求方式与动作action之间的对应关系外,还可以使用Routers来帮助我们快速实现路由信息. REST framework提供 ...
- homebrew 使用代理
ALL_PROXY=socks5://127.0.0.1:1086 brew cask install aerial
- logrus 剖析之 formatter
使用 logrus 通过 formatter 来定义输出日志的格式,具体例子如下: package main import ( log "github.com/Sirupsen/logrus ...
- Java基础系列3:多线程超详细总结
该系列博文会告诉你如何从入门到进阶,一步步地学习Java基础知识,并上手进行实战,接着了解每个Java知识点背后的实现原理,更完整地了解整个Java技术体系,形成自己的知识框架. 1.线程概述 几乎所 ...
- postman调用webapi错误记录
1.webapi ,接口中header中,value 不能太长,太长会报错 结局:value中不要存太长的数据 2.如果key 中有中文,会获取不到数据 , 解决:需要把中文转码,然后后端解码 3.如 ...
- 基于工作组消息队列高可用&msmq-wcf故障
场景: msmq 1# server故障手工切换到2# server,msmq-wcf service宿主服务重启后,无法成功读取消息,状似service不工作.无法监听到数据传输. 解决过程: 反复 ...
- vue + element ui开发过程中需要注意的几个点
1.实现动态的数据双向绑定 关键字[$set]在这个需求开发的过程中还遇到深度克隆的问题 2:form表单的动态字段验证 关键字[promise.all] 3:动态表单验证关键字[el-form-it ...
- [C#]DataTable转string[]
来源:https://zhidao.baidu.com/question/1754089856824824548.html string[] ary = Array.ConvertAll<Dat ...