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 ...
随机推荐
- linq 和lambda查询
EF 查询的两种 写法. linq 方法 或者 lambda方法 其中 ,只有tolist()的时候,才会真正的 在数据库中执行. 如果没有 tolist 方法,那么province1是 iqueab ...
- linq 和 lmabda 表达式 的用法 和优劣 转自 农码一生
https://www.cnblogs.com/zhaopei/p/5746414.html
- Adobe CS2提供免费序列号
据Adobe官方博客报道,自2012年12月13日起,因为技术故障,该公司已停止使用Creative Suite(CS2)产品及Acrobat 7的激活服务器. 这些产品大多是7年前发布,很多已经无法 ...
- MySQL游标(cursor) 定义及使用
概念 游标(Cursor)它使用户可逐行访问由SQL Server返回的结果集. 使用游标(cursor)的一个主要的原因就是把集合操作转换成单个记录处理方式. 用SQL语言从数据库中检索数据后,结果 ...
- c++标准之IO库
1.面向对象的标准库 2.多种IO标准库工具 istream,提供输入操作 ostream,提供输出操作 cin:读入标准输入的istream对象.全局对象extern std::istream ci ...
- juicer
function financingBodyTable(){ var jsonData = { FinancingBodyJSON:${relaListArr}//list数组 } var addMo ...
- 手机连上同一个局域网的PC,修改项目的vhost配置
<VirtualHost 172.16.6.100:80> DocumentRoot "D:\phpStudy\WWW\mywork\many_school" Serv ...
- 交叉编译qt5.6
按照网上的攻略编译QT5.6 https://www.lijingquan.net/2016/07/08/build-kernel-busybox-qt5-6-tslib-imx28/ 出现问题,找不 ...
- 笔记-docker-2安装(centos6.5环境)
笔记-docker-2安装(centos6.5环境) 1. centos6.5安装docker 1.1. 升级内核 安装docker,官方文档要求linux kernel至少3.8以上 ...
- Samba和NFS文件共享
SAMBA文件共享服务 通过Yum软件仓库来安装Samba服务程序 [root@zhangjh ~]# yum install samba -y Samba 配置文件注释信息较多,为了便于配置,因此先 ...