1. 程式人生 > >HDU 1890 splay區間翻轉

HDU 1890 splay區間翻轉

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 position, therefore, the robot arm reverses the first 4 samples. The second smallest sample is the last one, so the next robot operation will reverse the order of five samples on positions 2–6. The third step will be to reverse the samples 3–4, etc.

Your task is to find the correct sequence of reversal operations that will sort the samples using the above algorithm. If there are more samples with the same height, their mutual order must be preserved: the one that was given first in the initial order must be placed before the others in the final order too.

相關推薦

HDU 1890 splay區間翻轉

Somewhere deep in the Czech Technical University buildings, there are laboratories for examining mechanical and electrical properties of various materials.

3223 Tyvj 1729 文藝平衡樹——splay區間翻轉

剛開始學spaly,所以一上來不會打標記,後來想了想splay的區間操作和線段樹其實基本一樣。lazy標記的下推注意一下, update時如果直接進行splay操作的話會因lazy標記沒有下推而出錯,正確做法是在splay操作前先進行一個區間第k大查詢操作(因為區間反轉破壞了

HDU 1890 - Robotic Sort - [splay][區間反轉+刪除根節點]

分享 inf amp change 遍歷 ech was can words 題目鏈接:http://acm.hdu.edu.cn/showproblem.php?pid=1890 Time Limit: 6000/2000 MS (Java/Others)  Memory

Splay區間翻轉) 模板

iostream post tar clas spl sca .org while color 洛谷:P3391 【模板】文藝平衡樹(Splay) 1 #include<cstdio> 2 #include<iostream> 3 #

HihoCoder1677 : 翻轉字符串(Splay)(區間翻轉

輸出 fec shu void esp 翻轉 amp return for 描述 給定一個字符串S,小Hi希望對S進行K次翻轉操作。 每次翻轉小Hi會指定兩個整數Li和Ri,表示要將S[Li..Ri]進行翻轉。(S下標從0開始,即S[0]是第一個字母)

平衡樹【Splay區間翻轉【模板】

luoguP3391一道模板題 學習了splaysplaysplay區間翻轉的姿勢 具體就是先建兩個虛擬節點1,n+21,n+21,n+2,然後按節點下標+1+1+1將區間樹建出來,這時候排名為kkk的

BZOJ 3223 淺談SPLAY伸展樹演算法區間翻轉

世界真的很大 SPLAY是個很厲害的資料結構,相對於其他平衡樹,比如treap,對於每一次查詢雖然常數偏大,但是卻能力保總複雜度趨近於nlogn,而且除了treap能支援的操作以外,還支援如區間翻轉一類的特殊操作 其關鍵在於其獨屬的SPLAY操作 所以

區間翻轉 bzoj 3223 文藝平衡樹 (splay

【bzoj3223】Tyvj 1729 文藝平衡樹 Description 您需要寫一種資料結構(可參考題目標題),來維護一個有序數列,其中需要提供以下操作:翻轉一個區間,例如原有序序列是5 4 3 2 1,翻轉區間是[2,4]的話,結果是5 2 3 4 1

Splay區間翻轉問題

題目描述 給你 n 個數 分別為 1,2,3,4–n 然後有 m 個操作,每個操作對應一段區間,將區間的數進行翻轉。 比如 1,2,3,4,5 這段序列 操作區間為 2-4 翻轉完成後的序列為 1,4,3,2,5 輸入格式 第一行分別輸入 n

You Are the One HDU - 4283(區間dp)

eas value script names elf for stdio.h 表示 text You Are the One Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Jav

「模板」 FHQ_Treap 區間翻轉

rand for tchar 速度 r+ ++i void clu 回來 「模板」 FHQ_Treap 區間翻轉 <題目鏈接> 沒有旋轉的 Treap 實現區間操作的功能,很好理解,也很好寫,只是速度不算太快。 對於要翻轉的區間,把整棵 Treap(存有區間

Splay 區間反轉

pro 交換 putc push pan tdi esp 我們 tag 同樣的,我們以一道題來引入。 傳送門 這次的任務比較少,只要求進行區間反轉。區間反轉? 這個好像用啥都是O(n)的吧……(這次vector,set也救不了你了) 我們來使用splay解決這個問題。我們既

BZOJ4975: [Lydsy1708月賽]區間翻轉( 博弈&逆序對)

4975: [Lydsy1708月賽]區間翻轉 Time Limit: 1 Sec  Memory Limit: 256 MBSubmit: 265  Solved: 140[Submit][Status][Discus

bzoj 4975: [Lydsy1708月賽]區間翻轉【博弈論】

必敗狀態是倒序排列,也就是正序對為0 然後發現,每次翻轉都是有奇數個數對(\( C_{4x+2}^{2} C_{4x+3}^{2} \) 都是奇數),所以每次翻轉丟回改變正反數對的奇偶性 又因為偶數為必敗狀態,所以順序對為奇數則必勝 #include<iostream> #include<

Rabbit Kingdom(hdu 4777 求區間內與所有數都互質的數的個數 樹狀陣列)

題目連結: hdu 4777 Rabbit Kingdom 牛客: 小樂樂學數學 hdu英文題面,牛客中文題面,一個意思。   題意: 有一個長度為 n 的序列,m 個詢問。每個詢問求區間內與所有數都互質的數的個數。   思路: 對於序列

Hdu 4578 Transformation(區間加值,區間乘值,區間賦值,查詢區間的p次方)

Yuanfang is puzzled with the question below:  There are n integers, a1, a2, …, an. The initial values of them are 0. There are four kinds of operations. O

POJ 3468 A Simple Problem with Integers (Splay 區間更新、區間求和)

題目連結 題目大意 線段樹區間更新的模板題,用Splay寫一遍作為用Splay處理區間問題的模板題。 分析 程式碼 #include <iostream> #include <cstdio> #include <c

hdu 6012 維護區間字首和

These days Lotus is interested in cultivating potted plants, so she wants to build a greenhouse to meet her research desires. Lotus placed all of the n po

[BZOJ]3223 文藝平衡樹 區間翻轉

3223: Tyvj 1729 文藝平衡樹 Time Limit: 10 Sec  Memory Limit: 128 MBSubmit: 4861  Solved: 2851 [Submit][Status][Discuss] Description 您需要

HDU-5785 Manacher+區間處理

如何得到陣列L[i]與R[i]呢,首先用Manacher預處理出以每個位置為中心的迴文串的半徑,我們發現對於每個位置i,它前面半徑內的每個位置j對應的以i為中心的迴文串的結束位置在新串中為i*2-j,我們要將這個值加到L上。這裡可以採用樹狀陣列的思想,把這個值分為兩部分i*2與j,用陣列p[i]表示半徑,b