通讯系统
We have received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices. For each device, we are free to choose from several manufacturers. Same devices from two manufacturers differ in their maximum bandwidths and prices.
By overall bandwidth (B) we mean the minimum of the
bandwidths of the chosen devices in the communication system and the
total price (P) is the sum of the prices of all chosen devices. Our goal
is to choose a manufacturer for each device to maximize B/P.

Input

The first line of the input file contains a single integer t (1 ≤
t ≤ 10), the number of test cases, followed by the input data for each
test case. Each test case starts with a line containing a single integer
n (1 ≤ n ≤ 100), the number of devices in the communication system,
followed by n lines in the following format: the i-th line (1 ≤ i ≤ n)
starts with mi (1 ≤ mi ≤ 100), the number of manufacturers for the i-th
device, followed by mi pairs of positive integers in the same line, each
indicating the bandwidth and the price of the device respectively,
corresponding to a manufacturer.

Output

Your program should produce a single line for each test case
containing a single number which is the maximum possible B/P for the
test case. Round the numbers in the output to 3 digits after decimal
point.

Sample Input

1 3
3 100 25 150 35 80 25
2 120 80 155 40
2 100 100 120 110
题意:系统需要n件设备,每件设备可以有m个厂家生产,但宽度个价格会存在差别,现在每种设备都需要一个,
题意要求的是满足(B/P)max最大的情况下选出这n件设备,
B为这n件设备的最小宽度,P为花费的价格 我们在这所有设被备从小到大枚举设备的宽度,找出它对应的最小的价格,最后区最大的q/p;
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<cstdlib>
#include<string>
#define eps 0.000000001
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const int N=+;
double Max(double a,double b){
return a>b?a:b;
}
int B[N][N],P[N][N];
int a[N];
int f(int t,int n){
for(int i=;i<=n;i++)
for(int j=;j<=a[i];j++)
if(B[i][j]==t)return ;
return ;
}
int main(){
int t,n; scanf("%d",&t);
while(t--){
int minn=0x3f3f3f3f;
int maxx=-0x3f3f3f3f;
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
for(int j=;j<=a[i];j++){scanf("%d%d",&B[i][j],&P[i][j]);
minn=min(B[i][j],minn);
maxx=max(B[i][j],maxx);
}
}
// cout<<minn<<" "<<maxx<<endl;
double ans=0.0;
for(int i=minn;i<=maxx;i++){
if(f(i,n)==)continue;
int sum=;
for(int j=;j<=n;j++){
int t=0x3f3f3f3f;
for(int k=;k<=a[j];k++){
if(B[j][k]>=i)t=min(t,P[j][k]);
}
sum=sum+t;
}
//cout<<i<<" "<<sum<<endl;
ans=Max(ans,(double)i/sum);
}
printf("%.3f\n",ans);
}
}

poj 1018(枚举+贪心)的更多相关文章

  1. D. Diverse Garland Codeforces Round #535 (Div. 3) 暴力枚举+贪心

    D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. POJ 1018 Communication System(树形DP)

    Description We have received an order from Pizoor Communications Inc. for a special communication sy ...

  3. 51nod1625(枚举&贪心)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625 题意:中文题诶- 思路:枚举+贪心 一开始写的行和列同时 ...

  4. 枚举+贪心 HDOJ 4932 Miaomiao's Geometry

    题目传送门 /* 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则 ...

  5. POJ 1018 Communication System 贪心+枚举

    看题传送门:http://poj.org/problem?id=1018 题目大意: 某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m个厂家提供生产,而每个厂家生产的同种设备都 ...

  6. poj 1018 Communication System 枚举 VS 贪心

    Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21631   Accepted:  ...

  7. POJ 1018 【枚举+剪枝】.cpp

    题意: 给出n个工厂的产品参数带宽b和价格p,在这n个工厂里分别选1件产品共n件,使B/P最小,其中B表示n件产品中最小的b值,P表示n件产品p值的和. 输入 iCase n 表示iCase个样例n个 ...

  8. 【贪心】Communication System POJ 1018

    题目链接:http://poj.org/problem?id=1018 题目大意:有n种通讯设备,每种有mi个制造商,bi.pi分别是带宽和价格.在每种设备中选一个制造商让最小带宽B与总价格P的比值B ...

  9. poj -- 1042 Gone Fishing(枚举+贪心)

    题意: John现有h个小时的空闲时间,他打算去钓鱼.钓鱼的地方共有n个湖,所有的湖沿着一条单向路顺序排列(John每在一个湖钓完鱼后,他只能走到下一个湖继续钓),John必须从1号湖开始钓起,但是他 ...

随机推荐

  1. 6月10遇到的bug

    3.遇到的BUG        1.@Service(version = "1.0.0", interfaceClass = TransactionItemService.clas ...

  2. HTTPS的中那些加密算法

    密码学在计算机科学中使用非常广泛,HTTPS就是建立在密码学基础之上的一种安全的通信协议.HTTPS早在1994年由网景公司首次提出,而如今在众多互联网厂商的推广之下HTTPS已经被广泛使用在各种大小 ...

  3. 【转载】JavaScript中同名标识符优先级-Snandy

    一,局部变量先使用后声明,不影响外部同名变量 var x = 1; // --> 外部变量x function fn(){ alert(x); // --> undefined 局部变量x ...

  4. 如何在Eclipse中创建Web服务器

    使用Eclipse开发Web项目时,需要先配置Web服务器,如果已经配置好Web服务器,就不需要再重新配置了.也就是说,本节的内容不是开发每个项目时,都必须经过的步骤.创建Web服务器的具体步骤如下: ...

  5. SSIS 无法在 unicode 和非 unicode 字符串数据类型之间转换

    最近在学SSIS,遇到一个问题,把平面文件源的数据导入到EXCEL中. 平面文件源的对象是CSV,读进来的PhoneNumber是 DT_STR 然后倒入Excel 对应列建立的是longtext 一 ...

  6. 折纸---珠穆朗玛问题----简单for 循环

    一张纸的厚度大约是0.08mm,对折多少次之后能达到珠穆朗玛峰的高度(8848.13米)? package com.zuoye.test; public class Zhezhi { public s ...

  7. WinXP SSH连接不上虚拟机的解决方法

    问题现象描述: 在VMWare中安装好linux系统后,选择桥接,从宿主机Windows上使用Putty, SSH Secure Shell等客户端工具连接linux上的ssh服务,客户端一直没有反应 ...

  8. SLAM: 单目视觉SLAM的方案分类《机器人手册》

    摘抄知乎上一段有趣的话:     如果你出门问别人『学习SLAM需要哪些基础?』之类的问题,一定会有很热心的大哥大姐过来摸摸你的头,肩或者腰(不重要),一脸神秘地从怀里拿出一本比馒头还厚的<Mu ...

  9. CVPR2015深度学习回顾

    原文链接:http://www.csdn.net/article/2015-08-06/2825395 本文做了少量修改,仅作转载存贮,如有疑问或版权问题,请访问原作者或告知本人. CVPR可谓计算机 ...

  10. ldap 禁止匿名登录(5)

    [root@zabbix1 ~]# cat disable_anon.ldif dn: cn=config changetype: modify add: olcDisallows olcDisall ...