[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 ...
随机推荐
- 解决VMware“该虚拟机似乎正在使用中”问题
http://jingyan.baidu.com/article/4ae03de3fa2ae93eff9e6bb0.html
- HTML插入Flash的全兼容完美解决方案-SWFObject
Flash 嵌入的问题朋友们可能认为很简单,但是具体到一些问题上来讲,就不是那么简单了,比如:IE浏览器对FLASH的拦截虚框怎么去掉?在FF.OP.NS等其它浏览器是否兼容?代码是否符合W3C标准? ...
- ZMQ 在linux进程 和分布式之间的通信
ZMQ 在linux进程 和分布式之间的通信 待补全
- html() 和 text() 方法的区别
html()方法仅支持XHTML的文档,不能用于XML文档,而text()既支持HTML文档,也 支持XML文档. html():没有参数,用于获取html的值: html(val):有参数,用于设置 ...
- NLPP-03-Exercises
<PYTHON自然语言处理>第3章 处理原始文本 更多更复杂有关处理HTML内容 http://www.crummy.com/software/BeautifulSoup/ 3.11 深入 ...
- iOS 发送Email
第一步:在程序中添加MessageUi.framework框架 第二步:引入#import <MessageUI/MessageUI.h>头文件 第三步:代码实现 3.1判断是否可以发送邮 ...
- 创建solr集群简述
综述: 用两台服务器,每台服务器上启动两个solr实例(端口分别为8983.7574),即一共有2x2=4个节点.4个节点分散在两个分片上,每台机器上存放两个分片的各一个replica,这样等于每台机 ...
- [整理]PCB阻抗控制
之前一直听说PCB设计中信号完整性及阻抗方面的要求,但是本人对此还是有很多的不了解,每次和别人讨论到这里后就不知道该怎么继续就这个问题交谈下去.正巧最近手头有一点工作有这方面的一些需求,就拿来花了一点 ...
- AngularJs自定义指令详解(3) - scope
我们之所以要定义指令,目的是重用指令.假设有这么一个应用场景:在同一个html里使用了两次my-directive,第一个my-directive要展示的是Hello World,第二个my-dire ...
- GNU M4 - GNU Project - 免费软件基金会(FSF)
-------------------------------------------------------------------------------------- GNU M4介绍: GNU ...