POJ1018 Communication System
| Time Limit: 1000MS | Memory Limit: 10000K | |
| Total Submissions: 26738 | Accepted: 9546 |
Description
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
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
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
/**/
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
using namespace std;
const int INF=1e8;
const int mxn=;
double ans=;
int f[mxn][];
int b,p;
int n,m;
int main(){
int T;
scanf("%d",&T);
while(T--){
scanf("%d",&n);
memset(f,,sizeof f);
int i,j;
for(i=;i<;i++)f[][i]=;;
for(i=;i<=n;i++){
scanf("%d",&m);
for(j=;j<=m;j++){
scanf("%d%d",&b,&p);
if(i==)f[][b]=min(f[][b],p);
else{
for(int k=;k<;k++)
f[i][min(k,b)]=min(f[i][min(k,b)],f[i-][k]+p);
}
}
}
ans=;
for(i=;i<;i++){
ans=max(ans,i/(double)f[n][i]);
}
printf("%.3lf\n",ans);
}
return ;
}
POJ1018 Communication System的更多相关文章
- Communication System(dp)
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25006 Accepted: 8925 ...
- poj 1018 Communication System
点击打开链接 Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21007 Acc ...
- poj 1018 Communication System 枚举 VS 贪心
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21631 Accepted: ...
- POJ 1018 Communication System(贪心)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- F - Communication System
We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...
- POJ 1018 Communication System (动态规划)
We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...
- POJ 1018 Communication System(树形DP)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- poj 1018 Communication System (枚举)
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22380 Accepted: ...
- Communication System(动态规划)
个人心得:百度推荐的简单DP题,自己做了下发现真得水,看了题解发现他们的思维真得比我好太多太多, 这是一段漫长的锻炼路呀. 关于这道题,我最开始用DP的思路,找子状态,发现自己根本就不会找DP状态数组 ...
随机推荐
- python中的集合内置方法小结
#!/usr/local/bin/python3 # -*- coding:utf-8 -*- #集合性质:需要传入一个list,且不含重复的元素,无序 list_1=[1,2,1,4,5,8,3,4 ...
- B1016 部分A+B (15分)
B1016 部分A+B (15分) 输入格式: 输入在一行中依次给出 A.DA.B.DB,中间以空格分隔,其中 \(0<A,B<10^10\). 输出格式: 在一行中输出 PA+PB的值. ...
- [BZOJ2427][HAOI2010]软件安装(tarjan+树形DP)
如果依赖关系出现环,那么对于一个环里的点,要么都选要么都不选, 所以每个环可以当成一个点,也就是强连通分量 然后就可以构造出一颗树,然后树形背包瞎搞一下就行了 注意要搞一个虚拟节点当根节点 Code ...
- __builtin_popcount() 函数
详解 该函数的主要作用是计算一个数字的二进制中有多少个1,返回值就是其中1的个数. 它使用一张基于表的方法来进行位搜索,因此这个操作的执行效率很高 此处举一题 P1582 倒水 #include &l ...
- Apache 设置二级域名
开启重写模块 LoadModule rewrite_module modules/mod_rewrite.so 编辑配置 NameVirtualHost *:80 <VirtualHost *: ...
- Samba和NFS文件共享
SAMBA文件共享服务 通过Yum软件仓库来安装Samba服务程序 [root@zhangjh ~]# yum install samba -y Samba 配置文件注释信息较多,为了便于配置,因此先 ...
- 课后题2.87&2.86
课后题2.86&2.87 单纯就是想加点分第十章的题目都被做过了就做下第二章的,正好复习一下前面学的知识,第二章给我剩下的题目也不多了,我就挑了这个题目. 2.86 考虑一个基于IEEE浮点格 ...
- CentOS 更换yum源为aliyun yum源
CentOS自带的yum源为官方的源,由于墙的原因,经常无法访问,国内也有不错的源,这里讲一下使用aliyun的源替换原yam源. 第一种方法 1.安装base reop源 cd /etc/yum.r ...
- Windows下zookeeper注册中心的安装和启动
zookeeper的安装支持单机模式和集群模式 下载地址:http://www.apache.org/dyn/closer.cgi/zookeeper/,当前稳定版本为3.4.8 单机模式 修改zoo ...
- Windows系统安装测试redis
因本人电脑是windows系统,从https://github.com/ServiceStack/redis-windows下载了兼容windows系统的redis 下载后直接解压到D:\redis目 ...