ZOJ 3607 Lazier Salesgirl
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
贪心用map存储时间间隔。
只有两种情况:
如果后面的时间间隔比前面出现的最大的时间间隔还大的话,新建键值对存到map。
反之,在原来的最大时间间隔上进行处理。
#include <stdio.h>
#include <map>
#include <iostream>
#include <algorithm>
using namespace std; int n;
int cnt;
int sum[];
map< double , double > M;
map< double , double >::iterator it; struct Node{
int p,t;
}nod[]; bool cmp(Node n1, Node n2){
return n1.t<n2.t;
} int main(){
int t;
int i,j;
scanf("%d",&t);
while( t-- ){
scanf("%d" ,&n);
for(i=; i<n; i++){
scanf("%d" ,&nod[i].p);
}
for(i=; i<n; i++){
scanf("%d" ,&nod[i].t);
}
sort(nod ,nod+n ,cmp);
M.clear();
for(i=; i<n; i++){
if(i==){
sum[i]=nod[i].p;
}else{
sum[i]=sum[i-]+nod[i].p;
}
}
cnt=nod[].t;
M[cnt]=nod[].p;
for(i=; i<n; i++){
if( nod[i].t-nod[i-].t>cnt ){
cnt=nod[i].t-nod[i-].t;
M[cnt]=double(sum[i])/(i+);
}else{
M[cnt]=double(sum[i])/(i+);
}
}
double w=;
double maxValue=;
for(it=M.begin(); it!=M.end(); it++){
if( it->second > maxValue ){
w=it->first;
maxValue=it->second;
}
}
printf("%.6lf %.6lf\n",w,maxValue);
}
return ;
}
ZOJ 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 ...
- ZOJ 3607 Lazier Salesgirl(贪心)
题目:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607 题意:一个卖面包的小姑娘,给第i个来买面包的人的价格是pi, ...
- ZOJ 3607 Lazier Salesgirl 贪心
这个题比上个题简单得多,也是超过W时间会睡着,睡着就再也不会卖了,顾客按时间顺序来的,但是可能有顾客同时到(同时到如果醒着就全卖了),并且每个人只买一块面包,也是求最大的W,使得卖出面包的平均价格最高 ...
- zjuoj 3607 Lazier Salesgirl
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607 Lazier Salesgirl Time Limit: 2 Sec ...
- H - Lazier Salesgirl
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Status Practic ...
- ZOJ 3607贪心算法
http://blog.csdn.net/ffq5050139/article/details/7832991 http://blog.watashi.ws/1944/the-8th-zjpcpc/ ...
- ZOJ 3606 Lazy Salesgirl 浙江省第九届省赛
Lazy Salesgirl Time Limit: 5 Seconds Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who ma ...
- [ACM_模拟][ACM_暴力] Lazier Salesgirl [暴力 懒销售睡觉]
Description Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making ...
- 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 ...
随机推荐
- Delphi 调试连接 任意Android手机/平板/盒子(要安装Google USB Driver,并且还有USB的相关许多文章)
Delphi有时候无法连接调试一些手机,解决方案: 1.安装Google USB Driver 2.通过设备管理器查看手机或平板USB的VID,PID 3.修改你的电脑上的android_winusb ...
- LoadRunner10个用户并发测试时分别取不同的参数运行脚本
使用场景,比如说10个用户使用不同的账户名和密码同时并发登录,此时选择如下参数化策略: 参数选择:select next row 选择unique update value on 选择 once 另一 ...
- 性能测试工具Locust的介绍和使用
内容来自网络 https://www.w3xue.com/exp/article/20191/16707.html https://blog.csdn.net/qq_36255988/article/ ...
- ASP.NET Core中使用自定义验证属性控制访问权限
在应用中,有时我们需要对访问的客户端进行有效性验证,只有提供有效凭证(AccessToken)的终端应用能访问我们的受控站点(如WebAPI站点),此时我们可以通过验证属性的方法来解决. 一.publ ...
- CF1106F Lunar New Year and a Recursive Sequence(矩阵快速幂+bsgs+exgcd)
题面 传送门 前置芝士 \(BSGS\) 什么?你不会\(BSGS\)?百度啊 原根 对于素数\(p\)和自然数\(a\),如果满足\(a^x\equiv 1\pmod{p}\)的最小的\(x\)为\ ...
- 洛谷P3783 [SDOI2017]天才黑客(前后缀优化建图+虚树+最短路)
题面 传送门 题解 去看\(shadowice\)巨巨写得前后缀优化建图吧 话说我似乎连线段树优化建图的做法都不会 //minamoto #include<bits/stdc++.h> # ...
- 关于<ul> 下的 <li> 里面的<a> 标签字体颜色不能控制
1.元展示 <ul class="ul"> <li><a href="#">菜单一</a></li> ...
- screen新建窗口,环境变量跟原来不一致。
昨天为了方便npm安装全局包,我把环境变量重新配置了. 然后,在项目中引用全局包没有出问题.但是后来我在screen里面引用全局包,报错说找不到. 使用#npm list -g命令 发现昨天的全局包都 ...
- 阿里云服务主机部署Thinkphp系统错误解决方案
最近在阿里云上购买了虚拟主机,于是有了把自己的网站挂在云上的冲动,那就行动呗.本来想的很简单,以为在修改数据库配置之后,将文件打包上传,然后就可以了,可在实际操作过程中,出现了很多问题,找了很多资料, ...
- MongoDB mongo.exe启动及闪退解决 转载
转载自:http://blog.csdn.net/wyx_wx/article/details/76108662 启动: 进入MongoDB安装目录下的bin目录,启动mongod.exe 出现如图所 ...