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. dom4j测试

    book.xml <?xml version="1.0" encoding="UTF-8"?><books><book>&l ...

  2. android屏幕亮度

    /** * 获得当前屏幕亮度的模式 * SCREEN_BRIGHTNESS_MODE_AUTOMATIC=1 为自动调节屏幕亮度 * SCREEN_BRIGHTNESS_MODE_MANUAL=0 为 ...

  3. 011. asp.net内置对象

    Response对象: Response代表了服务器响应对象, 主要用于将数据从服务器发送回浏览器; 每次客户端发出一个请求的时候,服务器就会用一个响应对象来处理这个请求,处理完这个请求之后,服务器就 ...

  4. linux服务之iptables与firewalld

    开发语言: 服务器端:在内核中实现,无守护程序 客户端:一般是cli界面下的iptables命令 相关包:iptables-1.4.7-11.el6.x86_64 netfilter/iptables ...

  5. DMALL刘江峰:生鲜市场具有巨大O2O改造空间

    今日,全球移动互联网大会(GMIC)在北京-国家会议中心开幕.DMALL创始人刘江峰在全球O2O峰会论坛作主题发言时谈到,生鲜市场具有巨大O2O改造空间.同时这也是刘江峰在离开荣耀之后首次登台介绍自己 ...

  6. ASP.NET MV3 部署网站 报"Could not load file or assembly ' System.Web.Helpers “ 错的解决方法

    转自:http://www.cnblogs.com/taven/archive/2011/08/14/2138077.html 国内很多网站空间都只支持.NET 2.0 和 .NET 3.0 3.5, ...

  7. C99新特性:变长数组(VLA)

    C99标准引入了变长数组,它允许使用变量定义数组各维.例如您可以使用下面的声明: ; ; double sales[rows][cols]; // 一个变长数组(VLA) 变长数组有一些限制,它必须是 ...

  8. C语言常用的小代码

    圆周率Pi tan(Pi/4)=1 => Pi=4*arctan(1) 反正切函数arctan()在C语言里表示为atan(),为保证精度取圆周率的代码如下: const double Pi = ...

  9. Effective Java 学习笔记----第7章 通用程序设计

    第7章 通用程序设计 第29条 将局部变量的作用域最小化     使一个局部变量的作用域最小化,最有力的技术室在第一次使用它的地方声明.   第30条 了解和使用库      效率提高.如果你不知道库 ...

  10. nginx服务器应用中遇到的两个问题

    1>首先是413的错误! client_max_body_size Context: http, server, location It is the maximum size of a cli ...