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. delphi TColorDialog

    TColorDialog 预览          实现过程 动态创建和使用颜色对话框 function ShowColorDlg:TColor;begin  with TColorDialog.Cre ...

  2. VirtualBox 运行失败

    运行 VirtualBox --help 安装 VirtualBox 后 运行 报错内核没加载问题 需要设置环境变量 内核加载的环境变量 export KERN_DIR=/usr/src/kernel ...

  3. 后端接收不到AngularJs中$http.post发送的数据的问题

    1.问题: 后端接收不到AngularJs中$http.post发送的数据,总是显示为null 示例代码: $http.post(/admin/KeyValue/GetListByPage, { pa ...

  4. python s12 day2

    python s12 day2   入门知识拾遗 http://www.cnblogs.com/wupeiqi/articles/4906230.html 基本数据类型 注:查看对象相关成员 var, ...

  5. HTML5 文件域+FileReader 读取文件(二)

    一.读取文本文件内容,指定字符编码 <div class="container"> <!--文本文件验证--> <input type="f ...

  6. Eclipse设立不格式化注释

    From:http://www.educity.cn/wenda/467693.html Eclipse设置不格式化注释 注释中写点带格式的文字,format后全乱了,解决办法如下: Windows ...

  7. MySQL 5.6 my.cnf 参数详细说明

    # 以下选项会被MySQL客户端应用读取.# 注意只有MySQL附带的客户端应用程序保证可以读取这段内容.# 如果你想你自己的MySQL应用程序获取这些值.# 需要在MySQL客户端库初始化的时候指定 ...

  8. Cookie技术详解

    1. Cookie的特性 属性: 1> name: Cookie的名字 2> value: Cookie的值 3> path: 可选,Cookie的存储路径,默认情况下的存储路径时访 ...

  9. xcode中如何安装多个版本的模拟器

    在xcode里面,安装的时间默认自带的有模拟器,有时间为了调试需要使用个多个版本的模拟器 在xcode  -> preference  里面 选择download,这里你可下载你需要的模拟器

  10. 继承语法含有main()方法

    package me.ybleeho; class Cleanser{ //清洁剂 private String s="Cleanser"; public void append( ...