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

Description

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 题目大意就是一个买面包的小姑凉想偷懒,在卖到第i个人的时候,就会在一个之前维持的最大间隔时间内(如果在这个时间内没人来买面包的)她会一睡不醒。但又要满足能否去到最大平均值。
总体来说,这道题有两个条件:平均值最大,并且能一睡不醒。
 #include<cstdio>
#include<string.h>
using namespace std;
double p[];
double time[];
double maxt[];
double max(double a,double b)
{
return a>b?a:b;
}
int main()
{
int t,n;
double w;
double flag;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%lf",&p[i]);
for(int i=;i<=n;i++)
scanf("%lf",&time[i]);
time[]=;
maxt[]=time[]-time[];
for(int i=;i<=n;i++)
maxt[i]=max(time[i]-time[i-],maxt[i-]);//算出到第i个人时的前面的最大间隔时间
double maxn=;//最大平均值
double anst=;//间隔时间
double sum=;
for(int i=;i<=n;i++)//暴力枚举
{
w=maxt[i];
sum+=p[i];
if(i==n)
{
if(sum/i>maxn)
{
maxn=sum/i;
flag=w;
break;
}
}
if(sum/i>maxn&&w<time[i+]-time[i])//要保证他卖给第i个人后能睡觉
{
maxn=sum/i;
flag=w;
} }
printf("%.6lf %.6lf\n",flag,maxn);
}
return ;
}

H - Lazier Salesgirl的更多相关文章

  1. ZOJ 3607 Lazier Salesgirl (枚举)

    Lazier Salesgirl Time Limit: 2 Seconds Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who makes ...

  2. zjuoj 3607 Lazier Salesgirl

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

  3. 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 ...

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

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

  5. ZOJ 3607 Lazier Salesgirl 贪心

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

  6. ZOJ 3607 Lazier Salesgirl

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

  7. ZOJ 3607 Lazier Salesgirl(贪心)

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

  8. 2012-2014 三年浙江 acm 省赛 题目 分类

    The 9th Zhejiang Provincial Collegiate Programming Contest A    Taxi Fare    25.57% (166/649)     (水 ...

  9. ZOJ 3607贪心算法

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

随机推荐

  1. CodeForces #368 div2 D Persistent Bookcase DFS

    题目链接:D Persistent Bookcase 题意:有一个n*m的书架,开始是空的,现在有k种操作: 1 x y 这个位置如果没书,放书. 2 x y 这个位置如果有书,拿走. 3 x 反转这 ...

  2. telnet 使用

    Telnet协议是TCP/IP协议族中的一员,是Internet远程登陆服务的标准协议和主要方式.它为用户提供了在本地计算机上完成远程主机工作的能力.在终端使用者的电脑上使用telnet程序,用它连接 ...

  3. C#之Lock

    lock 关键字将语句块标记为临界区,方法是获取给定对象的互斥锁,执行语句,然后释放该锁. class Program { static void Main(string[] args) { Thre ...

  4. ubuntu14.04 wifi驱动

    ubuntu崩溃后再安装后,发现没有了wifi按钮 因为必须要用wifi不然太不方便了,于是在网上找了一下,安装了一下驱动就解决了 首先确定无线网卡类型: $ lspci -vnn -d 14e4: ...

  5. 如何隐藏DOM元素

    在CSS中,要隐藏DOM元素常见的方法有: 设置元素的opacity值为0 设置元素的visibility值为hidden 设置元素的display值为none 设置元素的position值为abso ...

  6. 转-squid介绍及其简单配置

    本文原始出处:http://linuxme.blog.51cto.com/1850814/372960 1.Squid是什么? Squid中文权威指南:http://zyan.cc/book/squi ...

  7. 关于ZendFramework环境的配置

    在运用PHP进行网站建设的时候,使用框架能够很好的提高编程效率,PHP语言的框架很多,现在普遍使用的是由Zend公司开发的ZendFramework框架,本篇文章是关于ZendFramework的运行 ...

  8. jQuery focus、blur事件 添加、删除类名

    jQuery.focusblur = function(ele,className){ var focusblurid = $(ele); focusblurid.focus(function(){ ...

  9. HalconMFC(一)之多版本配置

    今天比较匆忙,还得写周六日考试扯P的PPT,就先这样开个头吧.我的电脑是win7,32位的系统,我用Halcon10.0.但是很多小伙伴的都是64位系统的,所以我用小伙伴的64位系统试过很多次用VC配 ...

  10. 关于JavaScript和html的随笔

    最近听了一些关于JavaScript和html的讲课和读了一些书籍.因为我是给项目做网站知道的,所以要特别的注意和努力.JavaScript是一门挺好用的脚本语言,比较简单灵活,在这上面我深有体会,因 ...