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> ...
随机推荐
- 新版Azure Automation Account 浅析(二) --- 更新Powershell模块和创建Runbook
前篇我们讲了怎样创建一个自动化账户以及创建时候"Run As Account"选项背后的奥秘.这一篇针对在Azure自动化账户中使用Powershell Runbook的用户讲一下 ...
- HEXO+Github,搭建属于自己的博客
摘录自:http://www.jianshu.com/p/465830080ea9 1. github的准备 账号 密码 建立Repository建立与你用户名对应的仓库,仓库名必须为[your_us ...
- hive(II)--sql考查的高频问题
在了解别人hive能力水平的时候,不管是别人问我还是我了解别人,有一些都是必然会问的东西.问的问题也大都大同小异.这里总结一下我遇到的那些hive方面面试可能涉及的问题 1.行转列(列转行) 当我们建 ...
- javascript属性操作
属性的读写 //属性添加 var obj = {x:1,y:2}; obj.z = 3; obj["m"] = 4; //属性的读取 var obj = {x: 1, y: 2, ...
- android软键盘的显示和隐藏
显示: InputMethodManager imm = (InputMethodManager) getSystemService(INPUT_METHOD_SERVICE); imm.toggle ...
- 《CSS动画实用技巧》课程笔记
概述 这是我学习[CSS动画实用技巧][1]的课程笔记 常用动画属性--transition [常用动画属性--transition][2] .change img{ display:block; w ...
- TCP粘包和拆包问题
问题产生 一个完整的业务可能会被TCP拆分成多个包进行发送,也有可能把多个小的包封装成一个大的数据包发送,这个就是TCP的拆包和封包问题. 下面可以看一张图,是客户端向服务端发送包: 1. 第一种情况 ...
- vue调试神器vue-devtools安装
vue-devtools安装 vue-devtools是一款用来调试Vue应用的Chrome插件,可极大提高开发者调试项目效率,接着我们说一下如何下载安装这个插件; 一. 从chrome商店直接下载安 ...
- 通过重写 class 的 ToString() 来简化获取 enum 的 DescriptionAttribute 值
通过重写 class 的 ToString() 来简化获取 enum 的 DescriptionAttribute 值 目录 一.常见的 enum 类型 二.演变:class 版本的 enum 类型 ...
- mongodb- Java API 查询操作
package com.x.mongodb; import java.net.UnknownHostException;import java.util.Collection;import java. ...