POJ 1018 - Communication System
2016-01-22 20:46
507 查看
Communication System
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
Sample Output
Source
Tehran 2002, First Iran Nationwide Internet Programming Contest
[b]大致题意:[/b]
该通信系统需要n种设备,而每种设备分别可以有m1、m2、m3、...、mn个厂家提供生产。
同种设备都会存在两个方面的差别:bandwidths 和 prices。
现在每种设备都各需要1个,考虑到性价比问题,要求所挑选出来的n件设备,要使得B/P最大。
其中B为这n件设备的带宽的最小值,P为这n件设备的总价。
解题思路:
找出最大bandwidths和最小bandwidths,然后从小到大依次枚举,找出每种bandwidths的最大B/P(即最小prices),再比较出最大的即为answer;
Time Limit: 1000MS | Memory Limit: 10000K | |
Total Submissions: 25744 | Accepted: 9184 |
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
[b]大致题意:[/b]
该通信系统需要n种设备,而每种设备分别可以有m1、m2、m3、...、mn个厂家提供生产。
同种设备都会存在两个方面的差别:bandwidths 和 prices。
现在每种设备都各需要1个,考虑到性价比问题,要求所挑选出来的n件设备,要使得B/P最大。
其中B为这n件设备的带宽的最小值,P为这n件设备的总价。
解题思路:
找出最大bandwidths和最小bandwidths,然后从小到大依次枚举,找出每种bandwidths的最大B/P(即最小prices),再比较出最大的即为answer;
#include <iostream> #include <algorithm> using namespace std; #define N 105 int main() { int a ,b ,tot ;//bandwidths、prices 、输入计数 int t,n; scanf("%d",&t); while(t--) { double ans=0; int MAX=0,MIN=0xffff;//最大最小 bandwidths scanf("%d",&n); for(int i=1;i<=n;i++) { scanf("%d",&tot[i]); for(int j=1;j<=tot[i];j++) { scanf("%d%d",&a[i][j],&b[i][j]); MAX=max(MAX,a[i][j]); MIN=min(MIN,a[i][j]); } } for(int key=MIN;key<=MAX;key++)//枚举 { int sum=0; for(int i=1;i<=n;i++) { int M=0xffff; for(int j=1;j<=tot[i];j++) if(a[i][j]>=key&&M>b[i][j]) M=b[i][j]; sum+=M; } if(1.0*key/sum>ans) ans=1.0*key/sum; } printf("%.3lf\n",ans); } return 0; }
相关文章推荐
- 1.22作业
- Python工具之SQLAlchemy
- 进程清理
- CSS之盒模型
- 【BZOJ】1003 物流运输
- poj1753 Flip Game 位运算+科学枚举法 0ms无压力~
- 如何在Swift中调用C函数
- VIM编辑器的使用
- OleDbConnection打开xls文件发生“External table is not in the expected format.”异常
- 使用Dom4j解析XML
- IOS 关键字self,super,copy, retain, assign , readonly , readwrite, nonatomic、@synthesize、@property、@dyna
- Android使用ViewPager实现图片轮播(高度自适应,左右循环,自动轮播)
- 三角形
- OJ 约瑟夫环 数组
- armadillo ubuntu 使用注意
- QT中结合实际例子谈谈QTableWidget中布局控件的方法
- 哈希图像检索—图像数据集获取链接总结【Hashing数据集】
- 【重学数据结构】数制转换
- DL外文精华文章整理(CVPR2015)
- 【慕课笔记】第七章 方法 第4节 JAVA中带参无返回值方法的使用