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

枚举

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <algorithm> using namespace std;
int n;
int p[1005];
int t[1005];
int w;
int main()
{
int t1;
scanf("%d",&t1);
while(t1--)
{
scanf("%d",&n);
for(int i=1;i<=n;i++)
scanf("%d",&p[i]);
int num1=0;
int num2=100000;
t[0]=0;
for(int i=1;i<=n;i++)
{
scanf("%d",&t[i]);
num1=max(num1,t[i]-t[i-1]);
num2=min(num2,t[i]-t[i-1]);
}
int pos=1;
double res=0;
double ans;
for(w=num2;w<=num1;w++)
{
int sum=0;int num=0;
int time=w;
for(int i=1;i<=n;i++)
{
if(t[i]<=time)
{
sum+=p[i];
num++;
time=t[i]+w;
}
else
{
break;
}
}
double av=1.0*sum/num;
if(res<av)
{
res=av;
ans=w;
} }
printf("%.6f %.6f\n",ans,res); }
return 0;
}

ZOJ 3607 Lazier Salesgirl (枚举)的更多相关文章

  1. ZOJ 3607 Lazier Salesgirl(贪心)

    题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607 题意:一个卖面包的小姑娘,给第i个来买面包的人的价格是pi, ...

  2. ZOJ 3607 Lazier Salesgirl 贪心

    这个题比上个题简单得多,也是超过W时间会睡着,睡着就再也不会卖了,顾客按时间顺序来的,但是可能有顾客同时到(同时到如果醒着就全卖了),并且每个人只买一块面包,也是求最大的W,使得卖出面包的平均价格最高 ...

  3. ZOJ 3607 Lazier Salesgirl

    Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling ...

  4. zjuoj 3607 Lazier Salesgirl

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607 Lazier Salesgirl Time Limit: 2 Sec ...

  5. H - Lazier Salesgirl

    Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practic ...

  6. ZOJ 3607贪心算法

    http://blog.csdn.net/ffq5050139/article/details/7832991 http://blog.watashi.ws/1944/the-8th-zjpcpc/ ...

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

    Description Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making ...

  8. ZOJ 3606 Lazy Salesgirl 浙江省第九届省赛

    Lazy Salesgirl Time Limit: 5 Seconds      Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who ma ...

  9. H - 【59】Lazier Salesgirl 模拟//lxm

    Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling ...

随机推荐

  1. github提交一个空目录

    github默认不上传空目录,有的时候需要空目录来保持程序的结构. 二个小问题. 1.始终保持空目录,即时里面有文件,也全部忽略掉. 建立一个.gitignore文件放到空目录内. mkdir emp ...

  2. Atitit.软件GUI按钮与仪表盘--db数据库区--导入mysql sql错误的解决之道

    Atitit.软件GUI按钮与仪表盘--db数据库区--导入mysql sql错误的解决之道 Keyword::截取文本文件后部分 查看提示max_allowed_packet限制 Target Se ...

  3. 思科ACL不连续通配符掩码的计算

    access-list 120 permit ip 10.0.0.0 0.0.0.191 any     这条ACL看似简单,却又复杂,因为正常我们见到的通配符掩码都是诸如0.0.0.255(255. ...

  4. filter从web.xml读取config的时候中文编码问题

    首先,web.xml中不建议出现超出ASCII范围的字符 但是作为一点积累,简单举个例子如下,其核心代码就是new String(String.getBytes(charset_1), charset ...

  5. eclipse配置xml的自动提示

    如mybatis的mapper配置文件: <?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE ...

  6. 【基础练习】【区间DP】codevs2102 石子归并2(环形)题解

    题目描写叙述 Description 在一个园形操场的四周摆放N堆石子,现要将石子有次序地合并成一堆.规定每次仅仅能选相邻的2堆合并成新的一堆,并将新的一堆的石子数,记为该次合并的得分. 试设计出1个 ...

  7. Task Scheduling

    Introduction In the past, developers have generated a Cron entry for each task they need to schedule ...

  8. kettle的日志

    http://blog.sina.com.cn/s/blog_76a8411a01010u2h.html

  9. Linux 复制、移动覆盖文件不提示

    # vi ~/.bashrc   如果你看到如下内容,以下命令都会用别名执行了,就是说自动加了 -i 参数 alias rm='rm -i'alias cp='cp -i'alias mv='mv - ...

  10. boost 互斥体和锁

    1.共享资源是一个自动锁住的房间,互斥体是钥匙,进入房间必须取钥匙,离开房间应该还钥匙.这就对应着互斥体的lock(取钥匙)和unlock(还钥匙). 2.考虑下面的场景:还钥匙的时候出现异常,会发生 ...