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对超音速飞行感到十分恐惧.仔 ...
随机推荐
- 英语语法最终珍藏版笔记-18what 从句的小结
what 从句的小结 1.意思是“所….的事/物”, 相当于the thing(s) that…, that which…, 或those which… 可以用于以下情况: (1) 引导主语从句.如: ...
- android开源项目---blog篇
本文转载于:http://blog.csdn.net/likebamboo/article/details/19081241 主要介绍那些乐于分享并且有一些很不错的开源项目的个人和组织.Follow大 ...
- JPA的Column注解总结
就像@Table注解用来标识实体类与数据表的对应关系类似,@Column注解来标识实体类中属性与数据表中字段的对应关系. 该注解的定义如下: @Target({METHOD, FIELD}) @Ret ...
- 防止 SQL 注入的方法(摘抄)
——选自<深入Ajax : 架构与最佳实践 = Advanced Ajax : architecture and best practices/ (美)Shawn M.Lauriat著:张过,宋 ...
- linux下单节点oracle数据库间ogg搭建
环境说明: linux为Linux 2.6.32-573.el6.x86_64 oracle为 11g Enterprise Edition Release 11.2.0.1.0 - 64 ...
- javascript error
IE 6下expected identifier,string or number(缺少标示符.字符串或数字)其实就是多了一个逗号,之前没发现
- Unicode基本概念
Unicode是计算机可以支持这个星球上多种语言的秘密武器.通过使用一个或者多个字节来表示一个字符的方法突破了ASCII的限制.Unicode可以表示超过90000个字符. 使用方式:a=u'hell ...
- ISV 和SI 是什么
ISV是Independent Software Vendors 的英文缩写,意为"独立软件开发商",特指专门从事软件的开发.生产.销售和服务的企业,如微软(Microsoft). ...
- 014. asp.net实现记住密码的功能
protected void Button1_Click(object sender, EventArgs e) { if (txtname.Text.Trim().Equals("mr&q ...
- Python教程:[69]strip()函数详解
strip()用于裁剪字符串首尾的某些字符,是一个用处非常多的函数,今天我们来通过例子来探讨一下它的基本用法: 假如有一个这样的字符串 strip()不带任何参数,可以删除首位的空格 但是strip( ...