HDOJ 1890 Robotic Sort(一)

2014-11-24 12:04:05 · 作者: · 浏览: 2


Splay.... 每次把第i大的数旋转到根结点。删除这个点然后旋转左区间


Robotic Sort

Time Limit: 6000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 2050 Accepted Submission(s): 901


Problem Description Somewhere deep in the Czech Technical University buildings, there are laboratories for examining mechanical and electrical properties of various materials. In one of yesterday’s presentations, you have seen how was one of the laboratories changed into a new multimedia lab. But there are still others, serving to their original purposes.

In this task, you are to write software for a robot that handles samples in such a laboratory. Imagine there are material samples lined up on a running belt. The samples have different heights, which may cause troubles to the next processing unit. To eliminate such troubles, we need to sort the samples by their height into the ascending order.

Reordering is done by a mechanical robot arm, which is able to pick up any number of consecutive samples and turn them round, such that their mutual order is reversed. In other words, one robot operation can reverse the order of samples on positions between A and B.

A possible way to sort the samples is to find the position of the smallest one (P1) and reverse the order between positions 1 and P1, which causes the smallest sample to become first. Then we find the second one on position P and reverse the order between 2 and P2. Then the third sample is located etc.

\


The picture shows a simple example of 6 samples. The smallest one is on the 4th pZ http://www.2cto.com/kf/ware/vc/" target="_blank" class="keylink">vc2l0aW9uLCB0aGVyZWZvcmUsIHRoZSByb2JvdCBhcm0gcmV2ZXJzZXMgdGhlIGZpcnN0IDQgc2FtcGxlcy4gVGhlIHNlY29uZCBzbWFsbGVzdCBzYW1wbGUgaXMgdGhlIGxhc3Qgb25lLCBzbyB0aGUgbmV4dCByb2JvdCBvcGVyYXRpb24gd2lsbCByZXZlcnNlIHRoZSBvcmRlciBvZiBmaXZlIHNhbXBsZXMgb24KIHBvc2l0aW9ucyAyqEM2LiBUaGUgdGhpcmQgc3RlcCB3aWxsIGJlIHRvIHJldmVyc2UgdGhlIHNhbXBsZXMgM6hDNCwgZXRjLiA8YnI+Cjxicj4KWW91ciB0YXNrIGlzIHRvIGZpbmQgdGhlIGNvcnJlY3Qgc2VxdWVuY2Ugb2YgcmV2ZXJzYWwgb3BlcmF0aW9ucyB0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