Arrange seat of a bench for people
Given a bench with n seats and few people sitting, tell the seat number each time when a new person goes to sit on the bench such that his distance from others is maximum?
G jia
A few clarifying questions that i would ask:
1. What if the bench is emtpy. Can i return any seat number?
2. What if bench is full. Should i return -1.
3. How big can n be?
4. How many queries are we making?
Algo:
1. Traverse the bench once (saved as array or vector) and populate a max heap based on distance between two occupied seats. For each node in heap have distance, start seat no and end seat no.
2. When a query is made return the seat no as (end seat no - start seat no)/2 for the root node in heap.
3. Replace the root node with one node formed by (end seat no - start seat no)/2 and end seat no and call heapIfY() on heap.
4. insert the seconds node formed by start node no and (end seat no - start seat no)/2 in the heap.
Repeat process from 2 to 4 for each query.
Complexity:
Forming heap: O(n)
For each query: O(log(n))
Arrange seat of a bench for people的更多相关文章
- 2018SDIBT_国庆个人第三场
A - A CodeForces - 1042A There are nn benches in the Berland Central park. It is known that aiai peo ...
- CodeForce--Benches
A. Benches There are nn benches in the Berland Central park. It is known that aiai people are curr ...
- Codeforces Round #510 (Div. 2) A&B By cellur925
第一次CF祭== 由于太菜了只做了前两题== 因为在第一题上耗费时间太多了,我还是太菜了==. A. Benches time limit per test 1 second memory limit ...
- Codeforces Round #460 (Div. 2)-C. Seat Arrangements
C. Seat Arrangements time limit per test1 second memory limit per test256 megabytes Problem Descript ...
- Codeforces 919 C. Seat Arrangements
C. Seat Arrangements time limit per test 1 second memory limit per test 256 megabytes input standa ...
- codeforces 919C Seat Arrangements 思维模拟
C. Seat Arrangements time limit per test 1 second memory limit per test 256 megabytes input standard ...
- MySQL可视化软件Work Bench导出导入数据库
首先打开你的work bench,输入你的密码进入主页面 A:导入数据库 在Schemas空白处右键选择Create~:建立一个数据库,然后就可以导入你的sql文件了 File-->Open S ...
- bench.sh 跑分测速
#!/bin/bash #==============================================================# # Description: bench te ...
- 通过Measure & Arrange实现UWP瀑布流布局
简介 在以XAML为主的控件布局体系中,有用于完成布局的核心步骤,分别是measure和arrange.继承体系中由UIElement类提供Measure和Arrange方法,并由其子类Framewo ...
随机推荐
- Paper Reading:Mask RCNN
Mask RCNN 论文:Mask R-CNN 发表时间:2018 发表作者:(Facebook AI Research)Kaiming He, Georgia Gkioxari, Piotr Dol ...
- jquery 选择器能否查找display:none的元素
jQuery可以用可见性“:hidden”查找“display:none”的元素. 1.新家html文档,在head标签中引入本地jQuery文件,也可以引入cdn文件: 2.在body标签中添加一些 ...
- 2BIT
bit是比特,是英文 binary digit的缩写.而Byte是字节又叫bait. bit是表示信息的最小单位,是二进制数的一位包含的信息或2个选项中特别指定1个的需要信息量.一般来说,n比特的信息 ...
- vulkan gpu limits in mali
https://community.arm.com/developer/tools-software/graphics/b/blog/posts/memory-limits-with-vulkan-o ...
- 从list引用调用arraylist和linkedlist对象的方法了解多态
一.前言 今天和朋友在写代码时突然发现List<object> list=new ArrayList<object>()中,前面是通过List引用来调用其子类ArrayLis ...
- 成熟度等级CMM
软件能力成熟度模型 (Capability maturity model,CMM) CMM是目前国际上使用流行的一种软件生产过程行业标准模型,可定义.评价软件开发过程的成熟度,并提供提高软件质量的指导 ...
- [Luogu] 聪聪可可
题面:https://www.luogu.org/problemnew/show/P2634#sub 题解:https://www.zybuluo.com/wsndy-xx/note/1141506
- AtCoder Beginner Contest 132
目录 Contest Info Solutions A. Fifty-Fifty B. Ordinary Number C. Divide the Problems D. Blue and Red B ...
- 自动化测试报告浅谈之ExtentReports
我们在进行自动化测试时,往往需要有相应的测试报告,比如junit,testng,reportng等等,有会有自带的测试报告,那为什么我要在这边提ExtentReports?首先,我们来看看其它几种测试 ...
- 虚拟机安装WIN7教程
1.去下载win7原装镜像,推荐去官方网站下载:https://msdn.itellyou.cn/ 也可以直接使用Win7系统和激活工具链接:https://pan.baidu.com/s/1SJSE ...