POJ 1018 Communication System (枚举)
来源:互联网 发布:阿里云elb 编辑:程序博客网 时间:2024/04/30 09:41
~~~题目链接~~~
题目大意:现有n个通讯点, 要从n家通讯商那,每个通讯商中选出一个设备, 要求所选设备的带宽中最小的做为最小带宽B, 总价格为P, 现在要求求出B/P的值最大
思路:依次枚举B能到的值
code:
#include <stdio.h>#include <algorithm>#define inf 0x7fffffffusing namespace std;struct node{ int w, v;}p[102][102];int main(){ // freopen("input.txt", "r", stdin); int i = 0, j = 0, k = 0, n = 0, t = 0, price = 0, max = 0, min = inf; int m[102]; double ans = 0; scanf("%d", &t); while(t--) { scanf("%d", &n); min = inf; max = 0; for(i = 0; i<n; i++) { scanf("%d", &m[i]); for(j = 0; j<m[i]; j++) { scanf("%d %d", &p[i][j].w, &p[i][j].v); if(min>p[i][j].w) min = p[i][j].w; if(max<p[i][j].w) max = p[i][j].w; } } int flag = 0; ans = -1; for(i = min; i<=max; i++) { double sum = 0; for(k = 0; k<n; k++) { price = inf; flag = 0; for(j = 0; j<m[k] ; j++) { if(p[k][j].w>=i && price>p[k][j].v) { flag = 1; price = p[k][j].v; } } if(!flag) break;//在这组中没有可选的 sum += price; } if(!flag) break; if(ans<(double)i/sum) ans = (double)i/sum; } printf("%.3lf\n", ans); } return 0;}
- poj 1018 Communication System(枚举)
- POJ 1018 Communication System (枚举)
- poj 1018 Communication System (枚举+贪心)
- POJ 1018 Communication System(枚举)
- POJ 1018 - Communication System (枚举)
- POJ 1018 Communication System [枚举]
- POJ 1018 Communication System(枚举)
- poj 1018 Communication System(枚举+贪心)
- POJ 1018 Communication System 贪心+枚举
- poj 1018 Communication System 枚举 VS 贪心
- POJ 1018 Communication System (枚举+贪心)
- poj 1018 Communication System
- POJ 1018 Communication System
- poj 1018 Communication System
- POJ 1018 Communication System
- POJ 1018 Communication System
- POJ 1018 Communication System
- poj 1018 Communication System
- struts使用默认action时与通配符的冲突!
- dig理解DNS的解析过程
- Android 4.0 Launcher源码分析系列
- iOS开发——图片转PDF的实现方法
- 一个简单的wifi状态提示广播
- POJ 1018 Communication System (枚举)
- 友坚Android210支持LVDS 1024*600 10.1寸高清屏
- zoj - 1203 - Swordfish
- 备注sql
- 程序员能力矩阵(转)_找到自我定位和缺点
- poj 1459Power Network_ http://poj.org/problem?id=1459
- 一款不错的护眼软件
- 4.1.5 交叉编译示例程序并在mini6410上运行
- libnids抓包