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 ...
随机推荐
- android uri , file , string 互转
1:android Uri 介绍 http://www.cnblogs.com/lingyun1120/archive/2012/04/18/2455212.html 2:File 转成Uri < ...
- TCP SOCKET中backlog参数的用途是什么? ---图解
recv_queue中的包大小,为内核的包大小,而不是ip包大小. 如果发出去的包太大,需要修改write_queue和tx_queue两个参数,tx_queue主要是流量控制. 多进程必须在sock ...
- Service 如何知道caller
重写Binder的onTransact方法 1 you need to do that in Binder#onTransact method, this is a good place for ...
- nginx php7 配置 备用
yum install epel-* -y yum install -y wget unzip gcc gcc-c++ make zlib zlib-devel pcre pcre-devel lib ...
- Android Camera开发:使用TextureView和SurfaceTexture预览Camera 基础拍照demo
Google自Android4.0出了TextureView,为什么推出呢?就是为了弥补Surfaceview的不足,另外一方面也是为了平衡GlSurfaceView,当然这是本人揣度的.关于Text ...
- 分享一下自己在用的CSS样式重置代码
通过借鉴网上大牛们的经验和自己在工作中碰到的一些问题,总结出了这些比较常用的CSS样式重置的代码: @charset "utf-8"; /* 防止用户自定义背景颜色对网页的影响,添 ...
- 寒哥教你学 iOS - 经验漫谈(转)
转自http://www.cocoachina.com/ios/20150907/13339.html 本篇文章主要讲解 4个问题 load妙用 aop面向切面编程 NSNumber Or Int @ ...
- 微信小程序开发之 下拉刷新,上拉加载更多
本文记载了如何在微信小程序里面实现下拉刷新,上拉加载更多 先开看一下界面 大致如此的界面吧. 这个Demo使用了微信的几个Api和事件,我先列出来. 1.wx.request (获取远程服务器的数据, ...
- Spring MVC中注解 @ModelAttribute
1.@ModelAttribute放在方法之上,在当前Control内的所有方法映射多个URL的请求,都会执行该方法 @ModelAttribute public void itemsCommon(H ...
- VirtualBox 中的UBUNTU和java环境的配置以及各种常用说明
本来是要ubuntu下学习C++的,但是又懒的用高手们推荐的各种记事本级的操作,所以要用IDE.(我用IDE我自豪,人类的进化就是建立在工具的使用这个基础之上的.)我选用了oracle的netbean ...