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 录像
delphi xe系列自带的控件都无法保存录像,经网友帮忙,昨天终于实现了录像功能(但有个问题是录像时无画面显示),程序主要使用了JMediaRecorder,MediaRecorder的使用方法可参 ...
- python版本selenium定位方式(不止八种哦)
除了大家熟知的8种定位方式之外 1.id定位:find_element_by_id(self, id_)2.name定位:find_element_by_name(self, name)3.class ...
- nginx uwsgi flask相关配置
一.安装Nginx 在 /home/download下下载压缩包 wget https://nginx.org/download/nginx-1.12.2.tar.gz 解压缩 tar zxvf ng ...
- Collection 集合框架
1. Collection 集合框架:在实际开发中,传统的容器(数组)在进行增.删等操作算法和具体业务耦合在一起,会增加程序的开发难度:这时JDK提供了这样的容器---Collection 集合框架, ...
- “全栈2019”Java第七十四章:内部类与静态内部类相互嵌套
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
- php 获取 post 请求体参数
private function getPostData() { $postdata = file_get_contents("php://input"); $data = url ...
- [ActionSprit 3.0] FMS客户端与服务器端交互(传参)
客户端as: import flash.net.NetConnection; import flash.events.NetStatusEvent; var nc:NetConnection = ne ...
- [ActionScript 3.0] 通过BitmapData将对象保存成jpg图片
此方法需要用到JPGEncoder.as和BitString.as这两个类,是将BitmapData对象转换成ByteArray,然后通过FileStream把此ByteArray写入到文件保存成jp ...
- C#-★结构体★
结构体: 结构体类型是用户自己定义的一种类型,它是由其他类型组合而成的,可包含构造函数.常数.字段.方法.属性.索引器.运算符.事件和嵌套类型的值类型. 结构体在几个方面不同于类:结构体为值类型而不是 ...
- js中一切都是对象
<script> function cat(){} var cat = new cat(); console.log(cat.constructor) console.log(typeof ...