ZOJ 3606 Lazy Salesgirl 浙江省第九届省赛
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 浙江省第九届省赛的更多相关文章
- ZOJ 3601 Unrequited Love 浙江省第九届省赛
Unrequited Love Time Limit: 16 Seconds Memory Limit: 131072 KB There are n single boys and m si ...
- ZOJ 3606 Lazy Salesgirl ( 线段树 + 思路 )
卖切糕的小女孩 http://www.cnblogs.com/wuyiqi/archive/2012/04/28/2474672.html #include <cstdio> #inclu ...
- zjuoj 3606 Lazy Salesgirl
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3606 Lazy Salesgirl Time Limit: 5 Secon ...
- nyoj1273 河南省第九届省赛_"宣传墙"、状压DP+矩阵幂加速
宣传墙 时间限制:1000 ms | 内存限制:65535 KB 难度:4 描述 ALPHA 小镇风景美丽,道路整齐,干净,到此旅游的游客特别多.CBA 镇长准备在一条道路南 面 4*N 的墙上做 ...
- NYOJ 1272 表达式求值 第九届省赛 (字符串处理)
title: 表达式求值 第九届省赛 nyoj 1272 tags: [栈,数据结构] 题目链接 描述 假设表达式定义为: 1. 一个十进制的正整数 X 是一个表达式. 2. 如果 X 和 Y 是 表 ...
- 河南省acm第九届省赛--《表达式求值》--栈和后缀表达式的变形--手速题
表达式求值 时间限制:1000 ms | 内存限制:65535 KB 难度:3 描述 假设表达式定义为:1. 一个十进制的正整数 X 是一个表达式.2. 如果 X 和 Y 是 表达式,则 X+Y, ...
- NYOJ--1276--机器设备(河南省第九届省赛,简单的bfs)
机器设备 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 Alpha 公司设计出一种节能的机器设备.它的内部结构是由 N 个齿轮组成.整个机器设备有 一个驱动齿轮,当 ...
- SD第九届省赛B题 Bullet
Bullet Time Limit: 1000 ms Memory Limit: 65536 KiB Submit Statistic Discuss Problem Description In G ...
- 蓝桥杯第九届省赛 sscanf(),str.c_str()函数的使用
标题:航班时间 [问题背景]小h前往美国参加了蓝桥杯国际赛.小h的女朋友发现小h上午十点出发,上午十二点到达美国,于是感叹到“现在飞机飞得真快,两小时就能到美国了”. 小h对超音速飞行感到十分恐惧.仔 ...
随机推荐
- 最长不下降子序列的O(n^2)算法和O(nlogn)算法
一.简单的O(n^2)的算法 很容易想到用动态规划做.设lis[]用于保存第1~i元素元素中最长不下降序列的长度,则lis[i]=max(lis[j])+1,且num[i]>num[j],i&g ...
- Verilog
1.位拼接运算符{}
- EJB 的理解
引用源:http://blog.csdn.NET/cymm_liu/article/details/7760989 1.EJB 概念的剖析 我们先看一下,EJB 的官方解释: 商务软件的核心部分是它的 ...
- Apache Shiro 手册
(一)Shiro架构介绍 一.什么是Shiro Apache Shiro是一个强大易用的Java安全框架,提供了认证.授权.加密和会话管理等功能: 认证 - 用户身份识别,常被称为用户"登录 ...
- MySQL数据库update更新子查询
比如: ? 1 2 3 4 UPDATE test.tb_vobile a set a.name = '111 ' WHERE a.id = (select max(id) id from test. ...
- JS刷新页面的几种方法(转)
Javascript刷新页面的几种方法: 1 history.go(0) 2 location.reload() 3 location=location 4 location.assign(locat ...
- 浅析Struts1和Struts2的Action线程安全问题 转
浅析Struts1和Struts2的Action线程安全问题 转 http://blog.csdn.net/virgoboy2004/article/details/5876133 [问题描述]最近 ...
- CSS 使用小结
1.文字过长显示省略号(....) white-space: nowrap;overflow: hidden;text-overflow: ellipsis; 2.获取当前的ID : <asp ...
- Innodb 存储引擎(转)
第一部分:线程 Innodb是一个多线程的,各个线程负责不同的任务.主要的线程有:Master Thread.IO Thread.Purge Thread.Page Cleaner Thread. 一 ...
- R(七): R开发实例-map热力图
第四章通过REmap包完成基于map分布图示例,前面提到REmap基于Echart2.0, 一方面在移动终端适应效果差,另一方面REmap提供的热力图仅支持全国及省市大版块map,基于上面的原因,参考 ...