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. [ACM] HDU 5025 Saving Tang Monk (状态压缩,BFS)

    Saving Tang Monk Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others) ...

  2. MySQL Replication主从复制

    MySQL Replication:NySQL复制,MySQL的复制默认为异步工作模式   mysql的复制功能是mysql内置的,装上它之后就具备了这个功能,而mysql复制是mysql实现大规模高 ...

  3. android自定义控件,动态设置Button的样式

    原文  http://www.cnblogs.com/landptf/p/4562203.html 今天来看一个通过重写Button来动态实现一些效果,如圆角矩形.圆形.按下改变字体,改变背景色,改变 ...

  4. centos6.4安装flashcache

    FlashCache呢是Facebook技术团队的又一力作,最初是为加速MySQL设计的.Flashcache是在Linux层面的,所以任何受磁盘IO困绕的软件或应用都可以方便的使用.为什么是用于加速 ...

  5. Qt 学习之路:深入 Qt5 信号槽新语法

    在前面的章节(信号槽和自定义信号槽)中,我们详细介绍了有关 Qt 5 的信号槽新语法.由于这次改动很大,许多以前看起来不是问题的问题接踵而来,因此,我们用单独的一章重新介绍一些 Qt 5 的信号槽新语 ...

  6. Thread Runnable 多线程

    1. 实现多线程的两种方法         a) 让这个类继承java.lang.Thread,然后重写run方法         b) 让这个类实现 java.lang.Runnable接口,实现r ...

  7. Svg图片在asp网站上的使用

    最近需要做一个动态的根据后台的返回数据而动态显示的导航图,然后我就采用了jquery+ajax+SVG矢量图来实现这个功能. 首先,客户给了个ai的矢量图,我对这一块不懂就找以前同事帮我转成了svg图 ...

  8. JavaScript正则验证数字、英文、电话号、身份证号、邮箱地址、链接地址等

    验证是否为数字:/^[0-9]*$/验证是否为汉字:/^[\u4e00-\u9fa5],{0,}$/验证x-y位的数字:/^\d{x,y}$/验证由26个英文字母组成的字符串:/^[A-Za-z]+$ ...

  9. C++ hello world

    日文版本的vs 2008 , 在 < 新建 里面先创建一个项目 然后点击项目去创建一个C++的主启动文件 选择创建的文件类型 然后在文件里面写入代码 #include<iostream&g ...

  10. Uncaught SecurityError: Failed to execute 'toDataURL' on 'HTMLCanvasElement': Tainted canvases may not be exported.

    canvas绘制图片,由于浏览器的安全考虑,如果在使用canvas绘图的过程中,使用到了外域的图片资源,那么在toDataURL()时会抛出安全异常: Uncaught SecurityError: ...