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,有高级剪枝的.还有三分法的.八仙过海各 ...
随机推荐
- 【Xamarin挖墙脚系列:关闭 OS X El Capitan 中 SIP 安全设置功能】
比如需要修改内核配置文件: com.apple.Boot.plist 那么我们需要解锁权限. 禁止SIP模式,那么就可以修改此文件了. 在 OS X El Capitan 中有一个跟安全相关的模式叫 ...
- shell printf格式化输出语句
printf 命令用于格式化输出, 是echo命令的增强版.它是C语言printf()库函数的一个有限的变形,并且在语法上有些不同. 注意:printf 由 POSIX 标准所定义,移植性要比 ech ...
- Linux下(主要针对Ubuntu)下桌面分辨率的添加
系统版本: Linux (Ubuntu) 其他桌面发行版应该也行. 相关命令: lspci, cvt, xrandr 在桌面分辨率不正常显示桌面或者没有最佳的分辨率时,需要修改添加适合的桌面分辨率模式 ...
- Quartz.NET作业调度框架详解
Quartz.NET作业调度框架详解 http://www.cnblogs.com/lmule/archive/2010/08/28/1811042.html
- Contains Duplicate II 解答
Question Given an array of integers and an integer k, find out whether there are two distinct indice ...
- 有序线性搜索(Sorted/Ordered Linear Search)
如果数组元素已经排过序(升序),那我们搜索某个元素就不必遍历整个数组了.在下面给出的算法代码中,到任何一点,假设当前的arr[i]值大于搜索的值data,就可以停止搜索了. #include<s ...
- Java连接各类数据库
几种常用数据库的连接,以及Dao层的实现. 1.加载JDBC驱动: 1 加载JDBC驱动,并将其注册到DriverManager中: 2 //MySQL数据库 3 Class.forName(&quo ...
- Collections你用对了吗?
.Net有两类基础的集合类型:List和Dictionary.List是基于Index的,Dictionary是基于key的.集合类型一般实现了IEnumberable,ICollection或者Il ...
- UGUI实现的虚拟摇杆,可改变摇杆位置
实现方式主要参考这篇文章:http://www.cnblogs.com/plateFace/p/4687896.html. 主要代码如下: using UnityEngine; using Syste ...
- [生成树][Uva1395][Slim Span]
代码: #include <set> #include <queue> #include <cmath> #include <cstdio> #incl ...