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 ...
随机推荐
- java利用HttpClient进行https接口调用
1.为了避免需要证书,所以用一个类继承DefaultHttpClient类,忽略校验过程. import java.security.cert.CertificateException; import ...
- BZOJ 1977 严格次小生成树
小C最近学了很多最小生成树的算法,Prim算法.Kurskal算法.消圈算法等等.正当小C洋洋得意之时,小P又来泼小C冷水了.小P说,让小C求出一个无向图的次小生成树,而且这个次小生成树还得是严格次小 ...
- 多线程“尚未调用coinitialize” 报错
关于多线程中创建使用TADOConnect.TADODataSet等Com组件时,必须先初始化Com 在多线程启用执行前 CoInitialize(nil); 在多线程启用执行后 CoUninitia ...
- Android-Activity临时数据的保存
Activity临时数据的保存是非常重要的,例如:一款小说APP应用,读者使用这款APP看到了223页,用户也没有去记看了多少页: 突然去接了个电话,或者开启的应用程序太多了,可能会导致这款APP应用 ...
- mysql按照天或小时group分组统计
select DATE_FORMAT( deteline, "%Y-%m-%d %H" ) , COUNT( * ) FROM test GROUP BY DATE_FORMAT( ...
- LDAP 相关链接
http://www.cnblogs.com/fish-li/archive/2012/05/07/2486840.html细说ASP.NET Windows身份认证 http://www.cnblo ...
- C# 根据实体类的属性动态生成字符串
情景: 目前有两个实体类:Student,ClassInfo. public class Student { public string Name { get; set; } public strin ...
- sharepoint用户信息同步出错
首先使用工具定位问题,然后权限不够授予权限 C:\Program Files\Microsoft Office Servers\15.0\Synchronization Service\UIShell
- Collection 集合框架
1. Collection 集合框架:在实际开发中,传统的容器(数组)在进行增.删等操作算法和具体业务耦合在一起,会增加程序的开发难度:这时JDK提供了这样的容器---Collection 集合框架, ...
- windbg符号路径设置
.sympath C:\Users\leoyin\Desktop\last;SRV*C:\Symbols*http://msdl.microsoft.com/download/symbols