通讯系统
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. 表单校验插件(bootstrap-validator)

    表单校验插件(bootstrap-validator) 参考文档 http://blog.csdn.net/nazhidao/article/details/51542508 http://blog. ...

  2. List 练习

    (List)已知有一个Worker 类如下: public class Worker { private int age; private String name; private double sa ...

  3. response.getWriter().write()乱码问题

    前台代码: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> & ...

  4. 安卓Java读取SD卡文本文件

    在进行序列识别时,需要对多个模式串进行识别,需要对多行浮点数进行读取,并进行解析. 所以使用的方法为: 使用文本多行读取的方式:对每行文本进行正则表达式匹配:再进行字符转换. 代码如下:        ...

  5. Higher-Order Functions and Lambdas

    https://kotlinlang.org/docs/reference/lambdas.html

  6. C# 判断字符串是否左包含

    //测试字符串 左包含 //string str = "AAABBBCCC"; //char[] ss = str.ToArray(); //0-8 字符数组 //char[] s ...

  7. commons.dbutils 的使用列子

    c0p3的导入请参考前文 https://www.cnblogs.com/appium/p/10183016.html JdbcUtils: package cn.itcast.jdbc; impor ...

  8. codevs 2602 最短路径问题——良心题解

    2602 最短路径问题 时间限制: 1 s 空间限制: 32000 KB 题目等级 : 黄金 Gold 题解 题目描述 Description 平面上有n个点(n<=100),每个点的坐标均在- ...

  9. python-flask-1

    https://askubuntu.com/questions/244641/how-to-set-up-and-use-a-virtual-python-environment-in-ubuntu ...

  10. RMAN主要命令 show,list,crosscheck,delete详解

    Oracle RMAN 的 show,list,crosscheck,delete命令整理  Oracle RMAN 的 show,list,crosscheck,delete命令整理 1.SHOW命 ...