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. 使用jvisualvm进行远程监控

    1. 描述 jvisualvm是JDK自带的监控工具,位于JDK bin目录下面. 默认jvisualvm不能监控远程的JVM进程,需要进行一些配置. 2. 单独在应用上配置JVM启动参数 在Java ...

  2. iOS开发-iOS 10 由于权限问题导致崩溃的那些坑

     iOS开发-iOS 10 由于权限问题导致崩溃的那些坑 6月份的WWDC大会结束有一段时间了,相信很多开发者也是在努力工作的闲时用着Xcode8 Beta版学习着新的特性吧. 使用Xcode8写自己 ...

  3. 03、Windows Phone 套接字(Socket)实战之WP客户端设计

    因为 PC 端和 WP 端进行通信时,采用的自定义的协议,所以也需要定义 DataType 类来判断 通信数据的类型,并且把数据的描述信息(head) 和数据的实际内容(body)进行拼接和反转,所以 ...

  4. apache官方中文hadoop说明文档地址

    http://hadoop.apache.org/docs/r1.0.4/cn/quickstart.html

  5. web.config中的connectionString里面应该怎么写?

    2009-09-16 10:19信欣玛利 | 浏览 6068 次  网络 就是具体格式.. 谁能举个例子? asp.net 3.5的. 2009-09-16 10:40   提问者采纳   这是用来连 ...

  6. matlab使用的心得

    保存变量到一个文件,可以是部分变量或者全部变量save('back.mat','a'):%把a变量保存在文件中 加载文件中的变量可以是部分或者全部变量load('matlab.mat','a') 向字 ...

  7. phan—php语法静态检查在windows下的配置

    php7推出了语法树,于是静态语法分析更方便了.(可以直接下载我配置好的,传送门百度网盘) 1.先安装php7,到http://windows.php.net/下载php7带openssl的. 2.修 ...

  8. ajax——用ajax写用户注册

    zhuce.php <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://w ...

  9. 示例 - 10行代码在C#中获取页面元素布局信息

    最近研究一个如何在网页定位验证码并截图的问题时, 用SS写了一段C#小脚本可以轻松获取页面任意元素的布局信息 (top, left, width, height). 10行功能代码, 觉得有点用, 现 ...

  10. 清除Css中select的下拉箭头样式

    select {/*Chrome和Firefox里面的边框是不一样的,所以复写了一下*/border: solid 1px #000; /*很关键:将默认的select选择框样式清除*/appeara ...