本文主要是介绍POJnbsp;nbsp;1018nbsp;nbsp;Communicationnbsp;System,希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!
Poj_1018_Communication System
关键词:dp 贪心 枚举
题目描述:Communication System
Time Limit: 1000MS | | Memory Limit: 10000K |
Total Submissions: 8824 | | Accepted: 3095 |
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
这题还不会写,但是还是先贴上大牛(大牛貌似语文不是太好,错别字就让我改了半天)的吧,省的以后找不到了
题目分析:本题一看一位很水,没想到还有这么多细节啊!吸取教训。仔细一看想用dp,找不到什么子结构,贪心感觉有不太对。最后感觉有点像二分的枚举。题目意思大概就是有n个devices,每个都需要一个bandwidth,而这个会有很多商家提供,价格不同,现在在n个中,每个选一个,但是着n个中选B最小的,而所有选的price和最小,即是B/p最大。
算法:就是找到所有组中最小的且是所有组中最小的B,和每组中最大的B且是所有组中最小的,然后从最小到最大枚举,每次选取大于B的p最小的,然后比较求出最大的B/P。
思考:水题不水!每一个题都应该认真对待。总结-做题-再总结。
代码:
#include<stdio.h>
#include<string.h>
int main()
{
}
这篇关于POJnbsp;nbsp;1018nbsp;nbsp;Communicationnbsp;System的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!