Communication System
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 29218   Accepted: 10408

Description

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

Sample Output

0.649

题意  气得死,该死的英语。t组测试,每次输入一个n(要买的设备总数),接下来n行每行第一个数为生产i(1<=i<=n)设备的厂家数mi,紧接着是每个厂家生产该设备的bandwidth, price;
B为所选的n个设备中bandwidth的最小值,P为所选的n个设备price的和,问你怎样才能使B/P最大,输出B/P保留三位小数。
解析 该题有很多解法,我选择了贪心,比较好想;
B的取值范围,最小值每个设备所有生产商bandwidth的最小值,最大值每个设备所有生产商bandwidth最大值的最小值(样例中就是 80<=B<=120)
枚举区间中的bandwidth,每次在每个设备所有生产商中找bandwidth>=B且price最小的,把price累加起来,最后计算出B/P与上一次枚举的结果进行比较,留下较大的那个。 AC代码
 #include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <iostream>
#include <sstream>
#include <queue>
#include <vector>
#include <algorithm>
#define maxn 105
#define inf 0x3f3f3f3f
using namespace std;
typedef long long ll;
struct node
{
double b;
double p;
};
node f[maxn][maxn];
int main(int argc, char const *argv[])
{
int t,n;
int a[maxn];
double bz[maxn*maxn];
double b[maxn];
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
memset(a,,sizeof(a));
memset(b,,sizeof(b));
memset(bz,,sizeof(bz));
int cnt1=,cnt2=;
for(int i=;i<=n;i++)
{
scanf("%d",&a[i]);
double maxb=;
for(int j=;j<=a[i];j++)
{
scanf("%lf %lf",&f[i][j].b,&f[i][j].p);
bz[cnt1++]=f[i][j].b; //把所有的b放到一个数组,之后再排序,方便枚举
maxb=max(maxb,f[i][j].b); //找出每个设备的b的最大值
}
b[cnt2++]=maxb; //存进数组排序,b[0]就是所有设备的b的最大值的最小值
}
sort(bz,bz+cnt1);
sort(b,b+cnt2);
double maxbp=;
for(int i=;bz[i]<=b[];i++) //枚举
{
double sump=;
for(int j=;j<=n;j++) //第j个设备
{
double minp=inf;
for(int k=;k<=a[j];k++) //第j个设备的第k个生产商
{
if(f[j][k].p<minp&&f[j][k].b>=bz[i]) //找出最符合条件的p值
{
minp=f[j][k].p;
}
}
sump+=minp;
}
double ans=bz[i]/sump;
if(ans>maxbp)
maxbp=ans; //每次比较,留下较大的
}
printf("%.3lf\n",maxbp);
}
return ;
}

我比较菜,程序跑的慢,700+ms,QWQ

2017ecjtu-summer training #11 POJ 1018的更多相关文章

  1. 2017ecjtu-summer training # 11 POJ 2492

    A Bug's Life Time Limit: 10000MS   Memory Limit: 65536K Total Submissions: 38280   Accepted: 12452 D ...

  2. POJ 1018 Communication System(树形DP)

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

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

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

  4. POJ 1018 Communication System(DP)

    http://poj.org/problem?id=1018 题意: 某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m1.m2.m3.....mn个厂家提供生产,而每个厂家生产 ...

  5. POJ 1018 Communication System 贪心+枚举

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

  6. 【贪心】Communication System POJ 1018

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

  7. poj 1018 Communication System

    点击打开链接 Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21007   Acc ...

  8. 2017ecjtu-summer training #7 POJ 2689

    Prime Distance Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 18731   Accepted: 5006 D ...

  9. poj 1018 Communication System_贪心

    题意:给你n个厂,每个厂有m个产品,产品有B(带宽),P(价格),现在要你求最大的 B/P 明显是枚举,当P大于一定值,B/P为零,可以用这个剪枝 #include <iostream> ...

随机推荐

  1. Python 项目实践二(下载数据)第三篇

    接着上节继续学习,在本章中,你将从网上下载数据,并对这些数据进行可视化.网上的数据多得难以置信,且大多未经过仔细检查.如果能够对这些数据进行分析,你就能发现别人没有发现的规律和关联.我们将访问并可视化 ...

  2. android测试

    1.测试是否知道源代码: --黑盒测试 不知道代码 --白盒测试 知道源代码 2.按照测试粒度: --方法测试 --单元测试 Junit测试 --集成测试 --系统测试 3.按照测试暴力程度 --冒烟 ...

  3. JS如何实现导航栏的智能浮动

    <script language="javascript">     function smartFloat(obj) {         var obj = docu ...

  4. 视觉SLAM的数学表达

    相机是在某些时刻采集数据的,所以只关心这些时刻的位置和地图. 就把这一段时间的运动变成了李三时刻 t=1,2,...K当中发生的事情. 在这些事可,x表示机器自身的位置. x1,x2,x3,x4... ...

  5. js浏览器对象navigator

    移动端通常需要判断当前设备的类型,比如安卓,ios等.输出浏览器的请求代理,可以判断浏览器类型.js代码如下 判断当前浏览器的请求代理 我是出来玩的! <!DOCTYPE html> &l ...

  6. Angularjs 2 绝对零基础的教程(1):从安装配置开始

    写在前面 适合人群: 1. 愿意未来从事前端工作,并以此开拓自己未来职业 2. 有任何一种编程语言基础 3. 喜欢简单粗暴学一门实用的技术,而不是做科研. Angular 2 比 Angular 1 ...

  7. Java <clinit> & <init>

    在编译生成class文件时,会自动产生两个方法,一个是类的初始化方法<clinit>, 另一个是实例的初始化方法<init>.     <clinit>:在jvm第 ...

  8. C语言中static关键字的用法

    C记得还是大一时学的,现在觉得好久没用了,又捧起来看看.今天刚看到有关static关键字,仔细地看了一遍<C和指针>这本书中的解释,现在觉得清楚多了. 首先,我们将static关键字,修饰 ...

  9. 初用MssqlOnLinux 【1】

    https://docs.microsoft.com/zh-cn/sql/linux/quickstart-install-connect-red-hat 使用 Centos7,NetCore2.0, ...

  10. js 对象的值传递

    一.变量赋值的不同 1.原始值 在将一个保存着原始值的变量复制给另一个变量时,会将原始值的副本赋值给新变量,此后这两个变量是完全独立的. 2.引用值: 在将一个保存着对象内存地址的变量复制给另一个变量 ...