Communication System
Time Limit: 1000MS   Memory Limit: 10000K
Total Submissions: 28273   Accepted: 10074

Description

We have received an order from Pizoor Communications Inc. for a special communication system. The system consists of several devices. For each device, we are free to choose from several manufacturers. Same devices from two manufacturers differ in their maximum bandwidths and prices. 
By overall bandwidth (B) we mean the minimum of the bandwidths of the chosen devices in the communication system and the total price (P) is the sum of the prices of all chosen devices. Our goal is to choose a manufacturer for each device to maximize B/P. 

Input

The first line of the input file contains a single integer t (1 ≤ t ≤ 10), the number of test cases, followed by the input data for each test case. Each test case starts with a line containing a single integer n (1 ≤ n ≤ 100), the number of devices in the communication system, followed by n lines in the following format: the i-th line (1 ≤ i ≤ n) starts with mi (1 ≤ mi ≤ 100), the number of manufacturers for the i-th device, followed by mi pairs of positive integers in the same line, each indicating the bandwidth and the price of the device respectively, corresponding to a manufacturer.

Output

Your program should produce a single line for each test case containing a single number which is the maximum possible B/P for the test case. Round the numbers in the output to 3 digits after decimal point. 

Sample Input

1 3
3 100 25 150 35 80 25
2 120 80 155 40
2 100 100 120 110

Sample Output

0.649

一道醉人题。。。输出时用printf("%.3f",res); 第一次做wa以为思路出现了偏差。。。然后换了个思路做了一遍。。。两次都卡了
好久。。。还有就是没有数据规模。。。 自己的思路:
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdlib.h>
using namespace std;
#define N 105 struct Dev
{
int width,price;
} dev[N][N]; Dev dp1[N][N];
double dp2[N][N]; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,num[];
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&num[i]);
for(int j=; j<=num[i]; j++)
scanf("%d%d",&dev[i][j].width,&dev[i][j].price);
}
for(int i=; i<=num[]; i++)
{
dp1[][i].price=dev[][i].price;
dp1[][i].width=dev[][i].width;
dp2[][i]=dp1[][i].width/(double)dp1[][i].price;
}
for(int i=; i<=n; i++)
for(int j=; j<=num[i]; j++)
{
dp2[i][j]=;
for(int k=; k<=num[i-]; k++)
{
int width=min(dp1[i-][k].width,dev[i][j].width);
int price=dp1[i-][k].price+dev[i][j].price;
if(width/(double)price-dp2[i][j]>1e-)
{
dp2[i][j]=width/(double)price;
dp1[i][j].width=width;
dp1[i][j].price=price;
}
else if(abs(width/(double)price-dp2[i][j])<1e-)
{
if(width>dp1[i][j].width)
{
dp1[i][j].width=width;
dp1[i][j].price=price;
}
}
}
}
double res=;
for(int i=;i<=num[n];i++)
if(dp2[n][i]>res)
res=dp2[n][i];
printf("%.3f\n",res);
}
return ;
}
题解思路:
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 105
#define INF 999999999 struct Dev
{
int width,price;
} dev[N][N]; int dp[N][]; int main()
{
int t;
scanf("%d",&t);
while(t--)
{
memset(dp,,sizeof(dp));
int n,num[];
scanf("%d",&n);
for(int i=; i<=n; i++)
{
scanf("%d",&num[i]);
for(int j=; j<=num[i]; j++)
scanf("%d%d",&dev[i][j].width,&dev[i][j].price);
}
for(int i=;i<=n;i++)
for(int j=;j<=;j++)
dp[i][j]=INF;
for(int i=; i<=num[]; i++)
dp[][dev[][i].width]=min(dev[][i].price,dp[][dev[][i].width]);
for(int i=; i<=n; i++)
for(int j=; j<=num[i]; j++)
{
for(int k=; k<=; k++)
{
if(dp[i-][k]==INF)
continue;
if(k<=dev[i][j].width)
dp[i][k]=min(dp[i-][k]+dev[i][j].price,dp[i][k]);
else
dp[i][dev[i][j].width]=min(dp[i-][k]+dev[i][j].price,dp[i][dev[i][j].width]);
}
}
double res=;
for(int i=; i<=; i++)
{
if(dp[n][i]==INF)
continue;
//cout<<i/(double)dp[n][i]<<endl;
if(i/(double)dp[n][i]>res)
res=i/(double)dp[n][i];
}
printf("%.3f\n",res);
}
return ;
}
												

