Cf489_a_ Insert Sort

Source: Internet
Author: User

Title Link: Http://codeforces.com/problemset/problem/489/A

AC Code:

1#include <cstdio>2#include <iostream>3#include <cstring>4#include <cstdlib>5#include <algorithm>6 using namespacestd;7 8 Const intMAXN = the+Ten;9 intA[MAXN], L[MAXN], R[MAXN];Ten intMain () { One     //freopen ("Test.txt", "R", stdin); A     intN; -      while(SCANF ("%d", &n)! =EOF) { -         intAns =0; the          for(intI=0; i<n; i++) -scanf"%d", &a[i]); -          for(intI=0; i<n; i++) { -             intK = Min_element (A+i, A+n)-A;//find the subscript for the smallest element inside [A+i, A+n] +             if(i!=k) { - swap (A[i], a[k]); +L[ans] = i; R[ans] = k; ans++; A             } at         } -printf"%d\n", ans); -          for(intI=0; i<ans; i++) { -printf"%d%d\n", L[i], r[i]); -         } -     } in     return 0; -}
View Code

The STL is a good thing to read someone else's writing ...

Cf489_a_ Insert Sort

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.