http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607

Lazier Salesgirl


Time Limit: 2 Seconds      Memory Limit: 65536 KB

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 nintegers 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

Author: WU, Zejun
Contest: The 9th Zhejiang Provincial Collegiate Programming Contest

分析:

求当睡觉时间最短,卖出的面包平均价格最高时的W和平均值,注意:当他睡着的时候就不再醒啦,,,

AC代码:

 #include<cstdio>
#include<algorithm>
using namespace std;
int sum[],b[];
int main() {
int t;
scanf("%d",&t);
while(t--) {
int n;
scanf("%d",&n);
int tmp;
for(int i = ;i <= n;i++) {
scanf("%d",&tmp);
sum[i] = sum[i-] + tmp;
// printf("%d -- ",sum[i]);
} for(int i = ;i <= n;i++){
scanf("%d",&b[i]);
} double ma = ;
int maxT = ,res = ;
for(int i = ;i <= n;i++) {
if(b[i] - b[i - ] > maxT) {
maxT = b[i] - b[i - ];
}
while(i <= n && b[i] - b[i - ] <= maxT) i++;
i--;
if(1.0 * sum[i] / (i) > ma) {
ma = 1.0 * sum[i] / (i);
res = maxT;
}
}
printf("%.6lf %.6lf\n",res * 1.0,ma);
}
return ;
}

zjuoj 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. ZOJ 3607 Lazier Salesgirl

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

  5. H - Lazier Salesgirl

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

  6. zjuoj 3606 Lazy Salesgirl

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3606 Lazy Salesgirl Time Limit: 5 Secon ...

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

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

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

  9. ZOJ 3607贪心算法

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

随机推荐

  1. wxPython学习

    http://www.cnblogs.com/coderzh/archive/2008/11/23/1339310.html 一个简单的实例: #!/usr/bin/python import wx ...

  2. Notification Once

    Notification Once 前段时间整理项目中的AppDelegate,发现很多写在- application:didFinishLaunchingWithOptions:中的代码都只是为了在 ...

  3. LVS + KEEPAlived 配置 DIR模式

    1 .1 Lvs LVS是Linux Virtual Server的简写,意即Linux虚拟服务器,是一个虚拟的服务器集群系统.本项目在1998年5月由章文嵩博士成立,是中国国内最早出现的自由软件项目 ...

  4. zabbix3.2.0beta2 监控模版

    Zabbix监控中用到了一系列模版,nginx后端检测状态 微信告警等一系列常规的服务应用监控 memcached监控模版,可以自己重新定义memcached的端口 http://files.cnbl ...

  5. [LintCode] Segment Tree Build II 建立线段树之二

    The structure of Segment Tree is a binary tree which each node has two attributes startand end denot ...

  6. [LintCode] Decode Ways 解码方法

    A message containing letters from A-Z is being encoded to numbers using the following mapping: 'A' - ...

  7. jquery实现获取手机验证码倒计时效果

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  8. Lamp下安全配置随笔

    Apache方面: 1.apache有两个指令可以输出服务器的细节,即ServerSignature和ServerTokens. 当这两个指令一起使用时,会输出apache的版本号,php的版本号,i ...

  9. NLP 自然语言处理

    参考: 自然语言处理怎么最快入门:http://www.zhihu.com/question/ 自然语言处理简介:http://wenku.baidu.com/link?url=W6Mw1f-XN8s ...

  10. JDBC使用MySQL存储过程错误

    JDBC连接执行 MySQL 存储过程报权限错误:User does not have access to metadata required to determine stored procedur ...