【贪心】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: ...
随机推荐
- 18 Ajax、Json以及jackson框架解析json的基本应用
1. Ajax (1)概念:ASynchronous JavaScript And XML 异步的JavaScript 和 XML 异步和同步:客户端和服务器端相互通信的基础上 * 客户端必须等待服务 ...
- c++模板使用及常见问题
一.为什么使用模板?? 使用模板的目的是为了避免重复声明和定义一系列基本功能相同的函数或者类,其区别因传入参数的不同而产生不同类型的数据,其基本工作过程都是一致的! 二.调用模板函数产生不明确问题 ( ...
- Javascript获取JSON对象长度
- POJ 1661 Help Jimmy(C)动态规划
没刷过 POJ,这题是论坛有人问的,我才看看. 我发现 POJ 注册很奇怪,账号总是登不上去,弄的我还注册两个.Emmm 首次体验很差,还好我不在 POJ 刷题. 题目链接:POJ 1661 Help ...
- ArcGIS JS 使用Proxy之 Printing Tools unable to connect to mapServer
ArcGIS JS使用Proxy.ashx将地图服务隐藏,并在微博服务器端增加了地图服务权限判断. Proxy.ashx做了如下设置, <serverUrl url="http://l ...
- Redis Streams与Spark的完美结合
来源:Redislabs 作者:Roshan Kumar 翻译:Kevin (公众号:中间件小哥) 最近,我有幸在 Spark +AI 峰会上发表了题目为“Redis + Structured St ...
- java.lang.SecurityManager、java.security包
学习java大概3年多了,一直没有好好研究过java安全相关的问题,总是会看到 SecurityManger sm = System.getSecurityManager(); if(sm!=null ...
- unbuntu 16.04 MS-Celeb-1M + alexnet + pytorch
最近被保研的事情搞的头大,拖了半天才勉强算结束这个了.从熟悉unbantu 16.04的环境(搭个翻墙的梯子都搞了一上午 呸!)到搭建python,pytorch环境.然后花了一个上午熟悉py的基本语 ...
- java框架学习系列
这篇文章的目的主要是作为一个框架学习的索引,方便查找及顺序学习 一.struts2学习 1. java之struts框架入门教程 2. java之struts2的执行流程讲解 3. java之stru ...
- docker 执行 docker system prune 导致Azure Devops build镜像失败
运行docker的centos上, 只分配了16G的空间, 装了个mysql, 还有个rancher, 就只剩下2G的空间了, Azure Devops build镜像就出错了, 显示存储空间不足, ...