Codeforces Round #323 (Div. 2)B. Robot's Task
2015-10-05 19:58
288 查看
B. Robot's Task
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n.
Each computer containsexactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th
of them, the robot needs to collect at least ai any
pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which
the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input
The first line contains number n (1 ≤ n ≤ 1000).
The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n),
separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts
of information.
Sample test(s)
input
output
input
output
input
output
Note
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of
information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the
same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7.
题意:有个机器人要破解所有计算机,破解第i台计算机前,需要破解n台其他计算机,只有当资源点数大于或等于这台电脑的能量点数才可以破开,就可以得到一个资源。机器人起始位置在1,资源点数0,问破解所有计算机最少需要改变方向多少次。
简单题就是题意看了半天,哎!!英语!!直接模拟
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Robot Doc is located in the hall, with n computers stand in a line, numbered from left to right from 1 to n.
Each computer containsexactly one piece of information, each of which Doc wants to get eventually. The computers are equipped with a security system, so to crack the i-th
of them, the robot needs to collect at least ai any
pieces of information from the other computers. Doc can hack the computer only if he is right next to it.
The robot is assembled using modern technologies and can move along the line of computers in either of the two possible directions, but the change of direction requires a large amount of resources from Doc. Tell the minimum number of changes of direction, which
the robot will have to make to collect all n parts of information if initially it is next to computer with number 1.
It is guaranteed that there exists at least one sequence of the robot's actions, which leads to the collection of all information. Initially Doc doesn't have any pieces of information.
Input
The first line contains number n (1 ≤ n ≤ 1000).
The second line contains n non-negative integers a1, a2, ..., an (0 ≤ ai < n),
separated by a space. It is guaranteed that there exists a way for robot to collect all pieces of the information.
Output
Print a single number — the minimum number of changes in direction that the robot will have to make in order to collect all n parts
of information.
Sample test(s)
input
3 0 2 0
output
1
input
5
4 2 3 0 1
output
3
input
7 0 3 1 0 5 2 6
output
2
Note
In the first sample you can assemble all the pieces of information in the optimal manner by assembling first the piece of information in the first computer, then in the third one, then change direction and move to the second one, and then, having 2 pieces of
information, collect the last piece.
In the second sample to collect all the pieces of information in the optimal manner, Doc can go to the fourth computer and get the piece of information, then go to the fifth computer with one piece and get another one, then go to the second computer in the
same manner, then to the third one and finally, to the first one. Changes of direction will take place before moving from the fifth to the second computer, then from the second to the third computer, then from the third to the first computer.
In the third sample the optimal order of collecting parts from computers can look like that: 1->3->4->6->2->5->7.
题意:有个机器人要破解所有计算机,破解第i台计算机前,需要破解n台其他计算机,只有当资源点数大于或等于这台电脑的能量点数才可以破开,就可以得到一个资源。机器人起始位置在1,资源点数0,问破解所有计算机最少需要改变方向多少次。
简单题就是题意看了半天,哎!!英语!!直接模拟
相关文章推荐
- hdu5122 K.Bro Sorting
- orecle virtual box geneymotion无法开启问题
- 四则运算
- Android任务流调度 - Init
- iOS编程--------UIImagePickerController
- HDU 4810 Wall Painting(组合数学)
- cocos3——8.实现初学者指南
- [转]Fragment跳转至Activity或者Fragment
- IM6Q yocto开发平台搭建,学习FREESCALE官方手册笔记
- CComboBox控件的使用 1
- HTML5移动Web开发(四)——移动设计
- POJ 1511 Invitation Cards 最短路SPFA
- STL源码学习----lower_bound和upper_bound算法
- VS2010播放AVI视频时一闪而过的解决办法
- Oracle外键(Foreign Key)使用详细的说明(一)
- 指针间接赋值
- CYC-AVPlayer播放器的简单运用-02
- 51nod_learn_greedy_独木舟问题
- cmd无法使用粘贴的设置
- 读《暗时间》有感(逐步更新)