zjuoj 3607 Lazier Salesgirl
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3607
Lazier Salesgirl
Time Limit: 2 Seconds Memory Limit: 65536 KB
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 nintegers 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
Author: WU, Zejun
Contest: The 9th Zhejiang Provincial Collegiate Programming Contest
分析:
求当睡觉时间最短,卖出的面包平均价格最高时的W和平均值,注意:当他睡着的时候就不再醒啦,,,
AC代码:
#include<cstdio>
#include<algorithm>
using namespace std;
int sum[],b[];
int main() {
int t;
scanf("%d",&t);
while(t--) {
int n;
scanf("%d",&n);
int tmp;
for(int i = ;i <= n;i++) {
scanf("%d",&tmp);
sum[i] = sum[i-] + tmp;
// printf("%d -- ",sum[i]);
} for(int i = ;i <= n;i++){
scanf("%d",&b[i]);
} double ma = ;
int maxT = ,res = ;
for(int i = ;i <= n;i++) {
if(b[i] - b[i - ] > maxT) {
maxT = b[i] - b[i - ];
}
while(i <= n && b[i] - b[i - ] <= maxT) i++;
i--;
if(1.0 * sum[i] / (i) > ma) {
ma = 1.0 * sum[i] / (i);
res = maxT;
}
}
printf("%.6lf %.6lf\n",res * 1.0,ma);
}
return ;
}
zjuoj 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,使得卖出面包的平均价格最高 ...
- ZOJ 3607 Lazier Salesgirl
Kochiya Sanae is a lazy girl who makes and sells bread. She is an expert at bread making and selling ...
- H - Lazier Salesgirl
Time Limit:2000MS Memory Limit:65536KB 64bit IO Format:%lld & %llu Submit Status Practic ...
- zjuoj 3606 Lazy Salesgirl
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3606 Lazy Salesgirl Time Limit: 5 Secon ...
- [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 ...
- ZOJ 3607贪心算法
http://blog.csdn.net/ffq5050139/article/details/7832991 http://blog.watashi.ws/1944/the-8th-zjpcpc/ ...
随机推荐
- C程序演示产生僵死进程的过程
先抄录网上一段对僵死进程的描述: 僵尸进程:一个进程使用fork创建子进程,如果子进程退出,而父进程并没有调用wait或waitpid获取子进程的状态信息,那么子进程的进程描述符仍然保存在系统中.这种 ...
- C#注意事项及错误处理
1 使用到config文件配置数据库路径 ConfigurationManager.ConnectionStrings["dbPath"].ConnectionString; db ...
- jsp实现过滤器的简单例子
web.xml配置如下: <?xml version="1.0" encoding="UTF-8"?> <web-app xmlns=&quo ...
- webservice的Axis2入门教程java版
本文转自百度文库 Axis2是一套崭新的WebService引擎,该版本是对Axis1.x重新设计的产物.Axis2不仅支持SOAP1.1和SOAP1.2,还集成了非常流行的REST WebServi ...
- onselectstart
以前在做图片滚动时,在双击左右箭头,快速切换图片滚动时,会选择附近区域的文字,感觉不是很好,今天在同事在分享时,讲到了这个问题, 试了一下,不错,解决了问题IE及Chrome下的方法一样,对相应的元素 ...
- 1055. The World's Richest (25)
Forbes magazine publishes every year its list of billionaires based on the annual ranking of the wor ...
- java解析xml文档(dom)
DOM解析XML文档 读取本地的xml文件,通过DOM进行解析,DOM解析的特点就是把整个xml文件装载入内存中,形成一颗DOM树形结构,树结构是方便遍历和和操纵. DOM解析的特性就是读取xml文件 ...
- django1.9 创建数据表
1.在setting.py 中注册app: 2.编写models.py 文件创建表结构: (生成的表默认是: app名称_定义的表面 ) 3.执行命令: python manage.py check ...
- css小记(3)
1.只有块级元素可以设置背景图,行内元素要变成块级元素才可以:2.盒子不设置宽度,只设置高度,默认为100%,并自适应屏幕大小变化,为这个盒子设置margin可以在保证margin效果的同时默认调整盒 ...
- 配置RAC到单节点standby的data guard
1RAC主库准备 2创建物理备库 3主库调整参数 4测试DG