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. FlashBuilder 4.7 非正常关闭导致的不能启动的解决的方法

    停电.或者卡死.FB就不能正常启动了. 以下是老外给出的方法,好用: 进入.metadata/.plugins/org.eclipse.core.resources 文件夹 删除.snap文件 假设是 ...

  2. react 项目实战(八)图书管理与自动完成

    图书管理 src / pages / BookAdd.js   // 图书添加页 /** * 图书添加页面 */ import React from 'react'; // 布局组件 import H ...

  3. 在弱网传输的情况下,是怎么做到节约流量的(面试小问题,Android篇)

    立即毕业了,在毕业之际.我辞掉了曾经的实习工作,主要是工作内容不太感兴趣.近期在找工作.主要是找Java和Android方面的工作.自以为学得不错.可是面试屡屡受挫. 先提一下问到的一些问题吧. 第一 ...

  4. 2016/2/22 1、Window.document对象

    1.Window.document对象 一.找到元素: docunment.getElementById("id"):根据id找,最多找一个:     var a =docunme ...

  5. iOS开发——优化篇—— 25个性能优化/内存优化常用方法

    1. 用ARC管理内存 ARC(Automatic ReferenceCounting, 自动引用计数)和iOS5一起发布,它避免了最常见的也就是经常是由于我们忘记释放内存所造成的内存泄露.它自动为你 ...

  6. ios30---pthread, NSThread, GCD, NSOperation

    pthread(线程库,很早就有的技术,了解):一套通用的多线程API适用于Unix\Linux\Windows等系统(java开发也有pthread)跨平台\可移植使用难度大(全是C函数) C语言 ...

  7. 【CSU 1079】树上的查询

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1079 现有一棵有N个顶点的树,顶点的标号分别为1, 2, …, N.对于每个形如a b k的询问, ...

  8. linux下的C语言开发 GDB的例子

    在很多人的眼里,C语言和linux常常是分不开的.这其中的原因很多,其中最重要的一部分我认为是linux本身就是C语言的杰出作品.当然,linux操作系统本身对C语言的支持也是相当到位的.作为一个真正 ...

  9. 词典(一) 跳转表(Skip table)

    词典,顾名思义,就是通过关键码来查询的结构.二叉搜索树也可以作为词典,不过各种BST,如AVL树.B-树.红黑树.伸展树,结构和操作比较复杂,而且理论上插入和删除都需要O(logn)的复杂度. 在词典 ...

  10. 【转载】Java - Wait & Notify

    [本文转自]http://www.cnblogs.com/dolphin0520/p/3920385.html 这三个方法的文字描述可以知道以下几点信息: 1)wait().notify()和noti ...