HDU 5122 K.bro Sorting (2014 Beijing Regional Game K-problem simulation)

Source: Internet
Author: User

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)

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.