POJ 1018 Communication System(贪心)
Description
By overall bandwidth (B) we mean the minimum of the bandwidths of the chosen devices in the communication system and the total price (P) is the sum of the prices of all chosen devices. Our goal is to choose a manufacturer for each device to maximize B/P.
Input
Output
Sample Input
1 3
3 100 25 150 35 80 25
2 120 80 155 40
2 100 100 120 110
Sample Output
0.649
Source
#include <iostream>
#include <vector> using namespace std; struct goods
{
int p, b;
};
vector<goods>a[];
const int MAXN = ; void Clear() //用来清空信息的 很重要 没有这个会错
{
for (int i = ; i <= ; i++)
a[i].clear();
} int main()
{
int t, num, n;
double ans;
goods a1, a2;
cin >> t;
while (t--)
{
Clear();
ans = -;
cin >> num; //器件总数
for (int i = ; i < num; i++)
{
cin >> n;
for (int j = ; j < n; j++)
cin >> a1.b >> a1.p, a[i].push_back(a1);
}
for(int i = ; i < num; i++) //枚举第i个器件
{
for (int j = ; j < a[i].size(); j++) //枚举第i种器件的对应器件 确定第i种器件
{
a1 = a[i][j]; //选中第i种器件的第j个 而且假定这个器件的B是最小的
double B = a1.b;
double P = a1.p;
int pp;
for (int k = ; k < num; k++) //枚举n-1种器件
{
if (k == i) continue; //第i种器件已经选择过了 避免重复选择
pp = MAXN;
for (int h = ; h < a[k].size(); h++)
{
a2 = a[k][h];
if (a2.b < B) continue; //假定B是最小的 不能选择更小的
if (pp > a2.p) pp = a2.p; //为了使B/P尽可能大 P就要尽可能小
}
if (pp == MAXN) break; //找不到合适的器件 那么就表示选错了 重新选择
P += pp;
}
if (pp == MAXN) break;
if (ans < (B / P)) ans = (B / P);
}
}
printf("%.3f\n", ans);
}
return ;
}
POJ 1018 Communication System(贪心)的更多相关文章
- POJ 1018 Communication System 贪心+枚举
看题传送门:http://poj.org/problem?id=1018 题目大意: 某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m个厂家提供生产,而每个厂家生产的同种设备都 ...
- poj 1018 Communication System 枚举 VS 贪心
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21631 Accepted: ...
- 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: 21007 Acc ...
- POJ 1018 Communication System (动态规划)
We have received an order from Pizoor Communications Inc. for a special communication system. The sy ...
- poj 1018 Communication System (枚举)
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 22380 Accepted: ...
- POJ 1018 Communication System(DP)
http://poj.org/problem?id=1018 题意: 某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m1.m2.m3.....mn个厂家提供生产,而每个厂家生产 ...
- POJ 1018 Communication System 题解
本题一看似乎是递归回溯剪枝的方法.我一提交,结果超时. 然后又好像是使用DP,还可能我剪枝不够. 想了非常久,无奈忍不住偷看了下提示.发现方法真多.有贪心,DP,有高级剪枝的.还有三分法的.八仙过海各 ...
- poj 1018 Communication System_贪心
题意:给你n个厂,每个厂有m个产品,产品有B(带宽),P(价格),现在要你求最大的 B/P 明显是枚举,当P大于一定值,B/P为零,可以用这个剪枝 #include <iostream> ...
随机推荐
- [机器学习]模型评价参数,准确率,召回率,F1-score
很久很久以前,我还是有个建筑梦的大二少年,有一天,讲图的老师看了眼我的设计图,说:"我觉得你这个设计做得很紧张".当时我就崩溃,对紧张不紧张这样的评价标准理解无能.多年后我终于明白 ...
- C语言 模2除法
C语言中的模2除法: 模2除做法与算术除法类似,但每一位除(减)的结果不影响其它位,即不向上一位借位.所以实际上就是异或.然后再移位移位做下一位的模2减. 步骤如下: a.用除数对被除数最高n位做模2 ...
- 史上最全的判断android,ios还是ipad访问,附上多种语言的实现方式
js判断: (function(a,b){if(/(android|bb\d+|meego).+mobile|avantgo|bada\/|blackberry|blazer|compal|elain ...
- jquery 导出Excel表格
仅在 table 中应用过!适用于导出简单的excel <script type="text/javascript" src="jquery.table2excel ...
- Maven的Archetype简介
Archetype,骨架的意思. 文章出处:http://m.blog.csdn.net/blog/FireOfStar/42526027 Archetype是什么? 简单的说,Archetype是M ...
- Linux指令--chown
chown将指定文件的拥有者改为指定的用户或组,用户可以是用户名或者用户ID:组可以是组名或者组ID:文件是以空格分开的要改变权限的文件列表,支持通配符.系统管理员经常使用chown命令,在将文件拷贝 ...
- 【Thinkphp 5】auth权限设置以及实现
1.将auth类下载好 放置目录: extend\auth\auth.php 2.将类中的SQL语句执行,可以在数据库中创建3张表 auth_group(用户组表) auth_ru ...
- 《.NET 设计规范》第 9 章:常用的设计模式
第 9 章:常用的设计模式 9.1 聚合组件 考虑为常用的特性域提供聚合组件. 要用聚合组件来对高层的概念(物理对象)进行建模,而不是对系统级的任务进行建模. 要让聚合组件的名字与众所周知的系统实体相 ...
- Go语言入门——dep入门
本文出现了大量maven的内容,更适合java程序员阅读,如果你的语言做依赖管理的方案与maven差异很大,可能在有些地方会不理解 从很久之前go语言在依赖解决和管理方面方案的匮乏就被不少人诟病.光指 ...
- 关于异步IO与同步IO的写操作区别
最近这两天都在看IO相关的知识点.一开始太凌乱,太杂,不过终于整理清楚了.觉得杂乱是因为一开始以为异步IO等于非阻塞IO,这完全是两个概念, LINUX下的异步IO有两类,一类为glibc AIO,这 ...