zoukankan      html  css  js  c++  java
  • zjuoj 3607 Lazier Salesgirl

    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代码:

     1 #include<cstdio>
     2 #include<algorithm>
     3 using namespace std;
     4 int sum[1005],b[1005];
     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 = 1;i <= n;i++) {
    13             scanf("%d",&tmp);
    14             sum[i] = sum[i-1] + tmp;
    15         //    printf("%d -- ",sum[i]);
    16         }
    17         
    18         for(int i = 1;i <= n;i++){
    19             scanf("%d",&b[i]);
    20         }
    21         
    22         double ma = 0;
    23         int maxT = 0,res = 0;
    24         for(int i = 1;i <= n;i++) {
    25             if(b[i] - b[i - 1] > maxT) {
    26                 maxT = b[i] - b[i - 1];
    27             }
    28             while(i <= n && b[i] - b[i - 1] <= 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
    ",res * 1.0,ma);
    36     }
    37     return 0;
    38 }
    View Code
  • 相关阅读:
    计算机图形学——几何变换的数学基础
    算法设计与分析——多边形游戏(动态规划)
    算法设计与分析——凸多边形最优三角剖分(动态规划)
    计算机图形学——反走样
    Android 5.0 API
    Android 6.0 API
    Android 7.0 新增功能和api
    Android 8.0 功能和 API
    Android P 功能和 API
    解决华为手机无法输出Debug级别log的问题
  • 原文地址:https://www.cnblogs.com/jeff-wgc/p/4472239.html
Copyright © 2011-2022 走看看