POJ_1018_(dp)的更多相关文章

  1. BZOJ 1911: [Apio2010]特别行动队 [斜率优化DP]

    1911: [Apio2010]特别行动队 Time Limit: 4 Sec  Memory Limit: 64 MBSubmit: 4142  Solved: 1964[Submit][Statu ...

  2. 2013 Asia Changsha Regional Contest---Josephina and RPG(DP)

    题目链接 http://acm.hdu.edu.cn/showproblem.php?pid=4800 Problem Description A role-playing game (RPG and ...

  3. AEAI DP V3.7.0 发布,开源综合应用开发平台

    1  升级说明 AEAI DP 3.7版本是AEAI DP一个里程碑版本,基于JDK1.7开发,在本版本中新增支持Rest服务开发机制(默认支持WebService服务开发机制),且支持WS服务.RS ...

  4. AEAI DP V3.6.0 升级说明,开源综合应用开发平台

    AEAI DP综合应用开发平台是一款扩展开发工具,专门用于开发MIS类的Java Web应用,本次发版的AEAI DP_v3.6.0版本为AEAI DP _v3.5.0版本的升级版本,该产品现已开源并 ...

  5. BZOJ 1597: [Usaco2008 Mar]土地购买 [斜率优化DP]

    1597: [Usaco2008 Mar]土地购买 Time Limit: 10 Sec  Memory Limit: 162 MBSubmit: 4026  Solved: 1473[Submit] ...

  6. [斜率优化DP]【学习笔记】【更新中】

    参考资料: 1.元旦集训的课件已经很好了 http://files.cnblogs.com/files/candy99/dp.pdf 2.http://www.cnblogs.com/MashiroS ...

  7. BZOJ 1010: [HNOI2008]玩具装箱toy [DP 斜率优化]

    1010: [HNOI2008]玩具装箱toy Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 9812  Solved: 3978[Submit][St ...

  8. px、dp和sp,这些单位有什么区别?

    DP 这个是最常用但也最难理解的尺寸单位.它与“像素密度”密切相关,所以 首先我们解释一下什么是像素密度.假设有一部手机,屏幕的物理尺寸为1.5英寸x2英寸,屏幕分辨率为240x320,则我们可以计算 ...

  9. android px转换为dip/dp

    /** * 根据手机的分辨率从 dp 的单位 转成为 px(像素) */ public int dipTopx(Context context, float dpValue) { final floa ...

随机推荐

  1. openstack-glance-api.service start request repeated too quickly, refusing to start

    问题描写叙述 openstack J版 centos7部署 重新启动服务时起不来,日志也不报错.以glance服务为例,例如以下: # systemctl start openstack-glance ...

  2. [Java][Android] 多线程同步-主线程等待全部子线程完毕案例

    有时候我们会遇到这种问题:做一个大的事情能够被分解为做一系列相似的小的事情,而小的事情无非就是參数上有可能不同样而已! 此时,假设不使用线程,我们势必会浪费许多的时间来完毕整个大的事情.而使用线程的话 ...

  3. Cocos2d-x学习笔记(12)(CCControlSwitch开关、CCControlSlider滑动条、CCControlButtonbutton)

    CCEditBox.CCControlSwitch.CCControlSlider.CCControlColourPicker.CCControlButton等都是Cocos2d-x 2.x的最新UI ...

  4. java web中的session属性范围和request属性范围

    首先必需要了解client跳转和server端跳转的差别: client跳转: response.sendRedict(String path).地址栏发生改变. 不能传递request属性. ser ...

  5. IE7下兼容问题总结

    1.<LI> border-bottom 不显示 解决办法 加个height:100%; 2.border:none;不好使,要用 border:0;

  6. easyUI datagrid 时间格式化

    从后台传过来的数据,其中含有日期字段,那么在前端的easyUI这里显示的话,会显得比较怪异,一大串,中间是个T,后面一大堆零,不知道是什么意思. 看来要进行格式化. 问题是,在哪里格式化? 如果在后端 ...

  7. YTU 2629: E1 一种颜色,三个分量

    2629: E1 一种颜色,三个分量 时间限制: 1 Sec  内存限制: 128 MB 提交: 300  解决: 226 题目描述 在计算机中,常用三种基色红(R).绿(G).蓝(B)的混合来表示颜 ...

  8. ASP.NET和C#的区别/

    1..NET是一个平台,一个抽象的平台的概念. .NET平台其本身实现的方式其实还是库,抽象层面上来看是一个平台. 个人理解.NET核心就只是.NET Framework. .NET Framewor ...

  9. missing required source folder

    Eclipse 中XXX is missing required source folder 问题的解决 https://blog.csdn.net/itzhangdaopin/article/det ...

  10. 【USACO 2008FEB】 旅馆

    [题目链接] 点击打开链接 [算法] 线段树 对于一个节点,记录它从左端点延伸的最多的空房间的个数,从右端点延伸的最多的空房间个数,和该区间最多的连续 空房间个数 [代码] #include<b ...