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. linux安装memcache及memcache扩展

    一.安装libevent# wget http://www.monkey.org/~provos/libevent-2.0.12-stable.tar.gz# tar zxf libevent-2.0 ...

  2. sql查询语句的拼接小技巧(高手勿喷)

    1. 基本的查询语句后面加上 WHERE 1=1,便于增加查询条件. ASkStr := 'select * from Twork where 1=1 '; if length(cxTEworkid. ...

  3. .net EventHandler 事件处理

    通常定义事件 都是通过自定义委托的方式来实现, 今天使用EventHandler   委托来定义事件: public class NewMailEventArgs : EventArgs { priv ...

  4. Android-Observer(内容观察者)

    内容提供者应用暴露的数据,是被多个其他应用访问(insert,update,delete,query),但如果L应用要查询(内容提供者应用暴露的数据),难道要开启子线程一直循环去查询 ? 答:开启子线 ...

  5. C# 编写的SqlServer 数据库自动备份服务,带配置,功能强大

    数据库自动备份服务,带配置,还算可以吧 周末抽时间,编写了一个这样的工具,可以让,对数据库不了解或不熟悉的人,直接学会使用备份,省时省力,同样,我也将一份,通过脚本进行备份的,也奉献上来, 通过sql ...

  6. 使用PLSQL Developer时中文乱码问题

    使用PLSQL Developer时中文乱码问题 一.问题: 执行一些查询结果有中文的SQL语句,显示不了中文,显示???. 二.产生的原因: 客户端与服务器端的编码不一致造成的. 三.解决方案: 1 ...

  7. node.js 转载:有效

    二.安装Node.js步骤 1.下载对应你系统的Node.js版本:https://nodejs.org/en/download/2.选安装目录进行安装3.环境配置4.测试 三.前期准备 1.Node ...

  8. for循环 | range 对象

    # ### for循环 # 循环 遍历 迭代 # 把列表的元素一一的拿出来遍历 listvar = ["黄雄大","黄文","黄仪正",&q ...

  9. [Maven实战-许晓斌]-[第二章]-2.3安装目录分析

    bin boot conf settings.xml非常重要 这个是maven安装包自带的settings.xml 通常我们会放在习惯路径,C:\Users\admin\.m2\下面 即  用户路径\ ...

  10. selenium爬取qq空间,requests爬取雪球网数据

    一.爬取qq空间好友动态数据 # 爬取qq空间好友状态信息(说说,好友名称),并屏蔽广告 from selenium import webdriver from time import sleep f ...