poj1018:http://poj.org/problem?id=1018

题意:某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m1、m2、m3、...、mn个厂家提供生产,而每个厂家生产的同种设备都会存在两个方面的差别:带宽bandwidths 和 价格prices。现在每种设备都各需要1个,考虑到性价比问题,要求所挑选出来的n件设备,要使得B/P最大。其中B为这n件设备的带宽的最小值,P为这n
件设备的总价。
题解:方法一:暴力枚举。枚举每个bandwidth,然后从剩余的n-1个类中,找出bandwith大于等于这个ban的width而且price最小的那个值,然后求出b/p,每次枚举,然后更新b/p的值。

 #include<cstring>
#include<cstdio>
#include<iostream>
#include<algorithm>
using namespace std;
int visit[];//统计每个种类的个数
double ban[][];//记录每种的b值
double price[][];//记录每种的p值
int cas,n,temp;
int main(){
scanf("%d",&cas);//测试组数
while(cas--){
scanf("%d",&n);
for(int i=;i<=n;i++){//读取数据
scanf("%d",&visit[i]);
for(int j=;j<=visit[i];j++){
scanf("%lf%lf",&ban[i][j],&price[i][j]);
}
}
double ans=;//记录最终的结果
for(int i=;i<=n;i++){
for(int j=;j<=visit[i];j++){//枚举每个b值
double bb=ban[i][j];
double sum=price[i][j];//初始值应该是该种类这个对应的p,不是0
int count=;//记录剩余的类中有多少是有b值大于该b
for(int k=;k<=n;k++){//暴力剩余的种类
if(k==i)continue;
double ss=;
for(int g=;g<=visit[k];g++){//选取满足你要求的设备
if(ban[k][g]>=bb&&price[k][g]<ss)
ss=price[k][g];
}
if(ss!=){//如果找到了就更新sum以及count的个数
count++;
sum+=ss;
}
}
if(count==n-){//如果满足该条件,说明能从剩余的每个类中找出一个满足要求的
if(bb/sum>ans)//更新ans值
ans=bb/sum;
}
}
}
printf("%.3f\n",ans);
}
}

Communication System的更多相关文章

  1. Communication System(dp)

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

  2. poj 1018 Communication System

    点击打开链接 Communication System Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 21007   Acc ...

  3. poj 1018 Communication System 枚举 VS 贪心

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

  4. POJ 1018 Communication System(贪心)

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

  5. F - Communication System

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

  6. POJ 1018 Communication System (动态规划)

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

  7. POJ 1018 Communication System(树形DP)

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

  8. poj 1018 Communication System (枚举)

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

  9. Communication System(动态规划)

    个人心得:百度推荐的简单DP题,自己做了下发现真得水,看了题解发现他们的思维真得比我好太多太多, 这是一段漫长的锻炼路呀. 关于这道题,我最开始用DP的思路,找子状态,发现自己根本就不会找DP状态数组 ...

  10. POJ1018 Communication System

      Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 26738   Accepted: 9546 Description We ...

随机推荐

  1. mybatis0204 一对多查询

    查询所有订单信息及订单下的订单明细信息. sql语句 主查询表:订单表 关联查询表:订单明细 SELECT orders.*, user.username, user.sex , orderdetai ...

  2. Qt 学习之路:二进制文件读写

    在上一章中,我们介绍了有关QFile和QFileInfo两个类的使用.我们提到,QIODevice提供了read().readLine()等基本的操作.同时,Qt 还提供了更高一级的操作:用于二进制的 ...

  3. windows使用python调用wget批处理下载数据

    wget是linux/unix下通常使用的下载http/ftp的数据,使用非常方便,其实wget目前经过编译,也可在windows下使用.最近需要下载大量的遥感数据,使用了python写了批处理下载程 ...

  4. insert当 sql语句里面有变量 为字符类型的时候 要3个单引号

    set @InsertStr='INSERT INTO [dbo].[T_SchoolPercentMonth]([SchoolID],[MonthOfYear],[PercentNum]) VALU ...

  5. C#解leetcode 64. Minimum Path Sum

    Given a m x n grid filled with non-negative numbers, find a path from top left to bottom right which ...

  6. web前端开发浏览器兼容性 - 持续更新

    浏览器兼容性问题又被称为网页或网站兼容性问题:不同浏览器内核及所支持的html等网页语言标准不同,不同客户端环境(如分辨率不同)造成实际显示效果未能达到预期理想效果 首先我们来看一下目前市面上常见的一 ...

  7. HTML5 autocomplete属性、表单自动完成

    autocomplete属性 1.定义autocomplete属性规范表单是否启用自动完成功能.自动完成允许浏览器对字段的输入,是基于之前输入的值.2.应用范围autocomplete使用<fo ...

  8. C#快速排序法

    最近面试的时候,被问到了快速排序法.一时之间,无法想起算法来. 重新看了书本,算法如下: 1)设置两个变量I.J,排序开始的时候:I=0,J=N-1: 2)以第一个数组元素作为关键数据,赋值给key, ...

  9. c# 访问修饰符的访问权限

    1. 访问修饰符. 指定声明的类型和类型成员的可访问性. (1) public:是类型和类型成员的访问修饰符.公共访问是允许的最高访问级别.对访问公共成员没有限制. (2) private:是一个成员 ...

  10. GoogleAuthenticator

    <?php /** * PHP Class for handling Google Authenticator 2-factor authentication * * @author Micha ...