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

简介:


 

Description

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


题目大意:T种情况,每种n个客人,第i个客人可赚p[i]元钱,第i个客人t[i]时间来,卖东西的很懒,如果w时间内没人来就睡觉,一觉不起,求最大人均赚的钱同时输出最小w.
解题思路:暴力枚举每次在第i个顾客来后睡。用w[i]保存想赚第i个人w的最小值,用av[i]保存赚前i个顾客的平均值。如果在第i个顾客来后睡觉就要满足w[i]<w[i+1](这个式子表明第i和第i+1个顾客之间的时间间隔比之前的都大,所以可以取w=w[i]来在这点后睡觉不醒)

复制代码
 1 #include<iostream>
 2 #include<string.h>
 3 #include<cstring>
 4 #include<cstdio>
 5 #include<string>
 6 using namespace std;
 7 int main(){
 8     int T;cin>>T;
 9     while(T--){
10         int n;cin>>n;
11         int p[1002],t[1002];
12         //w[i]表示赚第i个人需要w的最小值;av[i]表示前i个的人均赚钱数
13         double w[1002],av[1002];
14         double sum=0;
15         for(int i=0;i<n;i++){
16             cin>>p[i];
17             sum+=p[i];
18             av[i]=sum/(i+1);
19         }
20         double max_w=-1;
21         for(int i=0;i<n;i++){
22             cin>>t[i];
23             if(i!=0){
24                 if(t[i]-t[i-1]>max_w){
25                     max_w=t[i]-t[i-1];
26                     w[i]=max_w;
27                 }else w[i]=max_w;
28             }
29             else {
30                 max_w=t[0];
31                 w[i]=max_w;
32             }
33         }w[n]=1312312313;//w[n]赋值很高
34         
35         int pos=0;double max_av=-1;//暴力枚举在i点睡着
36         for(int i=0;i<=n;i++){
37             if(w[i]<w[i+1]){
38                 if(av[i]>max_av){
39                     max_av=av[i];
40                     pos=i;
41                 }
42             }
43         }
44 
45         printf("%.6lf %.6lf\n",w[pos],av[pos]);
46     }return 0;
47 }
复制代码
相关文章
|
5月前
|
算法 Java C语言
第十四届蓝桥杯集训——练习解题阶段(无序阶段)-ALGO-246 算法训练 猴子吃包子
第十四届蓝桥杯集训——练习解题阶段(无序阶段)-ALGO-246 算法训练 猴子吃包子
59 2
|
5月前
|
Java C语言 C++
第十四届蓝桥杯集训——练习解题阶段(无序阶段)-ALGO-1000 kAc给糖果你吃
第十四届蓝桥杯集训——练习解题阶段(无序阶段)-ALGO-1000 kAc给糖果你吃
78 0
|
5月前
|
算法 Java C语言
第十四届蓝桥杯集训——练习解题阶段(无序阶段)-ALGO-985 幸运的店家
第十四届蓝桥杯集训——练习解题阶段(无序阶段)-ALGO-985 幸运的店家
78 0
|
5月前
|
机器学习/深度学习 算法 测试技术
青蛙跳台阶:我如何得知它是一道斐波那契数列题?——应用题破题“三板斧”(二)
这篇内容是关于解题策略的,主要介绍了在面对应用题时可以采用的“三板斧”方法:举例、模拟和找规律。通过一个走楼梯的例子详细解释了这三个步骤如何运用。首先,举例将抽象问题具体化,比如走5级台阶有几种方式。其次,通过模拟不同情况,例如思考走每一步的可能,发现递归或循环的模式。最后,通过找规律归纳出一般性的解决方案,这里发现走台阶问题与斐波那契数列相关。文章还提到了一个拓展案例——矩形覆盖问题,同样可以用类似的方法分析。总的来说,文章强调了解题过程中理解和转化问题的重要性,以及通过训练提升这方面能力。
48 0
|
5月前
|
C语言
青蛙跳台阶:我如何得知它是一道斐波那契数列题?——应用题破题“三板斧”(一)
这篇内容介绍了C语言学习中的经典例题——斐波那契数列,强调了解题思路的重要性。斐波那契数列是一个数列,其中每个数是前两个数的和。文章指出,很多类似题目,如“青蛙跳台阶”,实质上都在考察斐波那契数列的实现。文中提供了斐波那契数列的定义、代码实现和递归与非递归的思路,并鼓励读者从问题中分析出解题模型,而非直接套用已知方法。此外,还提及了一道相关题目“矩形覆盖问题”,以供进一步练习。
44 0
|
5月前
|
C++
【PTA】​L1-062 幸运彩票 ​ (C++)
【PTA】​L1-062 幸运彩票 ​ (C++)
85 0
【PTA】​L1-062 幸运彩票 ​ (C++)
|
5月前
|
算法 Java C语言
第十四届蓝桥杯集训——练习解题阶段(无序阶段)-ALGO-1006 拿金币
第十四届蓝桥杯集训——练习解题阶段(无序阶段)-ALGO-1006 拿金币
62 0
|
5月前
|
算法 Java C语言
第十四届蓝桥杯集训——练习解题阶段(无序阶段)-ALGO-545 IQ
第十四届蓝桥杯集训——练习解题阶段(无序阶段)-ALGO-545 IQ
50 0
|
5月前
蓝桥备战--纪念品分组OJ532,贪心证明
蓝桥备战--纪念品分组OJ532,贪心证明
26 0
[算法刷题题解笔记] 洛谷 P1008 [NOIP1998 普及组] 三连击 [枚举|模拟]
[算法刷题题解笔记] 洛谷 P1008 [NOIP1998 普及组] 三连击 [枚举|模拟]