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. Xcode相关整理

    阅读目录 javadoc格式文档注释插件 xcodekit插件 常用快捷键 XCode中快捷健字符与MAC键盘对应关系: 添加自动生成格式为javadoc文档注释的插件VVDocumenter 首先推 ...

  2. Scala 并发编程

    Runnable/Callable 线程 Executors/ExecutorService Futures 线程安全问题 例子:搜索引擎 解决方案 Runnable/Callable Runnabl ...

  3. Jquery弹窗效果

    1.主页面 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w ...

  4. Android中View的基础知识

    View的界限 View就是我们看到的界面,有四个界限范围分别是, Top/Left, Bottom/Right,坐标系从左上到右下.这四个值可以通过任何View的子类调用getTop()/get.. ...

  5. 字母序列递增,即A+1=B,B+2=D,ASCII

    实际遇到的问题是 单号15001订单的15001-A自动生成15001-B,15001-C.... //说明:以15001-A为基准生成15001-B string maxno ="1500 ...

  6. 在docker容器中安装和使用,linux版的powershell

    powershell 传教士 原创文章.始于 2016-09-18 ,2016-10-27修改powershell docker官网.允许转载,但必须保留名字和出处,否则追究法律责任 1 在任意版本的 ...

  7. [转]显卡帝揭秘3D游戏画质特效

    显卡帝揭秘3D游戏画质特效 近几年来,大量采用最新技术制作的大型3D游戏让大部分玩家都享受到了前所未有的游戏画质体验,同时在显卡硬件方面的技术革新也日新月异.对于经常玩游戏的玩家来说,可能对游戏画质提 ...

  8. extjs combobox

    states.js中 Ext.example.states=[ ['AL','ALabama','The Heart of Dixie'], ['AK','Alaska','The Land of t ...

  9. 区分PC端与移动端代码,涵盖C#、JS、JQuery、webconfig

    1)C#区分PC端或移动端 using System.Text.RegularExpressions string u = Request.ServerVariables["HTTP_USE ...

  10. JavaScript数据类型

    当说到JavaScript的数据类型时,好多做了很多年web的朋友甚至还不太清楚.这应该算是最基础的js知识了.我觉得有必要在这记录一下,方便自己和大家查看. 最基本的,js有五种数据类型:undef ...