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> ...
随机推荐
- Red Hat
同义词 REDHAT一般指Red Hat Red Hat(红帽)公司(NYSE:RHT)是一家开源解决方案供应商,也是标准普尔500指数成员.总部位于美国北卡罗来纳州的罗利市,截止2015年3月3日, ...
- 邓_Excal
--------------------------------------------------------------------- 快速输入固定文字 有一些固定的词组,输入 1 个.2 个,貌 ...
- 【转】WPF 从FlowDocument中找到Hyperlink
原文地址:How can I get a FlowDocument Hyperlink to launch browser and go to URL in a WPF app? #region Ac ...
- linux_inode和block
linux里一切皆文件 什么是文件属性? 文件本身带有的信息, 包括:索引节点编号. 文件类型以及权限.硬链接个数(备份作用).所有者.所属组.文件大小.修改月.修改日.时分 151387 -rw-- ...
- logback使用配置详解
title: logback使用配置详解 date: 2017-04-25 16:42:49 tags: 日志 --- 1.介绍 Logback是由log4j创始人设计的另一个开源日志组件,它当前分为 ...
- POI--HSSFCell类
用POI创建单元格,使用「HSSFCell」类 该类包含三个构造方法. protected HSSFCell(Workbook book, Sheet sheet, int row, CellVal ...
- 四、Html常用标签
1,列表相关标签 <ul>:定义无序列表,只能包含<li>子元素 <ol>:定义有序列表,只能包含<li>子元素,因为这个标签是有序的,所有这个标签还有 ...
- getResource()和getSystemResource()分析
1. getClass().getResource() 第一步,getClass().getResource(path)是有一个路径参数的,这个路径会先被转换成"类所在的包名称+path&q ...
- java Object类是可以接收集合类型的
废话不多说,上代码: package com.core.test; import java.util.ArrayList; import java.util.HashMap; import java. ...
- iOS项目——自定义UITabBar与布局
在上一篇文章iOS项目——基本框架搭建中,我们详细说明了如何对TabBarItem的图片属性以及文字属性进行一些自定义配置.但是,很多时候,我们需要修改TabBarItem的图片和文字属性之外,还需要 ...