ZOJ 3606 Lazy Salesgirl ( 线段树 + 思路 )
卖切糕的小女孩
http://www.cnblogs.com/wuyiqi/archive/2012/04/28/2474672.html
#include <cstdio>
#include <cstring>
#include <algorithm> #define lson l, m, rt << 1
#define rson m+1, r, rt << 1 | 1
#define lc rt << 1
#define rc rt << 1 | 1
#define LL long long int using namespace std; const int MAXN = ;
const double INF = 1e100;
const double eps = 1e-; struct node
{
int p;
int t;
int id;
}; int N;
int cnt[MAXN << ];
LL sum[][MAXN << ];
node D1[MAXN], D2[MAXN]; bool cmp( const node& a, const node& b )
{
return a.t < b.t;
} void build( int l, int r, int rt )
{
cnt[rt]=;
for ( int i = ; i < ; ++i ) sum[i][rt] = ;
if ( l == r ) return;
int m = ( l + r ) >> ;
build( lson );
build( rson );
return;
} void PushUp( int rt )
{
cnt[rt] = cnt[lc] + cnt[rc];
for ( int i = ; i < ; ++i )
sum[i][rt] = sum[i][lc] + sum[ (i+cnt[lc])% ][rc];
return;
} void update( int L, int l, int r, int rt )
{
if ( l == r && L == l )
{
++cnt[rt];
for ( int i = ; i < ; ++i )
sum[i][rt] += (LL)D1[L].p * (i + );
return;
} int m = ( l + r ) >> ;
if ( L <= m ) update( L, lson );
else update( L, rson );
PushUp( rt );
return;
} void init()
{
scanf( "%d", &N );
build( , N, );
for ( int i = ; i <= N; ++i )
scanf( "%d", &D1[i].p );
for ( int i = ; i <= N; ++i )
scanf( "%d", &D1[i].t ); sort( D1 + , D1 + N + , cmp ); D2[].t = ;
for ( int i = ; i <= N; ++i )
{
D2[i].id = i;
D2[i].t = D1[i].t - D1[i - ].t;
}
sort( D2 + , D2 + N + , cmp );
return;
} void solved()
{
double minW;
double maxAve = 0.0;
int i = , j = ;
while ( i <= N )
{
while ( j <= N && D2[i].t == D2[j].t )
{
update( D2[j].id, , N, );
++j;
} double tmpW = (double)D2[i].t;
double tmpA = (double)sum[][]/cnt[];
//printf( "tmp: %f %f\n", tmpW, tmpA ); if ( tmpA > maxAve )
{
maxAve = tmpA;
minW = tmpW;
}
else if ( tmpA == maxAve )
{
if ( minW > tmpW )
minW = tmpW;
}
i = j;
}
printf( "%.6f %.6f\n", minW, maxAve );
return;
} int main()
{
int T;
scanf( "%d", &T );
while (T--)
{
init();
solved();
}
return ;
}
ZOJ 3606 Lazy Salesgirl ( 线段树 + 思路 )的更多相关文章
- ZOJ 3606 Lazy Salesgirl 浙江省第九届省赛
Lazy Salesgirl Time Limit: 5 Seconds Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who ma ...
- zjuoj 3606 Lazy Salesgirl
http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemCode=3606 Lazy Salesgirl Time Limit: 5 Secon ...
- zoj 3511 Cake Robbery(线段树)
problemCode=3511" target="_blank" style="">题目链接:zoj 3511 Cake Robbery 题目 ...
- 分块+lazy 或者 线段树+lazy Codeforces Round #254 (Div. 2) E
E. DZY Loves Colors time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
- bzoj 2957 楼房重建 (线段树+思路)
链接: https://www.lydsy.com/JudgeOnline/problem.php?id=2957 思路: 用分块可以很简单的过掉,但是这道题也可以用线段树写. 分类讨论左区间最大值对 ...
- ZOJ 2859 二维线段树
思路:自己写的第二发二维线段树1A.哈哈,看来对二维的push操作比較了解了:可是还没遇到在两个线段树中同一时候进行push操作的,事实上这题我是想在x维和y维同一时候进行push操作的.可是想了好久 ...
- ZOJ 2301/HDU 1199 线段树+离散化
给这个题目跪了两天了,想吐简直 发现自己离散化没学好 包括前一个离散化的题目,实际上是错了,我看了sha崽的博客后才知道,POJ那题简直数据弱爆了,本来随便一组就能让我WA掉的,原因在于离散化的时候, ...
- HDU 4189 Cybercrime Donut Investigation 线段树+思路
参考:http://www.cnblogs.com/slon/archive/2012/03/30/2426104.html 题意:给一个有n个点的点集,有q个询问,每个询问询问一个点p,求与p曼哈顿 ...
- zoj 3325 Machine(线段树)
题意:0~n-1的数组,初始值为0:执行m个操作,每次操作执行后输出当前值为0的连续段的段数. 操作1: p i j : i~j区间的每个元素值减1 操作2: r i j :i~j区间的每个元素值加1 ...
随机推荐
- 【洛谷P1379】八数码难题(广搜、A*)
八数码难题 题目描述 一.广搜: 首先要考虑用什么存每一个状态 显然每个状态都用一个矩阵存是很麻烦的. 我们可以考虑将一个3*3的矩阵用一个字符串或long long 存. 每次扩展时再转化为矩阵. ...
- >题解< 校门外的树
题目描述 某校大门外长度为L的马路上有一排树,每两棵相邻的树之间的间隔都是 11 米.我们可以把马路看成一个数轴,马路的一端在数轴 00 的位置,另一端在 LL 的位置:数轴上的每个整数点,即 0,1 ...
- poj_1320_Street Numbers
A computer programmer lives in a street with houses numbered consecutively (from 1) down one side of ...
- 《Python语言及其应用》学习笔记
第二章 ========== 对象的类型决定了可以对它进行的操作.对象的类型还决定了它装着的数据是允许被修改的变量(可变的),还是不可被修改的常量(不可变的). Python是强类型的,你永远无法修改 ...
- python3 练习题100例 (十七)四位车号问题
#!/usr/bin/env python3 # -*- coding: utf-8 -*- __author__ = 'Fan Lijun' import math for i in range(1 ...
- 【异常】The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone.
异常错误:The server time zone value 'Öйú±ê׼ʱ¼ä' is unrecognized or represents more than one time zone ...
- SGU495 概率DP
Kids and Prizes ICPC (International Cardboard Producing Company) is in the business of producing car ...
- POJ:3104-Drying(神奇的二分)
Drying Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 20586 Accepted: 5186 Description I ...
- 在MAC下使用Robotframework+Selenium2【第二枪】如何处理Table点击指定记录
1.通过关键字Get Matching Xpath Count获取table中的记录 2.遍历Table所有记录 3.判断记录是否符合条件,做点击操作
- 1 web应用
web应用 Web应用程序是一种可以通过Web访问的应用程序,程序的最大好处是用户很容易访问应用程序,用户只需要有浏览器即可,不需要再安装其他软件.应用程序有两种模式C/S.B/S.C/S是客户端/服 ...