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 题意是要求出时间w使得卖出面包的平均价格最大
这个题可以求出到第i个客服保持清醒的时间w[i]然后模拟一遍就可
#include <iostream>

#include <stdio.h>

#include <cmath>

using namespace std;

#define maxn 1111

int p[maxn], times[maxn], w[maxn];

int t,n;

int main()

{

    cin>>t;

    while(t--)

    {

        cin>>n;

        for(int i=;i<n;i++)

            cin>>p[i];

        for(int i=;i<n;i++)

            cin>>times[i];

        w[]=times[];

        for(int i=;i<n;i++)

            w[i]=max(times[i]-times[i-],w[i-]);//到第i个所需要的最大的时间

        double the_time=,sum,ave,time;

        ave=;

        for(int i=;i<n;i++)

        {

            time=w[i];

            sum=;

            int cnt=;

            for(int j=;j<n;j++)

            {

                if(time>=w[j])

                {

                    sum+=p[j];

                    cnt++;

                }

                else

                    break;

            }

            if(ave<sum/cnt)

            {

                ave=sum/cnt;

                the_time=time;

            }

            else if (ave==sum/cnt)

            {

                the_time=min(the_time,time);

            }

        }

        printf("%.6lf %.6lf\n",the_time,ave);

    }

    return ;

}

H - 【59】Lazier Salesgirl 模拟//lxm的更多相关文章

  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 - Lazier Salesgirl

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

  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. H.数7(模拟)

    1212: H.数7 时间限制: 1 Sec  内存限制: 64 MB 提交: 8  解决: 5 标签提交统计讨论版 题目描述 数7是一个简单的饭桌游戏,有很多人围成一桌,先从任意一人开始数数,1.2 ...

  6. ZOJ 3607 Lazier Salesgirl 贪心

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

  7. ZOJ 3607 Lazier Salesgirl

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

  8. CERC2017 H Hidden Hierarchy(树+模拟)

    题意: 在一些给定的目录里按要求展开到制定大小并按字典序输出 思路: 因为有目录这个东西,所以想到模拟一个类似字典树的东西,不过这里每个儿子可能有n个节点,而且不能O(1)查询了 代码超长.. #in ...

  9. ZOJ 3607 Lazier Salesgirl(贪心)

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

随机推荐

  1. 【转载】非Lumia 950/XL机型 强行开启continuum教程

    听说Windows 10 Mobile 的 Continuum 特性很长时间了,但是由于我自己的 Lumia 930 不在支持之列,一直没能体验到这个功能.今天在酷七看到了这篇文章,按文章所述的步骤进 ...

  2. 对不队——Alpha冲刺

    第五天  日期:2018/6/20 一. 今日完成任务:专家审稿逻辑的开发 冯晓.马思远:会议网站栏目管理开发,软件功能测试 王爽.彭辉:审稿管理员分稿和稿件查找功能开发,博客撰写 吴琼.郝延婷:更换 ...

  3. js 转义

    1. JavaScript 特殊字符 2. 正反斜杠互相替换 'a/b/c'.replace(/\//g,'\\')      //  "a\b\c" $0.value.repla ...

  4. json-rpc和restful

    json-rpc是一种动作 restful 是一种资源 RPC 所谓的远程过程调用 (面向方法) SOA 所谓的面向服务的架构(面向消息) REST 所谓的 Representational stat ...

  5. rsync+inotify文件同步 - 同步慢的问题

    rsync+inotify文件同步 - 同步慢的问题 我们来看网上的教程,我加了注释.(网上所有的教程基本都一模一样,尽管写法不一样,致命点都是一样的) #!/bin/bash /usr/bin/in ...

  6. 清空mailq 队列里面的邮件

    tmp_=`mailq | grep -E "root" | awk '{print $1}'` for i in $tmp_;do postsuper -d $i;done po ...

  7. 20161227xlVBA多文件合并计算

    Sub NextSeven_CodeFrame() '应用程序设置 Application.ScreenUpdating = False Application.DisplayAlerts = Fal ...

  8. codeforces 930b//Game with String// Codeforces Round #468 (Div. 1)

    题意:一个串,右循环移位后,告诉你第一个字母,还能告诉你一个,问你能确定移位后的串的概率. 用map记录每个字母出现的位置.对于每个字母,用arr[j][k]记录它的所有出现位置的后j位是字母k的个数 ...

  9. codeforces 966c//Big Secret// Codeforces Round #477 (Div. 1)

    题意:一个数组,重新打乱后前缀异或和递增.问这样的排列. 将所有元素按照二进制最高位分组.每次选当前前缀和sum的二进制最低的0位,再从分组中挑一个作为答案.先放首1在较低位的再放首1在较高位的总是可 ...

  10. Java 访问控制关键字

    public, private, protected 在控制上有什么区别和不同请参考下面的说明. 请参考下图的说明. 和下面的一个说明: │ Class │ Package │ Subclass │ ...