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 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

题目大意就是一个买面包的小姑凉想偷懒,在卖到第i个人的时候,就会在一个之前维持的最大间隔时间内(如果在这个时间内没人来买面包的)她会一睡不醒。但又要满足能否去到最大平均值。总体来说,这道题有两个条件:平均值最大,并且能一睡不醒。
 1 #include<cstdio>
 2 #include<string.h>
 3 using namespace std;
 4 double p[1010];
 5 double time[1010];
 6 double maxt[1010];
 7 double max(double a,double b)
 8 {
 9     return a>b?a:b;
10 }
11 int main()
12 {
13     int t,n;
14     double w;
15     double flag;
16     scanf("%d",&t);
17     while(t--)
18     {
19         scanf("%d",&n);
20         for(int i=1;i<=n;i++)
21             scanf("%lf",&p[i]);
22         for(int i=1;i<=n;i++)
23             scanf("%lf",&time[i]);
24         time[0]=0;
25         maxt[1]=time[1]-time[0];
26         for(int i=2;i<=n;i++)
27             maxt[i]=max(time[i]-time[i-1],maxt[i-1]);//算出到第i个人时的前面的最大间隔时间
28         double maxn=0;//最大平均值
29         double anst=0;//间隔时间
30         double sum=0;
31         for(int i=1;i<=n;i++)//暴力枚举
32         {
33              w=maxt[i];
34             sum+=p[i];
35             if(i==n)
36             {
37                 if(sum/i>maxn)
38                 {
39                     maxn=sum/i;
40                     flag=w;
41                     break;
42                 }
43             }
44             if(sum/i>maxn&&w<time[i+1]-time[i])//要保证他卖给第i个人后能睡觉
45             {
46                 maxn=sum/i;
47                 flag=w;
48             }
49
50         }
51         printf("%.6lf %.6lf\n",flag,maxn);
52     }
53     return 0;
54 }

H - Lazier Salesgirl

时间: 2024-08-09 03:34:11

H - 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

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 th

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

[ZOJ 3607] Lazier Salesgirl

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

《linux 内核全然剖析》 include/asm/io.h

include/asm/io.h #define outb(value,port) __asm__ ("outb %%al,%%dx"::"a" (value),"d" (port)) //宏定义outb用汇编实现了在端口地址port处写入值value //使用的寄存器是al,一个byte长度,而端口port使用的是2byte长度地址来标记的寄存器,注意这里寄存器的使用 #define inb(port) ({ unsigned char _v;

CUDA gputimer.h头文件

#ifndef __GPU_TIMER_H__ #define __GPU_TIMER_H__ struct GpuTimer { cudaEvent_t start; cudaEvent_t stop; GpuTimer() { cudaEventCreate(&start); cudaEventCreate(&stop); } ~GpuTimer() { cudaEventDestroy(start); cudaEventDestroy(stop); } void Start() {

2017.5 校内预选赛 A H

题目描述: 目前图像识别是一项非常热门的技术,最流行的莫不过是深度学习的图像识别,识别率甚至能达到99%以上.当然,对于简单的图像来说,深度学习是没有必要的.比如如果要识别安徽拼音的首字母A和H,就可以不用深度学习就可以判断.现在有一些只含A或者H的图像,你知道该如何识别吗? 输入描述: 第一行输入正整数T,表示数据的组数. 每组数据中,第一行是两个正整数n和m,表示图像的大小. 接下来有n行,每行m个字符,只可能为'.'或者'#'.'.'表示白色,'#'表示黑色.'#'会通过上下左右或者左上左

编译过程中,termcap.h 文件找不到路径 licli.a终于生成

编译过程中,termcap.h      文件找不到路径 查看是linux  源码下找不到termcap.h文件 安装了所有关于*cap*的源码包也不起作用 今天终于解决了这个问题,搜termcap.h  发现一篇文章,如下 ----------------------------------------------------------------------------------------- 安装minicom2.3出现termcap.h错误解决方法 2010-05-06 17:12: