[USACO][Analysis][2018 January Bronze 3] Out Of Place
TruaTheOrca Feb 14th, 2020 99 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
- PROBLEM: http://www.usaco.org/index.php?page=viewproblem2&cpid=785
- CODE: https://pastebin.com/qvDGP0Dw
- In a normal situation, the cows would be sorted. (For the example on the site, the original ordering of cows is as so:)
- SORTED: [2, 3, 4, 7, 7, 9]
- CURRENT:[2, 4, 7, 7, 9, 3]
- We would like to swap pairs of cows until the current array is equal to sorted array.
- To put 2 cows in their proper order, it would take 1 swap.
- To put 3 cows in their proper order, it would take 2 swaps.
- Therefore, the number of swaps required == numbers out of place -1. (In this case, 3.)
- 1. Read in current array.
- 2. Make copy of current array and sort.
- 3. Keep a count (answerCount in my code) and loop through size of array. If current[i] != sorted[i], answerCount++.
- 4. Print answerCount-1.
RAW Paste Data