Communication System
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的更多相关文章
- Communication System(dp)
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 25006 Accepted: 8925 ...
- poj 1018 Communication System
点击打开链接 Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21007 Acc ...
- poj 1018 Communication System 枚举 VS 贪心
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21631 Accepted: ...
- POJ 1018 Communication System(贪心)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- F - Communication System
We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...
- POJ 1018 Communication System (动态规划)
We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...
- POJ 1018 Communication System(树形DP)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- poj 1018 Communication System (枚举)
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22380 Accepted: ...
- Communication System(动态规划)
个人心得:百度推荐的简单DP题,自己做了下发现真得水,看了题解发现他们的思维真得比我好太多太多, 这是一段漫长的锻炼路呀. 关于这道题,我最开始用DP的思路,找子状态,发现自己根本就不会找DP状态数组 ...
- POJ1018 Communication System
Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 26738 Accepted: 9546 Description We ...
随机推荐
- MySQL 一致性读 深入研究 digdeep博客学习
http://www.cnblogs.com/digdeep/p/4947694.html 一致性读,又称为快照读.使用的是MVCC机制读取undo中的已经提交的数据.所以它的读取是非阻塞的. 相关文 ...
- 观察者模式在ng(Angular)中的应用
在这个前端框架满天飞的天下,angular MVVM 的模式确实火了一把,所以最近一直在学习ng,感悟颇多,填坑无数,今天终静下心来打算更新自己久未变动的博客,做一做总结. 1.在ng中的观察者模式: ...
- Xcode常见报错及解决办法
报错一: 在iOS7的真机运行时,弹出错误:App installation failed. There was an internal API error. 如图 解决办法: 在Xcode -> ...
- windows下jboss启动、配置、访问
window 下的jboss启动.配置.访问 1.进入jboss\server\default\deploy\jboss-web.deployer 执行run命令 2.jboss访问地址:http:/ ...
- laydate时间组件在火狐浏览器下有多时间输入框时只能给第一个输入框赋值的问题
遇到的问题: laydate时间组件在火狐浏览器下有多时间输入框时只能给第一个输入框赋值的问题(safari下也有同样问题); 解决办法: 给laydate绑定id; 解决前代码: <input ...
- window.showModalDialog 子窗口和父窗口不兼容最新的谷歌
最新版的谷歌不支持window.showModalDialog的写法,会出现,找不到方法的问题,同时返回值的方法window.dialogArguments;也用不了. 这里就只能用最原版的windo ...
- Java-Android 之短信发送
file:///F:/workspace3/Android_ver2.5/src/cn/szy/com/MainActivity.java package cn.szy.com; import jav ...
- 关于get和set访问器以及属性和字段变量的区别问题
属性是对一个或者多个字段的封装. 类里面为什么要用一个共有的属性来封装其中的字段,也可以这样说用共有属性来封装私有变量,其中的好处应该大家都说的出来,就是为了实现数据的封装和保证了数据的安全 ...
- angularjs 遇到Error: [$injector:unpr] Unknown provider: tdpicnews-serviceProvider <- tdpicnews-service <- tdpic-controller 错误
define(['modules/tdpic-module', 'services/news-service', 'utilities/cryto'], function (app) { 'use s ...
- oracle中不曾熟悉的 to_char、to_number(未完待续)
十进制 十六进制88 58 用法一:Converts a HEX number to o FLOAT (转换一个十六进制数的浮标) SQL> sele ...