Lazy Salesgirl


Time Limit: 5 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 some pieces of bread at price pi for each piece. 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 wake her up and leave without buying anything. Once she is woken up, she will start to sell bread again until she encounters another gap of w minutes. What's more weird, she can sell 1 + ((k - 1) mod 3) pieces of bread when she sells at the k-th time. It's known that she starts to sell bread now and the i-th customer comes after ti minutes. What is the minimum possible value of w that maximizes the average value of the bread sold each time?

Input

There are multiple test cases. The first line of input is an integer T ≈ 100 indicating the number of test cases.

The first line of each test case contains an integer 1 ≤ n ≤ 105 indicating the number of customers. The second line contains n integers 1 ≤ pi ≤ 106. The third line contains n integers 1 ≤ ti ≤ 107. All ti are different.

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
1 2 3 4
4 7 9 10

Sample Output

3.000000 4.666667
3.000000 6.666667

AC代码:线段树
 #include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int N = 1e5+;
const int W = ;
int sum[N*];
long long get[W+][N*];
double ansg,anst;
#define left l,m,x<<1
#define right m+1,r,x<<1|1
struct TT
{
int p,t;
bool operator<(const TT &y) const
{
return t<y.t;
} }pre[N];
struct pp
{
int id,w;
bool operator<(const pp &y) const
{
return w<y.w;
}
}mm[N];
void init()
{
ansg = anst = 0.0;
memset(sum,,sizeof(sum));
memset(get,,sizeof(get));
}
void pushup(int x)
{
sum[x] = sum[x<<] +sum[x<< | ];
int tem,i;
for(i=;i<=W;i++)
{
tem = (i+sum[x<<]-)%W+;
get[i][x] = get[i][x<<]+get[tem][x<< | ];
}
}
void update(int pos,long long p,int l,int r,int x)
{
if(l == r)
{
sum[x]++;
for(int i=;i<=W;i++)
get[i][x] = i*p;
return ;
}
int m = (l+r)>>;
if(pos<=m) update(pos,p,left);
if(pos>m) update(pos,p,right);
pushup(x);
}
int main()
{
int T,i,j,n;
double tem;
scanf("%d",&T);
while(T--)
{ init();
scanf("%d",&n);
for( i=;i<n;i++) scanf("%d",&pre[i].p);
for( i=;i<n;i++) scanf("%d",&pre[i].t);
sort(pre,pre+n);//对到来的时间进行排序
mm[].w = pre[].t;
mm[].id = ;
for( i=;i<n;i++)
{
mm[i].w = pre[i].t - pre[i-].t;//取时间差,然后相减,再对时间差进行排序;
mm[i].id = i;
}
sort(mm,mm+n);
for( i=;i<n;)
{
j=i;
while(j<n && mm[i].w == mm[j].w)
{
update(mm[j].id,pre[mm[j].id].p,,n-,);
j++;
}
tem = get[][]*1.0/sum[];
if(ansg <tem)
{
ansg = tem;
anst = mm[i].w;
}
i=j;
}
printf("%.6lf %.6lf\n",anst,ansg);
}
return ;
}

