Title Link: http://acm.hdu.edu.cn/showproblem.php?pid=5122
Problem-Solving report: Define a sorting algorithm, each round can be randomly find a number, the number and the subsequent smaller than this number of exchanges, has been judged, until there is no smaller than this number, so called a round, now given a sequence of length n, you ask, at least through how many rounds, you can make this sequence into order.
Because we can only compare with the number of the following, so I just need to count the number of the next number is smaller than this number. Sweep from back to front, updating the current smallest one at a time.
1#include <cstdio>2#include <cstring>3#include <iostream>4#include <algorithm>5#include <cmath>6 using namespacestd;7 typedef __int64 INT;8 Const intMAXN = 1e6+5;9 Ten intA[MAXN]; One A intMain () - { - intT,n,kase =1; thescanf"%d",&T); - while(t--) - { -scanf"%d",&n); + for(inti =0; I < n;++i) -scanf"%d",&a[i]); +INT ans =0; A intM =0x7fffffff; at for(inti = n1; I >=0;--i) - { - if(M < a[i]) ans++; -M =min (m,a[i]); - } -printf"Case #%d:%i64d\n", kase++, ans); in } - return 0; to}
View Code
HDU 5122 K.bro Sorting (2014 Beijing Regional Game K-problem simulation)