In a queue, people are supposed to stand in ascending order of their heights. However,…
Jump to turn (9)
- 1In a queue, people are supposed to stand in ascending order of their heights. Ho
- 2Change to a faster method
- 3Change to a faster method by python
- 4"def countdisorderpairs(queue): , inversions = mergesort(queue) return inversion
- 5In a queue, people are supposed to stand in ascending order of their heights. Ho
- 6find a faeter way
- 7find a faeter way
- 8change a way
- 9修改之前程序中的漏洞
- User
In a queue, people are supposed to stand in ascending order of their heights. However, due to some confusion, the order of the queue gets disrupted. Your task is to determine the number of disorder pairs in the queue. A disorder pair is defined as a pair of people (pi , pj ) such that i < j and pi is taller than pj in the queue, which means their order is reversed. For example, consider a queue with 5 people: [180, 160, 175, 170, 170]. In this case, there are 6 disorder pairs: (180, 160), (180, 175), (180, 170), (180, 170), (175, 170) and (175, 170). Please note that (170, 170) is not considered as a disorder pair. Write the fastest program to calculate the number of disorder pairs in a given queue by Pyton.
- Assistant