卖切糕的小女孩

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. 继续折腾LNK 2005错误

    这次是因为要把一个很久的老项目改成使用Unicode字符集,又一次遇到了LNK 2005错误 先说说怎么把老项目改成Unicode字符集吧,首先要有足够的信心能把项目改好,比如我这次改的项目,也不算很 ...

  2. 移动页面请使用CSS3动画

    说到动画,我们一般会使用jQuery 中的animate(); 在PC浏览器中,是很方便的,由于PC的高性能,这种不断修改DOM的做法确实不会出现太大的问题,但是在手机端就不同了. 手机上使用jQue ...

  3. 第21章 DMA—直接存储区访问—零死角玩转STM32-F429系列

    第21章     DMA—直接存储区访问 全套200集视频教程和1000页PDF教程请到秉火论坛下载:www.firebbs.cn 野火视频教程优酷观看网址:http://i.youku.com/fi ...

  4. 头部导航悬浮,css

    .header{ position:fixed; z-index:100; left:; right:; } 如图.

  5. 统计文件中的URL

    1. 题目: 一个文本文件中每一行中有一个URL,最多一万行,统计每一个URL的次数,输出到另外一个文件中,每一行前面是URL,后面是个数. 2.代码: package test; import ja ...

  6. Python简单线程间通信

    本节主要举一个简单的线程间通信的例子,利用线程安全的数据结构queue.Queue保存线程间通信的内容, import queue from threading import Thread from ...

  7. Java分享笔记:泛型类的定义与使用

    当类中要操作的引用数据类型不确定时,可以定义泛型类完成扩展.下面是程序演示. package packB; class Student { //定义学生类 public String st = &qu ...

  8. Integer和int使用==比较的总结

    public static void main(String[] args) { int i1 = 128; Integer i2 = 128; Integer i3 = new Integer(12 ...

  9. C#爬虫实践

    忘了什么时候加的,iPad上的人人视频追剧了<我的天才女友>,没事的时候看了下,感觉还不错,进一步了解到原著那不勒斯四部曲,感觉视频进度有些慢,就想找找书看看,一时没找到[PS:购买实体书 ...

  10. 【vlan-端口配置】

    搭建好拓扑图如下: 分别配置两台终端的ip地址 创建vlan把e0/4/0接口加入到新的vlan中 连通性失败 . 同理在把e0/4/1加入到vlan视图中 连通性成功 : 搭建好拓扑图如下 进入e0 ...