• H


    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

    题意是要求出时间w使得卖出面包的平均价格最大
    这个题可以求出到第i个客服保持清醒的时间w[i]然后模拟一遍就可

    #include <iostream>
    
    #include <stdio.h>
    
    #include <cmath>
    
    using namespace std;
    
    #define maxn 1111
    
    int p[maxn], times[maxn], w[maxn];
    
    int t,n;
    
    int main()
    
    {
    
        cin>>t;
    
        while(t--)
    
        {
    
            cin>>n;
    
            for(int i=0;i<n;i++)
    
                cin>>p[i];
    
            for(int i=0;i<n;i++)
    
                cin>>times[i];
    
            w[0]=times[0];
    
            for(int i=1;i<n;i++)
    
                w[i]=max(times[i]-times[i-1],w[i-1]);//到第i个所需要的最大的时间
    
            double the_time=0,sum,ave,time;
    
            ave=0;
    
            for(int i=0;i<n;i++)
    
            {
    
                time=w[i];
    
                sum=0;
    
                int cnt=0;
    
                for(int j=0;j<n;j++)
    
                {
    
                    if(time>=w[j])
    
                    {
    
                        sum+=p[j];
    
                        cnt++;
    
                    }
    
                    else
    
                        break;
    
                }
    
                if(ave<sum/cnt)
    
                {
    
                    ave=sum/cnt;
    
                    the_time=time;
    
                }
    
                else if (ave==sum/cnt)
    
                {
    
                    the_time=min(the_time,time);
    
                }
    
            }
    
            printf("%.6lf %.6lf
    ",the_time,ave);
    
        }
    
        return 0;
    
    }
    
     
  • 相关阅读:
    day12_函数
    day12_游标
    day12_序列——重置序列
    day12_序列——oracle主键自动增加
    day12_B2B用户禁止PLSQL登录
    七月未央,安之若素
    php----显示中文乱码的问题
    C#--中实现邮件发送
    C#--使用存储过程
    C#--之文件操作
  • 原文地址:https://www.cnblogs.com/Annetree/p/6374129.html
Copyright © 2020-2023  润新知