H - 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 题目大意就是一个买面包的小姑凉想偷懒,在卖到第i个人的时候,就会在一个之前维持的最大间隔时间内(如果在这个时间内没人来买面包的)她会一睡不醒。但又要满足能否去到最大平均值。
总体来说,这道题有两个条件:平均值最大,并且能一睡不醒。
#include<cstdio>
#include<string.h>
using namespace std;
double p[];
double time[];
double maxt[];
double max(double a,double b)
{
return a>b?a:b;
}
int main()
{
int t,n;
double w;
double flag;
scanf("%d",&t);
while(t--)
{
scanf("%d",&n);
for(int i=;i<=n;i++)
scanf("%lf",&p[i]);
for(int i=;i<=n;i++)
scanf("%lf",&time[i]);
time[]=;
maxt[]=time[]-time[];
for(int i=;i<=n;i++)
maxt[i]=max(time[i]-time[i-],maxt[i-]);//算出到第i个人时的前面的最大间隔时间
double maxn=;//最大平均值
double anst=;//间隔时间
double sum=;
for(int i=;i<=n;i++)//暴力枚举
{
w=maxt[i];
sum+=p[i];
if(i==n)
{
if(sum/i>maxn)
{
maxn=sum/i;
flag=w;
break;
}
}
if(sum/i>maxn&&w<time[i+]-time[i])//要保证他卖给第i个人后能睡觉
{
maxn=sum/i;
flag=w;
} }
printf("%.6lf %.6lf\n",flag,maxn);
}
return ;
}
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 ...
- zjuoj 3607 Lazier Salesgirl
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607 Lazier Salesgirl Time Limit: 2 Sec ...
- 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 ...
- [ACM_模拟][ACM_暴力] Lazier Salesgirl [暴力 懒销售睡觉]
Description Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making ...
- ZOJ 3607 Lazier Salesgirl 贪心
这个题比上个题简单得多,也是超过W时间会睡着,睡着就再也不会卖了,顾客按时间顺序来的,但是可能有顾客同时到(同时到如果醒着就全卖了),并且每个人只买一块面包,也是求最大的W,使得卖出面包的平均价格最高 ...
- ZOJ 3607 Lazier Salesgirl
Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling ...
- ZOJ 3607 Lazier Salesgirl(贪心)
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607 题意:一个卖面包的小姑娘,给第i个来买面包的人的价格是pi, ...
- 2012-2014 三年浙江 acm 省赛 题目 分类
The 9th Zhejiang Provincial Collegiate Programming Contest A Taxi Fare 25.57% (166/649) (水 ...
- ZOJ 3607贪心算法
http://blog.csdn.net/ffq5050139/article/details/7832991 http://blog.watashi.ws/1944/the-8th-zjpcpc/ ...
随机推荐
- EF6 CodeFirst+Repository+Ninject+MVC4+EasyUI实践(八)
前言 本篇幅将对系统的菜单管理模块进行说明,系统的菜单采用树形结构,这样可以更好地方便层级设计和查看.本示例将说明如何通过EntityFramework读取递归的菜单树形结构,以及结合EasyUI的t ...
- Go语言开发环境配置
一.我为什么要学习go语言 当今已经是移动和云计算时代,Go出现在了工业向云计算转型的时刻,简单.高效.内 置并发原语和现代的标准库让Go语言尤其适合云端软件开发(毕竟它就是为此而设计的).到2014 ...
- solution to E: failed to fetch .......
There are some issues today for me that my desktop can't boot as I expected, I installed windows 8.1 ...
- jquery tab 插件
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...
- Windows 通用应用尝试开发 “51单片机汇编”总结
一.前言 终于完成windows通用应用“51单片机汇编”,半年前开始玩WindowsPhone开发的第一个真正意义上的App(还很多缺点=_=).开发从1月中旬考完试到今天,期间实习了半个月,玩了几 ...
- ASP通过ADODB读取Access数据库
<% On Error Resume Next set conn=server.createobject("adodb.connection") mypath=server. ...
- FFmpeg:初步编译使用[Android]
1.安装NDK:http://dl.google.com/android/ndk/android-ndk-r9-linux-x86.tar.bz2 sudo gedit ~/.bashrc 末尾添加: ...
- 研二下学期做的第一个项目(主要关于datagridview的一些笔记)
首先是行标题列rowheader dataGridView1.TopLeftHeaderCell.Value = "details"; ______________________ ...
- JAVA中SERIALVERSIONUID的解释
serialVersionUID作用: 序列化时为了保持版本的兼容性,即在版本升级时反序列化仍保持对象的唯一性.有两种生成方式: 一个是默认的1L,比如:private st ...
- c++ redis-client
http://hahaya.github.io/operator-redis-under-linux/#0-tsina-1-10809-397232819ff9a47a7b7e80a40613cfe1 ...