poj 1018(枚举+贪心)
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
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
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(枚举+贪心)的更多相关文章
- 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 ...
- POJ 1018 Communication System(树形DP)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- 51nod1625(枚举&贪心)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1625 题意:中文题诶- 思路:枚举+贪心 一开始写的行和列同时 ...
- 枚举+贪心 HDOJ 4932 Miaomiao's Geometry
题目传送门 /* 题意:有n个点,用相同的线段去覆盖,当点在线段的端点才行,还有线段之间不相交 枚举+贪心:有坑点是两个点在同时一条线段的两个端点上,枚举两点之间的距离或者距离一半,尽量往左边放,否则 ...
- POJ 1018 Communication System 贪心+枚举
看题传送门:http://poj.org/problem?id=1018 题目大意: 某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m个厂家提供生产,而每个厂家生产的同种设备都 ...
- poj 1018 Communication System 枚举 VS 贪心
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21631 Accepted: ...
- POJ 1018 【枚举+剪枝】.cpp
题意: 给出n个工厂的产品参数带宽b和价格p,在这n个工厂里分别选1件产品共n件,使B/P最小,其中B表示n件产品中最小的b值,P表示n件产品p值的和. 输入 iCase n 表示iCase个样例n个 ...
- 【贪心】Communication System POJ 1018
题目链接:http://poj.org/problem?id=1018 题目大意:有n种通讯设备,每种有mi个制造商,bi.pi分别是带宽和价格.在每种设备中选一个制造商让最小带宽B与总价格P的比值B ...
- poj -- 1042 Gone Fishing(枚举+贪心)
题意: John现有h个小时的空闲时间,他打算去钓鱼.钓鱼的地方共有n个湖,所有的湖沿着一条单向路顺序排列(John每在一个湖钓完鱼后,他只能走到下一个湖继续钓),John必须从1号湖开始钓起,但是他 ...
随机推荐
- 5.20 mybatis反向生成的映射文件xml(如果需要自己定义其他sql语句时如下)
解决mybatis-generator 生成的mapper.xml覆盖自定义sql的问题 mybatis-generator是个好工具,一建即可生成基本增删改成功能的mapper.xml.但这些是不够 ...
- SQLServer2008 关于while循环
有这样一个表tbl id code name 11 a aa/bb/cc 22 b ee/rr/tt 需要将name段根据‘/’拆分开来,变成新的数据行 即: id c ...
- Vue掉坑记
本文章汇总学习过程中掉入和不理解的坑,会持续更新,请保持关注 1.过滤器类 搜索过滤 2.修饰符 修饰符汇总 3.webpack webpack+vuecli打包路径 4.Vue后台管理框架 组件后台 ...
- Ubuntu16下安装lamp
1.安装php7 sudo apt-get install php7.0 php7.0-mcrypt 2.安装MySQL sudo apt-get install mysql-server 输入 su ...
- C#使用wkhtmltopdf,把HTML生成PDF(包含分页)
最近花了2天多的时间终于把HTML生成PDF弄好了.步骤如下: 1.首先是技术选型.看了好多都是收费的就不考虑了. 免费的有: jsPDF(前端生成,清晰度不高,生成比较慢) iText(严格要求ht ...
- python爬虫:爬取百度云盘资料,保存下载地址、链接标题、链接详情
在网上看到的教程,但是我嫌弃那个教程写的乱(虽然最后显示我也没高明多少,哈哈),就随手写了一个 主要是嫌弃盘搜那些恶心的广告,这样直接下载下来,眼睛清爽多了. 用pyinstall 打包成EXE文件, ...
- 【Linux】tmpfs简介及增加方式
一. 什么是tmpfs? tmpfs是一种基于内存的文件系统,它和虚拟磁盘ramdisk比较类似,但不完全相同,和ramdisk一样,tmpfs可以使用RAM,但它也可以使用swap分区来存储.而且传 ...
- Caffe: Vs13添加CUDA支持
1. 右键工程 点击:Building Dependency 右击:Build Customizations 点击选项:CUDA 7.5 2.添加C++依赖: cudart.lib kernel32 ...
- THREE.js代码备份——webgl - custom attributes [lines](自定义字体显示、控制字图的各个属性)
<!DOCTYPE html> <html lang="en"> <head> <title>three.js webgl - cu ...
- 通用功能类:改变WinForm窗体显示颜色
一.显示窗体调用方法 protected override void OnLoad(EventArgs e) { MDIClientSupport.SetBevel ...