Communication System
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 22380   Accepted: 7953

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

Source

Tehran 2002, First Iran Nationwide Internet Programming Contest
 
投降的题...
 
题意:
    给出n样零件,及每样零件的都有b[i]个厂生产,有带宽b和价格p两个值。求全部零件(每样一件) min(b)/sum(p) 的最大值。
 
枚举:
    对带宽进行枚举,选出全部零件的最大及最小带宽,然后进行枚举,每个循环选出符合条件的价格的和,得出ans再进行比较,得到最优解。
 //232K    47MS    C++    1164B    2014-05-07 19:16:42
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
struct node{
int b;
int p;
}a[][];
int b[];
int n;
inline int Max(int x,int y)
{
return x>y?x:y;
}
inline int Min(int x,int y)
{
return x<y?x:y;
}
int main(void)
{
int t,m;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
int ln=0x7ffffff,rn=;
for(int i=;i<n;i++){
scanf("%d",&b[i]);
for(int j=;j<b[i];j++){
scanf("%d%d",&a[i][j].b,&a[i][j].p);
ln=Min(ln,a[i][j].b);
rn=Max(rn,a[i][j].b);
}
}
double ans=;
for(int i=ln;i<=rn;i++){
int sminn=;
for(int j=;j<n;j++){
int minn=0x7ffffff;
for(int k=;k<b[j];k++){
if(a[j][k].b>=i && minn>a[j][k].p)
minn=a[j][k].p;
}
sminn+=minn;
}
ans=ans>(i*1.0/sminn)?ans:(i*1.0/sminn);
//printf("*****%lf\n",ans);
}
printf("%.3lf\n",ans);
}
return ;
}

poj 1018 Communication System (枚举)的更多相关文章

  1. poj 1018 Communication System 枚举 VS 贪心

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

  2. POJ 1018 Communication System(树形DP)

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

  3. POJ 1018 Communication System(贪心)

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

  4. poj 1018 Communication System

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

  5. POJ 1018 Communication System (动态规划)

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

  6. POJ 1018 Communication System 贪心+枚举

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

  7. POJ 1018 Communication System(DP)

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

  8. POJ 1018 Communication System 题解

    本题一看似乎是递归回溯剪枝的方法.我一提交,结果超时. 然后又好像是使用DP,还可能我剪枝不够. 想了非常久,无奈忍不住偷看了下提示.发现方法真多.有贪心,DP,有高级剪枝的.还有三分法的.八仙过海各 ...

  9. poj 1018 Communication System_贪心

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

随机推荐

  1. C# 终本案件、综合执行人、裁判文书爬虫

    终本案件:http://zxgk.court.gov.cn/zhongben/new_index.html 综合执行人:http://zxgk.court.gov.cn/zhixing/new_ind ...

  2. vim分屏功能总结

    vim的分屏功能 总结起来,基本都是ctrl+w然后加上某一个按键字母,触发一个功能.(1)在shell里打开几个文件并且分屏: vim -On file1 file2 ... vim -on fil ...

  3. NNLearning阶段性总结01

    神经网络最基本的元素与计算流程: 基本的组网原则: 神经网络监督学习的基本步骤: 初始化权值系数 提取一个样本输入NN,比较网络输出与正确输出的误差 调整权值系数,以减少上面误差——调整的方法对应不同 ...

  4. 浅析JVM内存区域及垃圾回收

    一.JVM简介 JVM,全称Java Virtual Machine,即Java虚拟机.以Java作为编程语言所编写的应用程序都是运行在JVM上的.JVM是一种用于计算设备的规范,它是一个虚构出来的计 ...

  5. Linux命令应用大词典-第36章 密码和证书管理

    36.1 pwdhash:密码哈希生成器 36.2 mkpasswd:生成应用于用户的新密码 36.3 keytool:密钥和证书管理工具 36.4 certutil:证书服务器管理工具 36.5 v ...

  6. Linux搭建mysql、apache、php服务总结

    本随笔文章,由个人博客(鸟不拉屎)转移至博客园 写于:2018 年 04 月 22 日 原地址:https://niaobulashi.com/archives/linux-mysql-apache- ...

  7. 关于java获取网页内容

    最近项目需求,做一些新闻站点的爬取工作.1.简单的jsoup爬取,静态页面形式: String url="a.atimo.cn";//静态页面链接地址Document doc = ...

  8. CodeForces - 776C(前缀和+思维)

    链接:CodeForces - 776C 题意:给出数组 a[n] ,问有多少个区间和等于 k^x(x >= 0). 题解:求前缀和,标记每个和的个数.对每一个数都遍历到1e5,记录到答案. # ...

  9. WCF服务库创建-20140919

    1. 创建wcf服务库 2. 宿主到web程序上 // 宿主wcf服务库 RouteTable.Routes.Add(new ServiceRoute("ctserver.dll" ...

  10. 接口_GET请求_基于python

    1.GET请求(不带参数) # coding:utf-8 import requests r=requests.get("https://www.baidu.com") #r即为r ...