poj 1018 Communication System_贪心
题意:给你n个厂,每个厂有m个产品,产品有B(带宽),P(价格),现在要你求最大的 B/P
明显是枚举,当P大于一定值,B/P为零,可以用这个剪枝
#include <iostream>
#include<cstring>
#include<cstdio>
using namespace std;
#define N 110
#define INF 0xffffff
int devb[N][N],devp[N][N];
int b[N*100],tb; int main(int argc, char** argv) {
int n,mi[N],i,j,t;
int blen,minprice,sum,minb,maxb,curb;
double dmax,tvalue;
scanf("%d",&t);
while(t--){
scanf("%d",&n);
blen=0;
for(i=0;i<n;i++){
scanf("%d",&mi[i]);
for(j=0;j<mi[i];j++){
scanf("%d%d",&devb[i][j],&devp[i][j]);
b[blen++]=devb[i][j];
if(minb>=devb[i][j])
minb=devb[i][j];
if(maxb<=devb[i][j])
maxb=devb[i][j];
}
}
dmax=0;
for(tb=minb;tb<=maxb;tb++){
sum=0;
curb=INF;
for(i=0;i<n;i++){
minprice=INF;
for(j=0;j<mi[i];j++){
if(devb[i][j]>=tb&&devp[i][j]<minprice){
minprice=devp[i][j];
if(curb>devb[i][j])
curb=devb[i][j];
}
}
if(minprice==INF)
break;
sum+=minprice;
}
if(i==n){
tvalue=(double)curb/sum;
if(tvalue>dmax)
dmax=tvalue;
tb=curb+1;
}else
break;
}
printf("%.3f\n",dmax);
}
return 0;
}
poj 1018 Communication System_贪心的更多相关文章
- POJ 1018 Communication System 贪心+枚举
看题传送门:http://poj.org/problem?id=1018 题目大意: 某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m个厂家提供生产,而每个厂家生产的同种设备都 ...
- POJ 1018 Communication System(树形DP)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- poj 1018 Communication System 枚举 VS 贪心
Communication System Time Limit: 1000MS Memory Limit: 10000K Total Submissions: 21631 Accepted: ...
- POJ 1018 Communication System(贪心)
Description We have received an order from Pizoor Communications Inc. for a special communication sy ...
- POJ 1018 Communication System(DP)
http://poj.org/problem?id=1018 题意: 某公司要建立一套通信系统,该通信系统需要n种设备,而每种设备分别可以有m1.m2.m3.....mn个厂家提供生产,而每个厂家生产 ...
- 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,还可能我剪枝不够. 想了非常久,无奈忍不住偷看了下提示.发现方法真多.有贪心,DP,有高级剪枝的.还有三分法的.八仙过海各 ...
随机推荐
- 【转】如何定制android源码的编译选项 & 后期安装? ---- 不错
原文网址:http://blog.sina.com.cn/s/blog_3e3fcadd0100z3o9.html Android编译过程比较长,配置起来也很麻烦.现仅就工作遇到的问题做个总结.所用硬 ...
- 使用sp_configure启用 'Ad Hoc Distributed Queries'
使用sp_configure启用 'Ad Hoc Distributed Queries' 原文地址:http://blog.sina.com.cn/s/blog_531bb7630100xh88.h ...
- cc150 Chapter 2 | Linked Lists 2.5 add two integer LinkedList, return LinkedList as a sum
2.5 You have two numbers represented by a linked list, where each node contains a single digit. The ...
- hdu 2079 选课时间_母函数
题意:需要学够n学分,有k个情况(x学分,y个相同学分的课) 解法:套母函数模板 #include <iostream> #include<cstdio> using name ...
- 三十一、Java图形化界面设计——布局管理器之GridLayout(网格布局)
摘自http://blog.csdn.net/liujun13579/article/details/7772491 三十一.Java图形化界面设计--布局管理器之GridLayout(网格布局) 网 ...
- 456. 132 Pattern
456. 132 Pattern Given an array of integers a1, a2, a3-an, judge if there exists the 132 pattern. 13 ...
- ZOJ1372 POJ 1287 Networking 网络设计 Kruskal算法
题目链接:problemCode=1372">ZOJ1372 POJ 1287 Networking 网络设计 Networking Time Limit: 2 Seconds ...
- Android 之 Gallery
1 在 xml 布局中添加 Gallery activity_main.xml <LinearLayout xmlns:android="http://schemas.andro ...
- mock server相关解决方案
前后端分离之后 前后端分离后, 大家从此进入了所谓的并行开发时代. 一旦完成前后端的(边界)分工, 大家就可以各司其职了. 前端在与后端交互时, 要想有效地提高工作效率, 后端的接口文档就是重中之重了 ...
- 使用 React和webpack开发和打包发布
建议在 React 中使用 CommonJS 模块系统,比如 browserify 或 webpack,本次使用 webpack. 第一步.安装全局包 $ npm install babel -g $ ...