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\n",res * 1.0,ma);
36     }
37     return 0;
38 }

时间: 2024-10-05 11:47:35

zjuoj 3607 Lazier Salesgirl的相关文章

ZOJ 3607 Lazier Salesgirl (贪心)

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

zoj 3607 Lazier Salesgirl 暴力 前缀和

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

[ZOJ 3607] Lazier Salesgirl

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607 思路:最小的相隔时间肯定是两个时间的间隔,只需要计算每个时间间隔所获的价值的平均值,取最大的平均值以及其对应的时间间隔即可,注意,当平均值相等的时候,取时间间隔小的. AC 代码: #include <cstdio> #include <vector> #include <iostream> using namespace std

ZOJ 3607 Lazier Salesgirl(贪心啊 )

题目链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=4710 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 laz

H - Lazier Salesgirl

Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3607 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 custome

zjuoj 3606 Lazy Salesgirl

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3606 Lazy Salesgirl Time Limit: 5 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 

zjuoj 3608 Signal Detection

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3608 Signal Detection Time Limit: 2 Seconds      Memory Limit: 65536 KB Parallelepiped Type Prism Faces 6 parallelograms Edges 12 Vertices 8 Dr. Gale is testing his laser system. He uses a

zjuoj 3605 Find the Marble

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3605 Find the Marble Time Limit: 2 Seconds      Memory Limit: 65536 KB Alice and Bob are playing a game. This game is played with several identical pots and one marble. When the game starts

zjuoj 3602 Count the Trees

http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3602 Count the Trees Time Limit: 2 Seconds      Memory Limit: 65536 KB A binary tree is a tree data structure in which each node has at most two child nodes, usually distinguished as "left&