通讯系统
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. php获取当地时间 time zone

      PHP5.2.4之前的版本无需设置时区.下面是修改PHP时区的三个办法. 1.修改PHP.ini这个文件 找到date.timezone这行,去掉前面的分号,改成: Java代码 date.tim ...

  2. Java_Web之宠物管理系统

    使用JSP+servLet实现宠物管理系统,oraC1e11g作为后台数据厍,实现查看宠物和增加宠物的功能由你实现,如图: 其中宠物包栝:狗.猫.鸟.鼠 具体要求及推荐实现步骤 第一步:创建数据库代码 ...

  3. 创建dml触发器

    -实现删除学生信息时把该学生的成绩记录全部清空 --判断触发器是否存在 if exists(select * from sysobjects where name = 'delete_student' ...

  4. python3设置打开文件的编码

    f = open(file_path,'r',encoding='utf8') 用起来很方便,不需要先读取再转码了.

  5. C++对象的内存模型

    1. 普通对象模型 对象是如何在内存中布局的? 成员 存放位置 访问范围 非静态数据成员 每一个对象体内 为该对象专有 静态数据成员 程序的静态存储区内,只有一份实体 为该类所有对象共享 成员函数(静 ...

  6. Fish:Linux中比bash或zsh更好用的Shell

    Fish是一个智能且用户友好的命令行shell,适用于macOS,Linux和其他家族.fish包含语法突出显示.根据你键入字符自动提示autosuggest-as-type和花式选项卡完成等功能,无 ...

  7. 整理Webview加载缓慢的解决方案

    1.https://www.cnblogs.com/xinye/p/3144139.html 2.https://www.jianshu.com/p/95d4d73be3d1

  8. BZOJ 1715: [Usaco2006 Dec]Wormholes 虫洞 DFS版SPFA判负环

    Description John在他的农场中闲逛时发现了许多虫洞.虫洞可以看作一条十分奇特的有向边,并可以使你返回到过去的一个时刻(相对你进入虫洞之前).John的每个农场有M条小路(无向边)连接着N ...

  9. Testbench文件编写纪要(Verilog)

    之前在使用Verilog做FPGA项目中.以及其他一些不同的场合下,零散的写过一些练手性质的testbench文件,开始几次写的时候,每次都会因为一些基本的东西没记住.写的很不熟练,后面写的时候稍微熟 ...

  10. PAT_A1138#Postorder Traversal

    Source: PAT A1138 Postorder Traversal (25 分) Description: Suppose that all the keys in a binary tree ...