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. mentohust 使用

    可使用帮助命令 mentohust -h 或着查看 https://wenku.baidu.com/view/95c08019ff00bed5b9f31d1a.html

  2. 视觉SLAM的数学表达

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

  3. BZOJ 4818 SDOI2017 序列计数

    刚出炉的省选题,还是山东的. 自古山东出数学和网络流,堪称思维的殿堂,比某地数据结构成风好多了. 废话不说上题解. 1.题面 求:n个数(顺序可更改),值域为[1,m],和为p的倍数,且这些数里面有质 ...

  4. ffmpeg常用命令---转

    1.分离视频音频流 ffmpeg -i input_file -vcodec copy -an output_file_video //分离视频流 ffmpeg -i input_file -acod ...

  5. Nodejs使用redis

    安装方法 安装redis方法请自行百度, 用npm方法,安装nodejs的redis模块 npm install redis 实战 var redis = require("redis&qu ...

  6. 点击按钮显示隐藏DIV,点击DIV外面隐藏DIV

    点击按钮显示隐藏DIV,点击DIV外面隐藏DIV 注意:此方法对touch事件不行,因为stopPropagation并不能阻止touchend的冒泡 <style type="tex ...

  7. Q:java中serialVersionUID的作用

    @转载自:http://www.cnblogs.com/guanghuiqq/archive/2012/07/18/2597036.html   简单来说,Java的序列化机制是通过在运行时判断类的s ...

  8. JavaScript的DOM编程--01--js代码的写入位置

    DOM:Document Object Model(文本对象模型) D:文档 – html 文档 或 xml 文档 O:对象 – document 对象的属性和方法 M:模型 DOM 是针对xml(h ...

  9. 例子:韩顺平JavaScript----JS乌龟抓小鸡游戏

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  10. Java Web高级编程(一)

    Servlet 一.创建Servlet类 在Java EE中,Servlet用来接收和响应终端用户的请求.Servlet是所有Web应用程序的核心类,是唯一既可以直接处理和响应用户请求,也可以将处理工 ...