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. makefile 学习网站

    http://blog.csdn.net/ruglcc/article/details/7814546/#t30

  2. Myeclipse——SSH框架搭建

    Struts2.x+Spring3.x+Hibernate3.x 一.首先建立一个Web 工程 二.搭建Struts 右键工程,选择MyEclipse->Add Struts Capabilit ...

  3. linux桌面的安装

    在CentOS 7中提供了两种桌面"GNOME DESKTOP" 和 "KDE Plasa Workspaces",我们以安装"GNOME DESKT ...

  4. MicroERP数据初始化SQL脚本

    --use MicroERP insert into tbUserGroup(GroupName,Remark) values('管理员组','具备所有权限')insert into tbUser(L ...

  5. OC基础--对成员变量的封装

    #import <Foundation/Foundation.h> //日期结构体 typedef struct{ int year; int month; int day; } Date ...

  6. JDK安装与环境变量配置

    1.安装JDK 选择安装目录 安装过程中会出现两次 安装提示 .第一次是安装 jdk ,第二次是安装 jre .建议两个都安装在同一个java文件夹中的不同文件夹中.(不能都安装在java文件夹的根目 ...

  7. DateTimePicker如何与Delphi自带Style同步

    Delphi 的 DateTimePicker 组件有一个CalColors属性,可以设置 DropDown 打开的日历节目的风格.但如果不使用 Delphi 自带的 Style,在这里设置属性看不到 ...

  8. 《java中异常和错误》

    异常和错误的区别. 异常: 在Java中程序的错误主要是语法错误和语义错误,一个程序在编译和运行时出现的错误我们统一称之为异常,它是VM(虚拟机)通知你的一种方式,通过这种方式,VM让你知道,你(开发 ...

  9. mysql免安装版本

    [下载MySQL 5.6.13] 从MySQL官方网站mysql.com找到MySQL Community Server 5.6.13的下载地址为http://dev.mysql.com/downlo ...

  10. android 网络请求库的比较

    源码请戳 一. 现有库和选择的库 HttpURLConnection:是Java中的标准类,是对Java中socket的封装. Httpclient:是Apache的开源框架,是对HttpURLCon ...