通讯系统
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
题意:系统需要n件设备,每件设备可以有m个厂家生产,但宽度个价格会存在差别,现在每种设备都需要一个,
题意要求的是满足(B/P)max最大的情况下选出这n件设备,
B为这n件设备的最小宽度,P为花费的价格 我们在这所有设被备从小到大枚举设备的宽度,找出它对应的最小的价格,最后区最大的q/p;
 #include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<queue>
#include<map>
#include<set>
#include<vector>
#include<cstdlib>
#include<string>
#define eps 0.000000001
typedef long long ll;
typedef unsigned long long LL;
using namespace std;
const int N=+;
double Max(double a,double b){
return a>b?a:b;
}
int B[N][N],P[N][N];
int a[N];
int f(int t,int n){
for(int i=;i<=n;i++)
for(int j=;j<=a[i];j++)
if(B[i][j]==t)return ;
return ;
}
int main(){
int t,n; scanf("%d",&t);
while(t--){
int minn=0x3f3f3f3f;
int maxx=-0x3f3f3f3f;
scanf("%d",&n);
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
for(int j=;j<=a[i];j++){scanf("%d%d",&B[i][j],&P[i][j]);
minn=min(B[i][j],minn);
maxx=max(B[i][j],maxx);
}
}
// cout<<minn<<" "<<maxx<<endl;
double ans=0.0;
for(int i=minn;i<=maxx;i++){
if(f(i,n)==)continue;
int sum=;
for(int j=;j<=n;j++){
int t=0x3f3f3f3f;
for(int k=;k<=a[j];k++){
if(B[j][k]>=i)t=min(t,P[j][k]);
}
sum=sum+t;
}
//cout<<i<<" "<<sum<<endl;
ans=Max(ans,(double)i/sum);
}
printf("%.3f\n",ans);
}
}

poj 1018(枚举+贪心)的更多相关文章

  1. D. Diverse Garland Codeforces Round #535 (Div. 3) 暴力枚举+贪心

    D. Diverse Garland time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  2. POJ 1018 Communication System(树形DP)

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

  3. 51nod1625(枚举&贪心)

    题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625 题意:中文题诶- 思路:枚举+贪心 一开始写的行和列同时 ...

  4. 枚举+贪心 HDOJ 4932 Miaomiao's Geometry

    题目传送门 /* 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则 ...

  5. POJ 1018 Communication System 贪心+枚举

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

  6. poj 1018 Communication System 枚举 VS 贪心

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

  7. POJ 1018 【枚举+剪枝】.cpp

    题意: 给出n个工厂的产品参数带宽b和价格p,在这n个工厂里分别选1件产品共n件,使B/P最小,其中B表示n件产品中最小的b值,P表示n件产品p值的和. 输入 iCase n 表示iCase个样例n个 ...

  8. 【贪心】Communication System POJ 1018

    题目链接:http://poj.org/problem?id=1018 题目大意:有n种通讯设备,每种有mi个制造商,bi.pi分别是带宽和价格.在每种设备中选一个制造商让最小带宽B与总价格P的比值B ...

  9. poj -- 1042 Gone Fishing(枚举+贪心)

    题意: John现有h个小时的空闲时间,他打算去钓鱼.钓鱼的地方共有n个湖,所有的湖沿着一条单向路顺序排列(John每在一个湖钓完鱼后,他只能走到下一个湖继续钓),John必须从1号湖开始钓起,但是他 ...

随机推荐

  1. windows和linux无法访问VMware中linux的tomcat主页问题

    1.一定确定自己的tomcat服务器是启动的.(为了确保保险可以在测试前重新shutdown,startup一次) 2.确定自己访问的ip地址和端口号是正确的 如果是VMware外部windows的话 ...

  2. 3A课程笔记分享_StudyJams_2017

    课程3A-面向对象编程(上) 概述 面向对象的思想在当今的软件开发中占据着主导地位. Java是一门完全面向对象的语言,是一种天然的分布式互联网软件的开发语言,在当今企业级应用中占据绝对领先地位,也是 ...

  3. 关于Core里的 StartUp里的方法的理解。

    public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; ...

  4. iis 7.5 ftp site用户名不能是 'ftp'?

    在windows server 2008 r2上配置一个iis ftp site,创建了一个名为 ftp 的账号,并添加到允许规则中,可总是出现: Connected to ***.***.***.* ...

  5. C#访问Win 32的一些尝试

    使用C#调用Win 32 Api大部分情况下基本只涉及到参数类型的转变,但在遇到Win 32 Api返回LPVOID *lpBuff 时会遇到一些解析遍历难题.lpBuff为二维指针,*lpBuff是 ...

  6. 面试官问你:MYSQL事务和隔离级别,该如何回答

    一.事务 事务是由一组SQL语句组成的逻辑处理单元,是满足 ACID 特性的一组操作,可以通过 Commit 提交一个事务,也可以使用 Rollback 进行回滚.事务具有以下4个属性,通常简称为事务 ...

  7. marquee图片无缝拼接滚动

    marquee图片无缝滚动 先了解一下对象的几个的属性: innerHTML:     设置或获取位于对象起始和结束标签内的 HTML scrollHeight: 获取对象的滚动高度. scrollL ...

  8. [luogu2602 ZJOI2010] 数字计数 (数位dp)

    传送门 Description 给定两个正整数a和b,求在[a,b]中的所有整数中,每个数码(digit)各出现了多少次. Input 输入文件中仅包含一行两个整数a.b,含义如上所述. Output ...

  9. PHP中把数据库查询结果输出为json格式

    <?php header("Content-type:text/html;charset=utf-8");//字符编码设置 $servername = "local ...

  10. 2.2 SVN的简单使用

    1.打开SVN服务器 选中Repositories→右键→Create new Repositories 选中Test2→右键→Copy URL to Clipboard 打开记事本粘贴地址:http ...