首页 技术 正文
技术 2022年11月8日
0 收藏 600 点赞 1,294 浏览 1558 个字

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 1111int 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 ;}
相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,110
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,584
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,431
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,202
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:7,837
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:4,920