Lazier Salesgirl

Time Limit: 2 Seconds Memory Limit: 65536 KB

Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling. She can sell the i-th customer a piece of bread for price pi. But she is so lazy that she will fall asleep if no customer comes to buy bread for more than w minutes. When she is sleeping, the customer coming to buy bread will leave immediately. It’s known that she starts to sell bread now and the i-th customer come after ti minutes. What is the minimum possible value of w that maximizes the average value of the bread sold?

Input

There are multiple test cases. The first line of input is an integer T ≈ 200 indicating the number of test cases.

The first line of each test case contains an integer 1 ≤ n ≤ 1000 indicating the number of customers. The second line contains n integers 1 ≤ pi ≤ 10000. The third line contains n integers 1 ≤ ti ≤ 100000. The customers are given in the non-decreasing order of ti.

Output

For each test cases, output w and the corresponding average value of sold bread, with six decimal digits.

Sample Input

2

4

1 2 3 4

1 3 6 10

4

4 3 2 1

1 3 6 10

Sample Output

4.000000 2.500000

1.000000 4.000000

枚举

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm> using namespace std;
int n;
int p[1005];
int t[1005];
int w;
int main()
{
int t1;
scanf("%d",&t1);
while(t1--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&p[i]);
int num1=0;
int num2=100000;
t[0]=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&t[i]);
num1=max(num1,t[i]-t[i-1]);
num2=min(num2,t[i]-t[i-1]);
}
int pos=1;
double res=0;
double ans;
for(w=num2;w<=num1;w++)
{
int sum=0;int num=0;
int time=w;
for(int i=1;i<=n;i++)
{
if(t[i]<=time)
{
sum+=p[i];
num++;
time=t[i]+w;
}
else
{
break;
}
}
double av=1.0*sum/num;
if(res<av)
{
res=av;
ans=w;
} }
printf("%.6f %.6f\n",ans,res); }
return 0;
}

ZOJ 3607 Lazier Salesgirl (枚举)的更多相关文章

  1. ZOJ 3607 Lazier Salesgirl(贪心)

    题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607 题意:一个卖面包的小姑娘,给第i个来买面包的人的价格是pi, ...

  2. ZOJ 3607 Lazier Salesgirl 贪心

    这个题比上个题简单得多,也是超过W时间会睡着,睡着就再也不会卖了,顾客按时间顺序来的,但是可能有顾客同时到(同时到如果醒着就全卖了),并且每个人只买一块面包,也是求最大的W,使得卖出面包的平均价格最高 ...

  3. ZOJ 3607 Lazier Salesgirl

    Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling ...

  4. zjuoj 3607 Lazier Salesgirl

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607 Lazier Salesgirl Time Limit: 2 Sec ...

  5. H - Lazier Salesgirl

    Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practic ...

  6. ZOJ 3607贪心算法

    http://blog.csdn.net/ffq5050139/article/details/7832991 http://blog.watashi.ws/1944/the-8th-zjpcpc/ ...

  7. [ACM_模拟][ACM_暴力] Lazier Salesgirl [暴力 懒销售睡觉]

    Description Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making ...

  8. ZOJ 3606 Lazy Salesgirl 浙江省第九届省赛

    Lazy Salesgirl Time Limit: 5 Seconds      Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who ma ...

  9. H - 【59】Lazier Salesgirl 模拟//lxm

    Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling ...

随机推荐

  1. 【ActiveMQ】ActiveMQ在Windows的安装,以及点对点的消息发送案例

    公司最近会用MQ对某些业务进行处理,所以,这次我下载了apache-activemq-5.12.0-bin把玩下. 基于练习方便需要,使用Windows的版本. 参考的优秀文章: activemq的几 ...

  2. Qt学习过程中遇到的问题

    由于工作需要,开始使用Qt,由于在网上找的教程文档时针对qt3的,所以在学习的过程遇到了许多由于版本不一致造成的问题,因此记录下来. 参考的文档是:Qt入门教程 详细讲解版 本机Qt版本为:Qt5.3 ...

  3. cloudera-manager-installer.bin不生成repo文件

    [转] 运行cloudera-manager-installer.bin,并在后边增加参数使其不再在/etc/yum.repo.d/下生成cloudera-manager.repo文件 ./cloud ...

  4. FMC—扩展外部 SDRAM

    本章参考资料:< STM32F4xx 参考手册 2>.< STM32F4xx 规格书>.库帮助文档< stm32f4xx_dsp_stdperiph_lib_um.chm ...

  5. GPIO 输入—按键检测

    这里要用到一定的模电知识.电容两端电压不能突变,电感两端电流不能突变.这里利用了电容的放电延时实现硬件消抖.按键按下会有抖动,波形有毛刺,使得高低电平显现不明显,而按键按下时,电容放电一下,马上又被充 ...

  6. sql 记录

    INSERT INTO B([name],[info]) SELECT [name,'10'] FROM A 级联更新1:update tb1, tb2 set tb1.a=tb2.a,tb1.b=t ...

  7. osgi实战学习之路:6. Service-1

    什么是Service? 它是注冊到osgi的一个java对象 Service注冊: 通过BundleContext::registerService(java.lang.String[] clazze ...

  8. 理解vertical-align或“如何竖向居中”<转>

    在各种技术论坛里经常会有这样的问题提出,“我如何能将这个东西竖向居中?”这个问题通常会跟随着这样一句话,“我使用了 vertical-align:middle,但是不管用! ” 这个问题其实有三个层面 ...

  9. CSS——伪元素

    CSS伪元素 伪元素的语法: selector:pseudo-element {property:value;} 作    用 添加特殊样式 :first-line 伪元素 "first-l ...

  10. EasyUI 另一种form提交方式

    (function ($) { window.XW = {}; //全局系统对象 //异步请求统一调用方法 XW.ajax = function (options, param, callback) ...