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,有高级剪枝的.还有三分法的.八仙过海各 ...
随机推荐
- 【原创整理,基于JavaScript的创建对象方式的集锦】
以下4种方式,是我在项目中最常见的JavaScript的面向对象的方式的开发. 测试一般在微软的工具:http://www.typescriptlang.org/Playground 进行测试,或者使 ...
- Android 匿名共享内存Java接口分析
在Android 匿名共享内存驱动源码分析中介绍了匿名共享内存的驱动实现过程,本文在Android匿名共享内存驱动基础上,介绍Android匿名共享内存对外Android系统的匿名共享内存子系统的主体 ...
- Pascal's Triangle II 解答
Question Given an index k, return the kth row of the Pascal's triangle. For example, given k = 3,Ret ...
- LeeCode-Pow(x, n)
Implement pow(x, n). double myPow(double x, int n) { ) return 1.0; ) return 1.0/pow(x,-n); ); }
- python多线程简单例子
python多线程简单例子 作者:vpoet mail:vpoet_sir@163.com import thread def childthread(threadid): print "I ...
- ftp报错 200 port command successful. consider using pasv 425 failed to establish connection
最近在公司做的项目是需要在客户端录制视频,然后通过ftp传到服务器端.客户端是windows,服务器端linux.今天用新的电脑配置好项目之后,测试数据传输时出现了“200 port command ...
- The Java™ Tutorials下载地址
1.The Java™ Tutorials下载地址: http://www.oracle.com/technetwork/java/javase/java-tutorial-downloads-200 ...
- CDH 2、Cloudera Manager的安装
1.Cloudera Manager • Cloudera Manager是一个管理CDH的端到端的应用. • 作用: – 管理 – 监控 – 诊断 – 集成 • 架构 • Server – 管理控制 ...
- python语言磁力搜索引擎源码公开,基于DHT协议
原文地址: http://www.cnblogs.com/huangxie/p/5550680.html
- Back to Underworld(搜索)
Back to Underworld Time Limit:4000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Su ...