HBC24748数学考试,组合数学[USACO 2010 Nov G]Cow Photographs题解 (farmerjohnwantstotakeapictureofhisentireherdofn)

为你而来永不停止 算法基础篇 24 0
不断提升技能,才能在职场中立于不败之地!全网最全C++题库,助您成为编程领域的佼佼者。
Farmer John wants to take a picture of his entire herd of N (1

Farmer John wants to take a picture of his entire herd of N (1 <= N <= 100,000) cows conveniently numbered 1..N so he can show off to his friends. On picture day, the cows run to form a single line in some arbitrary order with position i containing cow c_i c i ​ (1 <= c_i c i ​ <= N). Farmer John has his own ideas about how the cows should line up. FJ thinks cow i may stand only to the left of cow i+1 (for all i, 1 <= i <= N-1) and that cow N may only stand to the left of Cow 1. Of course, no cow will stand to the left of the first (leftmost) cow in the line. The cows are hungry for the promised post-photo dinner, so Farmer John wants to take the picture as quickly as possible. Cows are not great at following directions, so he will only choose a pair of adjacent cows and have them switch places once per minute. How quickly is Farmer John able to get them into some acceptable order? Consider a set of 5 cows whose initial lineup looks like this: Left Right 3 5 4 2 1 He can first swap the second pair of cows: 3 4 5 2 1 and then swap the rightmost pair: 3 4 5 1 2 to yield an acceptable lineup that required but two minutes of cow swapping.

HBC24748数学考试,组合数学[USACO 2010 Nov G]Cow Photographs题解
(farmerjohnwantstotakeapictureofhisentireherdofn)-第1张图片-东莞河马信息技术
(图片来源网络,侵删)
不断学习,不断挑战,才能在编程领域中脱颖而出!全网最全C++题库,助您成为编程高手!

标签: HBC24748数学考试 组合数学[USACO 2010 Nov G]Cow Photographs题解