[ACM_模拟][ACM_暴力] 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 题目大意:T种情况,每种n个客人,第i个客人可赚p[i]元钱,第i个客人t[i]时间来,卖东西的很懒,如果w时间内没人来就睡觉,一觉不起,求最大人均赚的钱同时输出最小w.
解题思路:暴力枚举每次在第i个顾客来后睡。用w[i]保存想赚第i个人w的最小值,用av[i]保存赚前i个顾客的平均值。如果在第i个顾客来后睡觉就要满足w[i]<w[i+1](这个式子表明第i和第i+1个顾客之间的时间间隔比之前的都大,所以可以取w=w[i]来在这点后睡觉不醒)
#include<iostream>
#include<string.h>
#include<cstring>
#include<cstdio>
#include<string>
using namespace std;
int main(){
int T;cin>>T;
while(T--){
int n;cin>>n;
int p[],t[];
//w[i]表示赚第i个人需要w的最小值;av[i]表示前i个的人均赚钱数
double w[],av[];
double sum=;
for(int i=;i<n;i++){
cin>>p[i];
sum+=p[i];
av[i]=sum/(i+);
}
double max_w=-;
for(int i=;i<n;i++){
cin>>t[i];
if(i!=){
if(t[i]-t[i-]>max_w){
max_w=t[i]-t[i-];
w[i]=max_w;
}else w[i]=max_w;
}
else {
max_w=t[];
w[i]=max_w;
}
}w[n]=;//w[n]赋值很高 int pos=;double max_av=-;//暴力枚举在i点睡着
for(int i=;i<=n;i++){
if(w[i]<w[i+]){
if(av[i]>max_av){
max_av=av[i];
pos=i;
}
}
} printf("%.6lf %.6lf\n",w[pos],av[pos]);
}return ;
}
[ACM_模拟][ACM_暴力] Lazier Salesgirl [暴力 懒销售睡觉]的更多相关文章
- [ACM_模拟][ACM_数学] LA 2995 Image Is Everything [由6个视图计算立方体最大体积]
Description Your new company is building a robot that can hold small lightweight objects. The robo ...
- zjuoj 3607 Lazier Salesgirl
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607 Lazier Salesgirl Time Limit: 2 Sec ...
- ZOJ 3607 Lazier Salesgirl (枚举)
Lazier Salesgirl Time Limit: 2 Seconds Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who makes ...
- 玲珑杯”ACM比赛 Round #18 A -- 计算几何你瞎暴力(瞎暴力)
题目链接:http://www.ifrog.cc/acm/problem/1143?contest=1020&no=0 题解:就是瞎暴力具体多暴力看一下代码就知道了. #include < ...
- ACM_跳坑小能手(暴力)
跳坑小能手 Time Limit: 2000/1000ms (Java/Others) Problem Description: GDUFE-GAME现场有一个游戏场地人头窜动,围观参与游戏的学生在场 ...
- [CSP-S模拟测试]:打扫卫生(暴力)
题目描述 有$N$头奶牛,每头那牛都有一个标号$P_i1\leqslant Pi\leqslant M\leqslant N\leqslant 40,000$.现在$Farmer\ John$要把这 ...
- [CSP-S模拟测试]:String Master(暴力)
题目描述 所谓最长公共子串,比如串$A:"abcde"$,串$B:"jcdkl"$,则它们的最长公共子串为串$"cd"$,即长度最长的字符串 ...
- [ACM_模拟] POJ1068 Parencodings (两种括号编码转化 规律 模拟)
Description Let S = s1 s2...s2n be a well-formed string of parentheses. S can be encoded in two diff ...
- 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 ...
随机推荐
- MySQL计算销售员昨日各指标综合得分_20161206
数据需求如上,新增重激活以15天未下单为界定 SELECT d.销售员,(日销售额得分*0.6+日新增客户数得分*0.15+日客单价得分*0.1+日客户平均产品数得分*0.15)AS 综合得分,日销售 ...
- div一直浮动在页面的底部
永远在底部是那种无论滚动条怎么拉,都可以看见悬浮在底部的那种,如果是那种,是用固定定位做的.另外注意页面中最后的元素或者body要空出固定条的高度,不然最后的元素会被遮挡. html: <div ...
- 设置表格td宽度
CSS布局,表格宽度不听使唤的实例.想把表格第一例宽度设为20,其他自适应.但CSS中宽度是等宽的.只设这一行也不起作用.但是在实际应用中总是等宽处理,并不按照样式来走. XML/HTML代码 & ...
- [vivado系列]设置Xilinx Documention Navigator
版本:2015.1 ------------------------------------------ 这是一个很便利FPGA工程师的文档整理收纳神器. 针对个人使用上的习惯,进行简单的2项设置. ...
- 为什么V8引擎这么快?
目录(?)[-] 高速引擎的需求 语言本身的问题 JIT编译 JIT Compile 垃圾回收管理 内嵌缓存inline cache 隐藏类 内嵌缓存Inline Cache 机器语言的特性 附录熟悉 ...
- VC++ WINDOWS自定义消息范围
WINDOWS自定义消息WM_USER和WM_APP WM_USER常量是Windows帮助应用程序定义私有窗口类里的私有消息,通常使用WM_USER+一个整数值,但总值不能超过0x7FFF(十进制: ...
- html制作,点击文字超链接显示文本框,再点击文字超链接隐藏文本框
</head><body> <script> window.onload=function(){ document.getElementById('click'). ...
- HTML5和CSS3基础教程(第8版)-读书笔记(4)
第16章 表单 表单有两个基本组成部分:访问者在页面上可以看见并填写的控件.标签和按钮的集合:以及用于获取信息并将其转化为可以读取或计算的格式的处理脚本. 基本的表单字段类型包括文本框.单选按钮.复选 ...
- python学习之——计算文件行数
# -*- coding: cp936 -*- #转载源于:http://blog.csdn.net/houyj1986/article/details/21196027 #计算文件行数 #1.文件比 ...
- main与对象初始化 in C++
没有学过代码编译的原理,以前也没有兴趣去学编译器的相关原理,但是近期通过阅读google开源项目gtest,对我稍有触动. 代码: main test示例 TEST宏定义 #define TEST(t ...