ZOJ 1409 Communication System(枚举 + 贪心)
来源:互联网 发布:阿里伯克 052d数据对比 编辑:程序博客网 时间:2024/05/21 21:36
题目大意:有n种设备,每种有mi件,每件设备有一个带宽和价格,从每种设备中选一件,使得带宽B/总价格P的值最大。B为挑选的n件设备中带宽最小的设备的带宽,P为n件设备的总价格。
解题思路:要求最大的带宽价值比,只需让带宽尽可能的大,总价格尽可能的小就行。所以可以枚举所有可能的带宽,然后从选出n件设备,每种设备贪心选择满足带宽限制的价格最小的,这样能保证总价格最小。
#include <cstdio>#include <algorithm>using namespace std;const int INF = 0x3f3f3f3f;int main() {int T, N;scanf("%d", &T);while (T--) {scanf("%d", &N);int B[105][105], P[105][105], M[105];int min_B = INF, max_B = 0;for (int i = 0; i < N; i++) {scanf("%d", &M[i]);for (int j = 0; j < M[i]; j++) {scanf("%d%d", &B[i][j], &P[i][j]);min_B = min(min_B, B[i][j]);max_B = max(max_B, B[i][j]);}}double ans = 0;for (; min_B <= max_B; min_B++) {double sum = 0;for (int i = 0; i < N; i++) {int min_P = INF; for (int j = 0; j < M[i]; j++)if (B[i][j] >= min_B)min_P = min(min_P, P[i][j]);if (min_P == INF) goto end;sum += min_P;}ans = max(ans, min_B / sum);}end:printf("%.3lf\n", ans);}return 0;}
0 0
- ZOJ 1409 Communication System(枚举 + 贪心)
- ZOJ 1409 Communication System(枚举 + 贪心)
- zoj1409 Communication System (贪心+枚举)
- zoj 1409 Communication System
- ZOJ 1409 Communication System
- ZOJ 1409 Communication System
- poj 1018 Communication System(枚举+贪心)
- POJ 1018 Communication System 贪心+枚举
- poj 1018 Communication System 枚举 VS 贪心
- poj 1018 Communication System (枚举+贪心)
- POJ 1018 Communication System (枚举+贪心)
- 1018 Communication System - 贪心
- ZOJ1409 Communication System贪心
- 贪心算法--Communication System
- POJ 1018 Communication System [枚举]
- 1018 Communication System 枚举+剪枝
- POJ 1018 Communication System(枚举)
- [POJ1018]Communication System(贪心)
- STL中的multimap---顺便说说如何查找同一关键字对应的所有值(利用count, lower_bound/upper_bound, equal_range)
- Search Insert Position -LeetCode
- 黄金分割数
- Mongodb Linux安装
- hdu1847Good Luck in CET-4 Everybody! 博弈
- ZOJ 1409 Communication System(枚举 + 贪心)
- 神奇算式
- POJ 1046 Color Me Less
- 一个新的开始?
- 工作周记
- 关于COIDE的各种小技巧
- 使用storyboard,设置tab bar Item的选中图片(selected Image)
- 记一次线程堵塞
- hdu 4353 Finding Mine 计算几何