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 题目大意:T种情况,每种n个客人,第i个客人可赚p[i]元钱,第i个客人t[i]时间来,卖东西的很懒,如果w时间内没人来就睡觉,一觉不起,求最大人均赚的钱同时输出最小w.
解题思路:暴力枚举每次在第i个顾客来后睡。用w[i]保存想赚第i个人w的最小值,用av[i]保存赚前i个顾客的平均值。如果在第i个顾客来后睡觉就要满足w[i]<w[i+1](这个式子表明第i和第i+1个顾客之间的时间间隔比之前的都大,所以可以取w=w[i]来在这点后睡觉不醒)
 #include<iostream>
#include<string.h>
#include<cstring>
#include<cstdio>
#include<string>
using namespace std;
int main(){
int T;cin>>T;
while(T--){
int n;cin>>n;
int p[],t[];
//w[i]表示赚第i个人需要w的最小值;av[i]表示前i个的人均赚钱数
double w[],av[];
double sum=;
for(int i=;i<n;i++){
cin>>p[i];
sum+=p[i];
av[i]=sum/(i+);
}
double max_w=-;
for(int i=;i<n;i++){
cin>>t[i];
if(i!=){
if(t[i]-t[i-]>max_w){
max_w=t[i]-t[i-];
w[i]=max_w;
}else w[i]=max_w;
}
else {
max_w=t[];
w[i]=max_w;
}
}w[n]=;//w[n]赋值很高 int pos=;double max_av=-;//暴力枚举在i点睡着
for(int i=;i<=n;i++){
if(w[i]<w[i+]){
if(av[i]>max_av){
max_av=av[i];
pos=i;
}
}
} printf("%.6lf %.6lf\n",w[pos],av[pos]);
}return ;
}

[ACM_模拟][ACM_暴力] Lazier Salesgirl [暴力 懒销售睡觉]的更多相关文章

  1. [ACM_模拟][ACM_数学] LA 2995 Image Is Everything [由6个视图计算立方体最大体积]

    Description   Your new company is building a robot that can hold small lightweight objects. The robo ...

  2. zjuoj 3607 Lazier Salesgirl

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

  3. ZOJ 3607 Lazier Salesgirl (枚举)

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

  4. 玲珑杯”ACM比赛 Round #18 A -- 计算几何你瞎暴力(瞎暴力)

    题目链接:http://www.ifrog.cc/acm/problem/1143?contest=1020&no=0 题解:就是瞎暴力具体多暴力看一下代码就知道了. #include < ...

  5. ACM_跳坑小能手(暴力)

    跳坑小能手 Time Limit: 2000/1000ms (Java/Others) Problem Description: GDUFE-GAME现场有一个游戏场地人头窜动,围观参与游戏的学生在场 ...

  6. [CSP-S模拟测试]:打扫卫生(暴力)

    题目描述 有$N$头奶牛,每头那牛都有一个标号$P_i1\leqslant Pi\leqslant M\leqslant N\leqslant 40,000$.现在$Farmer\  John$要把这 ...

  7. [CSP-S模拟测试]:String Master(暴力)

    题目描述 所谓最长公共子串,比如串$A:"abcde"$,串$B:"jcdkl"$,则它们的最长公共子串为串$"cd"$,即长度最长的字符串 ...

  8. [ACM_模拟] POJ1068 Parencodings (两种括号编码转化 规律 模拟)

    Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two diff ...

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

随机推荐

  1. codeforces 361 B - Mike and Shortcuts

    原题: Description Recently, Mike was very busy with studying for exams and contests. Now he is going t ...

  2. Linux内核分析第四周学习总结:扒开系统调用的三层皮(上)

    韩玉琪 + 原创作品转载请注明出处 + <Linux内核分析>MOOC课程http://mooc.study.163.com/course/USTC-1000029000 一.用户态.内核 ...

  3. 2015年毕业生收到的offer和薪资透露

    个人情况:全国排名70多的大学,非211,计算机专业硕士 收到的offer: 苏州同程旅游--6k/月 ,自己要了这么多,就给了这么多,没有规范.苏州蜗牛科技--8k/月 ,给了个口头offer,要去 ...

  4. linux下查找某文件关键字

    -e表示罗列出与关键字有关的行,“ABC”表示查找的关键字,/XXX/4.assoc.linear表示该路径下的文件 .assoc.linear

  5. 第三十七章 springboot+docker(手动部署)

    一.下载centos镜像 docker pull hub.c.163.com/library/centos:latest docker tag containId centos:7 docker ru ...

  6. C# upnp

    //获取Host Name var name = Dns.GetHostName(); Console.WriteLine("用户:" + name); //从当前Host Nam ...

  7. 解决org.openqa.selenium.WebDriverException: Unable to connect to host 127.0.0.1 on port 7055 after 45000 ms org.springframework.beans.BeanInstantiation

    解决方法为将selenium-server-standalone-2.37.0.jar升级至selenium-server-standalone-2.41.0.jar即可. 下载地址:http://s ...

  8. AppcompatActivity闪退问题解决方案

    apply plugin: 'com.android.application' android { compileSdkVersion 23 buildToolsVersion "23.0. ...

  9. Lamp 安装(CentOS6.6, php-5.4.39, httpd-2.4.12, mysql-5.6.24)

    软件版本: pcre-8.36.tar.gzapr-1.5.1.tar.gzapr-util-1.5.4.tar.gzhttpd-2.4.12.tar.bz2 mysql-5.6.24.tar.gz ...

  10. "2013":爱你不容易

    2013对我来说确实像年初时曾给自己定义的那样,真的是非常不平常的一年.依稀记得去年年终时,BOSS和我深聊了1多钟头,谈到职业规划.人生还有家庭的林林种种.春节在家时也仔细考虑过2013自己该如何规 ...