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 ...
随机推荐
- 火狐新版移除developer Toolbar和无法关闭自动更新的解决
随着火狐的不断更新已经更新到66版本了,近期注意到有个问题是火狐经常提示更新,更新了没多久,又时不时跳出更新的提示,不胜其烦. 在火狐的前期的版本中(大概4年之前吧)在Options菜单里是可以设置从 ...
- http响应Last-Modified和ETag
http响应Last-Modified和ETag [日期:2008-06-16] 来源: 作者: [字体:大 中 小] 基础知识 1) 什么是”Last-Modified”? 在浏览器第一次请求某一 ...
- Android特定语言 Xtendroid
Xtendroid是一款Android的领域特定语言,它大大降低样板代码,同时提供巨大的工具支持.Xtendroid利用Xtend transpiler实现,它的特点是能够在Java代码编辑或编译期间 ...
- python3.6 创建字典三法
这里献丑给出 python 3.6 创建字典变量的三法 其一:阳春白雪法:直接声明 mydic = {"name":"徐晓冬","age" ...
- python自动华 (十七)
Python自动化 [第十七篇]:jQuery介绍 jQuery jQuery是一个兼容多浏览器的javascript库,核心理念是write less,do more(写得更少,做得更多),对jav ...
- npm install、npm install --save与npm install --save-dev (转)
仅供学习参考,侵权删 以npm安装msbuild为例: npm install msbuild: 会把msbuild包安装到node_modules目录中 不会修改package.json 之后运行n ...
- Vivado RAM使用
RAM使用的几点说明: 1,RAM的读写位宽可以不同,举例:写的位宽为8(1Byte),读的位宽为1(1bit),那么读的地址就变成了写地址的8倍,即位宽增加3bit.
- /bin/sh: warning: setlocale: LC_ALL: cannot change locale (zh_CN.UTF-8) centos7
今天登陆centos 7 遇到一个 警告 /bin/sh: warning: setlocale: LC_ALL: cannot change locale (zh_CN.UTF-8) bash : ...
- SIGAI机器学习第七集 k近邻算法
讲授K近邻思想,kNN的预测算法,距离函数,距离度量学习,kNN算法的实际应用. KNN是有监督机器学习算法,K-means是一个聚类算法,都依赖于距离函数.没有训练过程,只有预测过程. 大纲: k近 ...
- [Luogu P1658] 购物
题目链接 这道题的主要思想是贪心. 题目的要求用几个硬币将1~x的数都能够凑出的最少硬币个数.这里注意一下是都凑出而不是同时凑出. 先讨论什么时候无解.所有的自然数都可以用1堆砌而成.换而言之只要有1 ...