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

  1. 2
  2. 4
  3. 1 2 3 4
  4. 1 3 6 10
  5. 4
  6. 4 3 2 1
  7. 1 3 6 10

Sample Output

  1. 4.000000 2.500000
  2. 1.000000 4.000000

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

分析:

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

AC代码:

  1. #include<cstdio>
  2. #include<algorithm>
  3. using namespace std;
  4. int sum[],b[];
  5. int main() {
  6. int t;
  7. scanf("%d",&t);
  8. while(t--) {
  9. int n;
  10. scanf("%d",&n);
  11. int tmp;
  12. for(int i = ;i <= n;i++) {
  13. scanf("%d",&tmp);
  14. sum[i] = sum[i-] + tmp;
  15. // printf("%d -- ",sum[i]);
  16. }
  17.  
  18. for(int i = ;i <= n;i++){
  19. scanf("%d",&b[i]);
  20. }
  21.  
  22. double ma = ;
  23. int maxT = ,res = ;
  24. for(int i = ;i <= n;i++) {
  25. if(b[i] - b[i - ] > maxT) {
  26. maxT = b[i] - b[i - ];
  27. }
  28. while(i <= n && b[i] - b[i - ] <= maxT) i++;
  29. i--;
  30. if(1.0 * sum[i] / (i) > ma) {
  31. ma = 1.0 * sum[i] / (i);
  32. res = maxT;
  33. }
  34. }
  35. printf("%.6lf %.6lf\n",res * 1.0,ma);
  36. }
  37. return ;
  38. }

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. 【JAVA】通过公式字符串表达式计算值,网上的一种方法

    public class Test {    public static void main(String[] args) {     SimpleCalculator s=new SimpleCal ...

  2. 谷歌(GDG):智能技术在物联网及移动互联网中的最新应用讲座

       谷歌开发者社区GDG(原谷歌技术用户组GTUG),将于11月23日(周六)下午 1:30-5:00,在北京翠宫饭举办一场智能技术在物联网及移动互联网中的最新应用讲座,培训讲座中将通过三个专题与众 ...

  3. Oracle临时表GLOBAL TEMPORARY TABLE

    临时表:像普通表一样,有结构,但是对数据的管理上不一样,临时表存储事务或会话的中间结果集,临时表中保存的数据只对当前 会话可见,所有会话都看不到其他会话的数据,即使其他会话提交了,也看不到.临时表不存 ...

  4. [译]FastClick: native-like tapping for touch apps

    原文地址:http://labs.ft.com/2011/08/fastclick-native-like-tapping-for-touch-apps/ 这篇文章是一篇老文了,现在才看到,真是落后啊 ...

  5. windows2008 IIS下配置FTP服务

    一.服务器管理器 1.2008的系统使用服务器管理器,选择角色,因为我之前已经开启了IIS服务器角色,所以我现在只要添加角色服务即可,如果你没有开启过的话,直接添加角色即可. 2.选择WEB服务器,打 ...

  6. 使用audio标签播放音频文件

    HTML5定义了一个新的元素用来指定标准的方式来插入音频文件到web页面中:<audio>标签.使用audio标签可以控制音频的播放与停止,循环播放与播放次数设置,以及播放位置等等. 例如 ...

  7. java之redis篇(spring-data-redis整合一)

    redis的知识:官网 1.利用spring-data-redis整合 项目使用的pom.xml: <project xmlns="http://maven.apache.org/PO ...

  8. as3如何做出残影效果

    在页游中,时不时能看到人物做一些快速移动动作如冲刺时,有残影效果,强化了画面表现.实际人肉眼之所以能看到残影的效果,是因为观察到的物体会在人视线中残留几十毫秒时间,当运动物体运动太快时,人肉眼所见未能 ...

  9. 将bootstrap弹出框的点击弹出改为鼠标移入弹出

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  10. width,clientWidth,offsetWidth

    <!DOCTYPE HTML> <html> <head> <meta http-equiv="Content-Type" content ...