Kaidul

Sereja and Sorting 2

Mar 23rd, 2014
152
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.18 KB | None | 0 0
  1. /****************************************************
  2. ***   Problem       : Sereja and Sorting 2
  3. ***   Author        : Kaidul Islam
  4. ***   E-mail        : [email protected]
  5. ***   Blog          : http://kaidul.efireit.com
  6. ****************************************************/
  7. #include <bits/stdc++.h>
  8.  
  9. using namespace std;
  10.  
  11. #define rep(i,n) for(__typeof(n) i=0; i<(n); i++)
  12. #define repl(i,n) for(__typeof(n) i=1; i<=(n); i++)
  13. #define FOR(i,a,b) for(__typeof(b) i=(a); i<=(b); i++)
  14.  
  15. /** function **/
  16. #define SDi(x) sf("%d", &x)
  17. #define SDs(x) sf("%s", x)
  18. #define pf printf
  19. #define print(x) pf("%d ", x)
  20. #define println(x) pf("%d\n", x)
  21. #define sf scanf
  22. #define READ(f) freopen(f, "r", stdin)
  23.  
  24. /** Implementation **/
  25. #define Max 20000
  26. int a[Max];
  27. int start[Max];
  28. int end[Max];
  29.  
  30. int main() {
  31.     int Q = 0;
  32.     int n;
  33.     SDi(n);
  34.     repl(i, n) SDi(a[i]);
  35.  
  36.     repl(i, n) {
  37.         int k = i;
  38.         FOR(j, i + 1, n) if(a[k] > a[j]) k = j;
  39.  
  40.         if (k != i) {
  41.             reverse(a + i, a + k + 1);
  42.             Q++;
  43.             start[Q] = i;
  44.             end[Q] = k;
  45.         }
  46.     }
  47.     println(Q);
  48.     repl(i, Q) print(start[i]), println(end[i]);
  49.     return 0;
  50. }
Advertisement
Add Comment
Please, Sign In to add comment