【贪心】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: ...
随机推荐
- windows10 ubuntu子系统运行docker出现的问题
前一篇笔记记录了安装的过程及错误处理办法,但是在正式使用docker时,却又出现新的问题: “docker: Cannot connect to the Docker daemon at unix:/ ...
- linux shell 获取文件夹全文绝对路径
在ls中列出文件的绝对路径 ls | sed "s:^:`pwd`/:" # 就是在每行记录的开头加上当前路径 ps: #在所有行之前/后加入某个字符串 sed 's/^/stri ...
- python基础 — 文件操作
读取键盘输入 Python提供了两个内置函数从标准输入读入一行文本,默认的标准输入是键盘.如下: raw_input input raw_input函数 raw_input([prompt]) 函数从 ...
- L2R 一:基础知识介绍
一.背景 l2r可以说是搜索推荐里面很常用的知识了,一直处于一知半解的地步,今天开个博客准备把这些零散的东西系统性整理好,一版就粗糙点了. 二.粗概 前段时间的项目主要和搜索引擎相关,记录下搜索引擎的 ...
- python 操作redis集群
一.连接redis集群 python的redis库是不支持集群操作的,推荐库:redis-py-cluster,一直在维护.还有一个rediscluster库,看GitHub上已经很久没更新了. 安装 ...
- Jenkins + GitLab + SpringBoot 实现持续集成脚本
Linux脚本 #!/bin/bash jar_name=hq-api.jar cd /usr/local/app/hq-api echo "Stopping SpringBoot Appl ...
- Java泛型 - 返回父类的子类
一.栗子 public class GenericityInher { //error: Type mismatch: cannot convert from ArrayList<Child&g ...
- ④ Python3.0字符串
字符串无论是python或者其他语言,是最常用的数据类型之一: 这儿注意在python中可以通过使用引号( ' 或 " )来创建字符串.使用三引号('''或""" ...
- python3基础之“函数(1)”
1.type:查看当前字符串的类型 c=' print(type(c),c) b= int(c) print(type(b),b) num=" a=int(num,base=16) prin ...
- 【cookie的使用】&【Session】
明确一点: cookie由服务器创建Cookie cookie=new Cookie("haha","xixi") 通过HtttpServletR ...