卖切糕的小女孩

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 ( 线段树 + 思路 )的更多相关文章

  1. ZOJ 3606 Lazy Salesgirl 浙江省第九届省赛

    Lazy Salesgirl Time Limit: 5 Seconds      Memory Limit: 65536 KB Kochiya Sanae is a lazy girl who ma ...

  2. zjuoj 3606 Lazy Salesgirl

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

  3. zoj 3511 Cake Robbery(线段树)

    problemCode=3511" target="_blank" style="">题目链接:zoj 3511 Cake Robbery 题目 ...

  4. 分块+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 ...

  5. bzoj 2957 楼房重建 (线段树+思路)

    链接: https://www.lydsy.com/JudgeOnline/problem.php?id=2957 思路: 用分块可以很简单的过掉,但是这道题也可以用线段树写. 分类讨论左区间最大值对 ...

  6. ZOJ 2859 二维线段树

    思路:自己写的第二发二维线段树1A.哈哈,看来对二维的push操作比較了解了:可是还没遇到在两个线段树中同一时候进行push操作的,事实上这题我是想在x维和y维同一时候进行push操作的.可是想了好久 ...

  7. ZOJ 2301/HDU 1199 线段树+离散化

    给这个题目跪了两天了,想吐简直 发现自己离散化没学好 包括前一个离散化的题目,实际上是错了,我看了sha崽的博客后才知道,POJ那题简直数据弱爆了,本来随便一组就能让我WA掉的,原因在于离散化的时候, ...

  8. HDU 4189 Cybercrime Donut Investigation 线段树+思路

    参考:http://www.cnblogs.com/slon/archive/2012/03/30/2426104.html 题意:给一个有n个点的点集,有q个询问,每个询问询问一个点p,求与p曼哈顿 ...

  9. zoj 3325 Machine(线段树)

    题意:0~n-1的数组,初始值为0:执行m个操作,每次操作执行后输出当前值为0的连续段的段数. 操作1: p i j : i~j区间的每个元素值减1 操作2: r i j :i~j区间的每个元素值加1 ...

随机推荐

  1. CXF报错[1 counts of IllegalAnnotationExceptions]and[Two classes have the same XML type name]and[Use @XmlType.name and @XmlType.namespace to assign different names to them]

    启动时CXF报错如下: Caused by: com.sun.xml.bind.v2.runtime.IllegalAnnotationsException: 1 counts of IllegalA ...

  2. 2.Mysql集群------Mycat读写分离

    前言: Mycat: 一个彻底开源的,面向企业应用开发的大数据库集群 支持事务.ACID.可以替代MySQL的加强版数据库 一个可以视为MySQL集群的企业级数据库,用来替代昂贵的Oracle集群 一 ...

  3. Tomcat启动排查

    Tomcat启动排查 一.参考 https://blog.csdn.net/baidu_32739019/article/details/64155136

  4. iOS开发网络缓存原理

    一.关于同一个URL的多次请求 有时候,对同一个URL请求多次,返回的数据可能都是一样的,比如服务器上的某张图片,无论下载多少次,返回的数据都是一样的. 上面的情况会造成以下问题 (1)用户流量的浪费 ...

  5. 【shopex】真正可用的app开发机制

    shopex的app开发机制详解   网上流传的shopex4.8.5的app开发教程,不仅说得不明不白,而且由于版本问题,照着做根本是做不成的. 知其然,亦要知其所以然. shopex提供了的一个干 ...

  6. MySQL创建民族表的SQL语句

    MySQL创建民族表的SQL语句 CREATE TABLE `nation` ( `id` ) unsigned NOT NULL AUTO_INCREMENT, `nation` ) NOT NUL ...

  7. MLT教程:从BXL文件导入Altium Designer原理图封装和PCB封装

    在TI官网的封装文件中提供弄BXL文件可以导出Altium Designer的封装库和原理图库. 这个界面往下面拉会看到: 然后可以下载各种封装的bxl文件了.下面视频说明bxl文件如何导出成功. 如 ...

  8. opencv中对图像的像素操作

    1.对灰度图像的像素操作: #include<iostream> #include<opencv2/opencv.hpp> using namespace std; using ...

  9. [Codeforces947D]Riverside Curio(思维)

    Description 题目链接 Solution 设S[i]表示到第i天总共S[i]几个标记, 那么满足S[i]=m[i]+d[i]+1 m[i]表示水位上的标记数,d[i]表示水位下的标记数 那么 ...

  10. 使用Windows Live Writer写文章时不要用360清除垃圾

    ref:http://www.zhengsiwei.com/write-an-article-to-use-windows-live-writer-dont-use-360-to-remove-rub ...