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

题目要求所选d的最小值除以总p最大;

一开始的想法是从第一个开始选然后慢慢选后面的,但是发现有bug,这种方法做不了;

这题因为n,t都比较小,所以可以用暴力,把所有的情况都选一边,就是从d最小开始选择,然后把所有情况的d/p算出来,选最大的就好了

#include<iostream>
#include<stdio.h>
#include<stdlib.h>
#include<cmath>
#include<string.h>
#include<algorithm>
#define sf scanf
#define pf printf
#define cl clear()
#define pb push_back
#define mm(a,b) memset((a),(b),sizeof(a))
#include<vector>
const double pi=acos(-1.0);
typedef __int64 ll;
typedef long double ld;
const ll mod=1e9+7;
struct qq
{
int num;
int a[105];
int b[105];
}q[105];
int dd[10005],d[10005];
double ans[10005];
using namespace std;
int main()
{
int re;
cin>>re;
while(re--)
{
mm(ans,0);
int ww=1;
int w=0;
mm(d,0);
mm(dd,0);
int n;
cin>>n;
double b=0,p=0;
for(int i=0;i<n;i++)
{
mm(q[i].a ,0);mm(q[i].b,0);
int m;
cin>>m;
q[i].num =m;
for(int j=0;j<m;j++)
{
sf("%d%d",&q[i].a[j],&q[i].b[j]);
dd[w++]=q[i].a[j];
}
}
sort(dd,dd+w);
d[0]=dd[0];
for(int i=1;i<w;i++)
{
if(dd[i]!=d[ww-1])
d[ww++]=dd[i];
}
int k;
for( k=0;k<ww;k++)
{
int pp=0,temp=0;
for(int i=0;i<n;i++)
{
int p=mod;
for(int j=0;j<q[i].num ;j++)
{
if(q[i].a[j]>=d[k])
if(q[i].b[j]<p)
p=q[i].b[j];
}
if(p==mod)
temp=1;
pp+=p;
}
if(temp)
break;
ans[k]=(double)d[k]/pp;
}
double max=ans[0];
for(int i=1;i<k;i++)
if(max<ans[i])
max=ans[i];
pf("%.3lf\n",max);
}
return 0;
}

F - Communication System的更多相关文章

  1. poj 1018 Communication System

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

  2. POJ1018 Communication System

      Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26738   Accepted: 9546 Description We ...

  3. Communication System(dp)

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

  4. Codeforces Gym 100286F Problem F. Fibonacci System 数位DP

    Problem F. Fibonacci SystemTime Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://acm.hust.edu.cn/vjudg ...

  5. poj 1018 Communication System 枚举 VS 贪心

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

  6. POJ 1018 Communication System(贪心)

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

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

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

  8. POJ 1018 Communication System(树形DP)

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

  9. poj 1018 Communication System (枚举)

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

随机推荐

  1. 如何用C#动态编译、执行代码

    在开始之前,先熟悉几个类及部分属性.方法:CSharpCodeProvider.ICodeCompiler.CompilerParameters.CompilerResults.Assembly. 一 ...

  2. MySQL查看数据库表容量大小

    本文介绍MySQL查看数据库表容量大小的命令语句,提供完整查询语句及实例,方便大家学习使用. 1.查看所有数据库容量大小 select table_schema as '数据库', sum(table ...

  3. Openstack配置文件管理的变迁之路

    在管理一个Openstack集群时,如何维护配置文件无疑是其中最艰难和繁琐的任务之一.因为你不仅要面对众多的核心服务(nova,keystone,glance,cinder,etc)的配置文件,还需要 ...

  4. 微软BI 之SSIS 系列 - 带有 Header 和 Trailer 的不规则的平面文件输出处理技巧

    案例背景与需求介绍 之前做过一个美国的医疗保险的项目,保险提供商有大量的文件需要发送给比如像银行,医疗协会,第三方服务商等.比如像与银行交互的 ACH 文件,传送给协会的 ACH Credit 等文件 ...

  5. MDX Cookbook 11 - 计算 Year Over Year 增长 (同比计算) ParallelPeriod

    这一小节主要介绍如何在一个平行期间的度量值,当前值的对比对象是指当前值的上一年,上一个季度或者其它时间级别上与当前值同一时间点上的的那个对象.有一个非常常见的需求就是对比上一年同一个时间点的某个值来判 ...

  6. SQL与MySQL基本

    一:概念辨析 数据库(database):是一种保存有组织的数据的容器. 数据库软件(DBMS):使用DBMS操作数据库.访问数据库. SQL:结构化查询语言,专门用来与数据库通信的语言.几乎所有DB ...

  7. ceph 生成rpm包

    概述 从ceph的源码build出rpm包: #git clone --recursive https://github.com/ceph/ceph.git #./instal-dep.sh 以上两点 ...

  8. IDEA使用笔记(八)——自动生成 serialVersionUID 的设置

    这个设置比较简单,也有一些博文已经写到了,为什么我还要写哪?(潜台词:因为我想凑一篇博文)我觉得学习,特别是编程学习是需要重复造轮子的,另外,就是加深自己的印象方便自己的查找.还有就是关键点,有些博客 ...

  9. 使用ExpandableListView以及如何优化view的显示减少内存占用

    上篇博客讲到如何获取手机中所有歌曲的信息.本文就把上篇获取到的歌曲按照歌手名字分类.用一个ExpandableListView显示出来. MainActivity .java   public cla ...

  10. Atitit 项目文档规范化与必备文档与推荐文档列表

    Atitit 项目文档规范化与必备文档与推荐文档列表 ===========比较重要的必备文档========== 项目组名单通讯录( 包括项目组,客户沟通人等 需求文档 原型ui文档 开发计划表 项 ...