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

贪心用map存储时间间隔。

只有两种情况:

如果后面的时间间隔比前面出现的最大的时间间隔还大的话,新建键值对存到map。

反之,在原来的最大时间间隔上进行处理。

 #include <stdio.h>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std; int n;
int cnt;
int sum[];
map< double , double > M;
map< double , double >::iterator it; struct Node{
int p,t;
}nod[]; bool cmp(Node n1, Node n2){
return n1.t<n2.t;
} int main(){
int t;
int i,j;
scanf("%d",&t);
while( t-- ){
scanf("%d" ,&n);
for(i=; i<n; i++){
scanf("%d" ,&nod[i].p);
}
for(i=; i<n; i++){
scanf("%d" ,&nod[i].t);
}
sort(nod ,nod+n ,cmp);
M.clear();
for(i=; i<n; i++){
if(i==){
sum[i]=nod[i].p;
}else{
sum[i]=sum[i-]+nod[i].p;
}
}
cnt=nod[].t;
M[cnt]=nod[].p;
for(i=; i<n; i++){
if( nod[i].t-nod[i-].t>cnt ){
cnt=nod[i].t-nod[i-].t;
M[cnt]=double(sum[i])/(i+);
}else{
M[cnt]=double(sum[i])/(i+);
}
}
double w=;
double maxValue=;
for(it=M.begin(); it!=M.end(); it++){
if( it->second > maxValue ){
w=it->first;
maxValue=it->second;
}
}
printf("%.6lf %.6lf\n",w,maxValue);
}
return ;
}

ZOJ 3607 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. ZOJ 3607 Lazier Salesgirl(贪心)

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

  3. ZOJ 3607 Lazier Salesgirl 贪心

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

  4. zjuoj 3607 Lazier Salesgirl

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

  5. H - Lazier Salesgirl

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

  6. ZOJ 3607贪心算法

    http://blog.csdn.net/ffq5050139/article/details/7832991 http://blog.watashi.ws/1944/the-8th-zjpcpc/ ...

  7. ZOJ 3606 Lazy Salesgirl 浙江省第九届省赛

    Lazy Salesgirl Time Limit: 5 Seconds      Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who ma ...

  8. [ACM_模拟][ACM_暴力] Lazier Salesgirl [暴力 懒销售睡觉]

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

  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. VS2010下安装OpenCV2.4.3

    本文记录Windows 7 X86 SP1操作系统环境下,安装与配置OpenCV2.4.3的详细步骤.前置需求:已安装有VS2010. 下载并安装OpenCV 从http://www.opencv.o ...

  2. win10与子系统Ubuntu 相关配置

    系统间 文件访问: 1. 在win10环境下访问Ubuntu文件系统的home目录:C:\Users\xxx\AppData\Local\Packages\CanonicalGroupLimited. ...

  3. 创建 ASP.NET Web API的Help Page

    转:创建WEBAPI项目 转:添加测试API中的ASP.NET Web API帮助页面

  4. Django Query

    Making Qeries 一旦创建了数据模型,Django就会自动为您提供一个数据库抽象API,允许您创建.检索.更新和删除对象.本文档解释了如何使用这个API. The models 一个clas ...

  5. Heimich manoeuvre 海姆利克氏操作

    食物,异物卡喉的问题屡见不鲜,造成呼吸困难,甚至心跳停止. 一旦发生这个状况,千万千万不要叩击病人的背部,应在迅速联系医院救援的同时,对病人进行现场急救. heimlich的实施最重要的功能是可以实现 ...

  6. “全栈2019”Java第七章:IntelliJ IDEA注释快捷键

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  7. better-scroll在vue中的应用

    在我们日常的移动端项目开发中,处理滚动列表是再常见不过的需求了,以滴滴为例,可以是这样竖向滚动的列表,如图所示: 微信 —> 钱包—>滴滴出行”体验效果. 什么是 better-scrol ...

  8. [Maven实战-许晓斌]-[第三章] Mave使用入门二(在IDE中的使用) [第四章] 案例的背景介绍

    创建maven项目

  9. 制作基于centos可以ssh连接的容器以及tomcat容器

    可以ssh连接的centos容器 参考:http://blog.csdn.net/mexel310/article/details/51705777 一. pull好镜像后,运行容器 1. docke ...

  10. Navicat 导出sql文件和导入sql文件

    1.导出sql文件 (1)选择需要导出数据库表,右击--->转储为sql文件---->结构和数据 (2)会弹出如下界面,采用默认的数据表名,点击确认即可. 2.导入sql文件 (1)点击表 ...