XOJ 1123A(XOJ 1451)Haybale Stacking(差分)

博客介绍了如何运用差分思想解决一道关于干草堆高度的数学问题。Bessie帮助FJ在指定干草堆上加草捆,最后求解完成指令后的中位数高度。算法分析提到,通过增加和减少操作更新数组,计算前缀和并排序找到中位数。
摘要由CSDN通过智能技术生成

一、题目描述
Feeling sorry for all the mischief she has caused around the farm recently, Bessie has agreed to help Farmer John stack up an incoming shipment of hay bales.

She starts with N (1 <= N <= 1,000,000, N odd) empty stacks, numbered 1…N. FJ then gives her a sequence of K instructions (1 <= K <= 25,000), each of the form “A B”, meaning that Bessie should add one new haybale to the top of each stack in the range A…B. For example, if Bessie is told “10 13”, then she should add a haybale to each of the stacks 10, 11, 12, and 13.

After Bessie finishes stacking haybales according to his instructions, FJ would like to know the median height of his N stacks – that is, the height of the middle stack if the stacks were to be arranged in sorted order (conveniently, N is odd, so this stack is unique). Please help Bessie determine the answer to FJ’s question.

贝茜为最近在农场附近造成的种种灾难感到难过,她同意帮助农场主约翰把一批干草捆起来。
一开始有N(1 <= N <= 1,000,000, N 是奇数)个空堆,编号为1…N。FJ给出了K (1 <= K <= 25,000)条指令,格式为“A B"的形式,意思是贝茜要添加一包新的干草到范围为A…B的干草堆顶。例如,如果贝茜的指令是”10 13“,那么她要给10,11,12和13这些干草堆添加一包干草。
在贝茜完成了所有干草堆的指令后,FJ要知道N堆干草的中间高度是多少——这就意味着需要对高度进行排序(为了方便,N是奇数,所以中间的高度是独一无二的)。请帮助贝茜确定FJ问题的答案。

PROBLEM NAME: stacking

Inp

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值