ZOJ 3606 Lazy Salesgirl 浙江省第九届省赛的更多相关文章

  1. ZOJ 3601 Unrequited Love 浙江省第九届省赛

    Unrequited Love Time Limit: 16 Seconds      Memory Limit: 131072 KB There are n single boys and m si ...

  2. ZOJ 3606 Lazy Salesgirl ( 线段树 + 思路 )

    卖切糕的小女孩 http://www.cnblogs.com/wuyiqi/archive/2012/04/28/2474672.html #include <cstdio> #inclu ...

  3. zjuoj 3606 Lazy Salesgirl

    http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3606 Lazy Salesgirl Time Limit: 5 Secon ...

  4. nyoj1273 河南省第九届省赛_"宣传墙"、状压DP+矩阵幂加速

    宣传墙 时间限制:1000 ms  |  内存限制:65535 KB 难度:4 描述 ALPHA 小镇风景美丽,道路整齐,干净,到此旅游的游客特别多.CBA 镇长准备在一条道路南 面 4*N 的墙上做 ...

  5. NYOJ 1272 表达式求值 第九届省赛 (字符串处理)

    title: 表达式求值 第九届省赛 nyoj 1272 tags: [栈,数据结构] 题目链接 描述 假设表达式定义为: 1. 一个十进制的正整数 X 是一个表达式. 2. 如果 X 和 Y 是 表 ...

  6. 河南省acm第九届省赛--《表达式求值》--栈和后缀表达式的变形--手速题

    表达式求值 时间限制:1000 ms | 内存限制:65535 KB 难度:3   描述 假设表达式定义为:1. 一个十进制的正整数 X 是一个表达式.2. 如果 X 和 Y 是 表达式,则 X+Y, ...

  7. NYOJ--1276--机器设备(河南省第九届省赛,简单的bfs)

    机器设备 时间限制:1000 ms  |  内存限制:65535 KB 难度:2   描述 Alpha 公司设计出一种节能的机器设备.它的内部结构是由 N 个齿轮组成.整个机器设备有 一个驱动齿轮,当 ...

  8. SD第九届省赛B题 Bullet

    Bullet Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Description In G ...

  9. 蓝桥杯第九届省赛 sscanf(),str.c_str()函数的使用

    标题:航班时间 [问题背景]小h前往美国参加了蓝桥杯国际赛.小h的女朋友发现小h上午十点出发,上午十二点到达美国,于是感叹到“现在飞机飞得真快,两小时就能到美国了”. 小h对超音速飞行感到十分恐惧.仔 ...

随机推荐

  1. Python爬虫学习笔记——豆瓣登陆(二)

    昨天能够登陆成功,但是不能使用cookies,今天试了一下requests库的Session(),发现可以保持会话了,代码只是稍作改动. #-*- coding:utf-8 -*- import re ...

  2. C# App.config 自定义 配置节 报错“配置系统未能初始化” 解决方法

    App.config,结果运行的时候出现了 "配置系统未能初始化" 的错误.找了半天才发现是下面的原因造成的: "如果配置文件中包含configSections元素,则c ...

  3. JVMInternals

    http://blog.jamesdbloom.com/JVMInternals.html http://blog.jamesdbloom.com/JavaCodeToByteCode_PartOne ...

  4. 二十四种设计模式:外观模式(Facade Pattern)

    外观模式(Facade Pattern) 介绍为子系统中的一组接口提供一个一致的界面,Facade模式定义了一个高层接口,这个接口使得这一子系统更加容易使用.示例有一个Message实体类,某对象对它 ...

  5. 023. Asp.net参数化查询预防Sql注入攻击

    /// <summary> /// 参数化查询预防SQL注入式攻击 /// </summary> public int checkLogin(string loginName, ...

  6. unity, 同步物体坐标一定要在LateUpdate中进行

    设a为主动物体,b为跟随物体. 如果a,b都在同一个Update里更新坐标,那么两者自然是同步的. 如果a在a.Update里更新位置,而b在b.Update里将自己的位置更新为与a相同,那就会有误差 ...

  7. OpenJudge就算概论-统计字符数

    /*===================================== 统计字符数 总时间限制: 1000ms 内存限制: 65536kB 描述 判断一个由a-z这26个字符组成的字符串中哪个 ...

  8. OpenJudge计算概论-文字排版

    /*====================================================================== 文字排版 总时间限制: 1000ms 内存限制: 65 ...

  9. SQL中 EXCEPT、INTERSECT用法

    EXCEPT 返回两个结果集的差(即从左查询中返回右查询没有找到的所有非重复值). INTERSECT 返回 两个结果集的交集(即两个查询都返回的所有非重复值). UNION返回两个结果集的并集. 语 ...

  10. jQuery 追加元素的方法如append、prepend、before

    1.jQuery append() 方法 jQuery append() 方法在被选元素的结尾插入内容. 实例 复制代码代码如下: $("p").append("Some ...