Codeforces #359 B. Little Robber Girl's Zoo
传送门:http://codeforces.com/contest/686/problem/B
题目大意
一个序列,经过不超过20000次交换操作,是序列编程一个单调不减序列。
交换操作:规定 l , r (r-l+1为偶数)l 与 l+1 交换 ,l+2 与 l+3 交换以此类推到 r-1 与 r 交换。
题解
我们使 r = l+1 ,然后冒泡排序
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 |
#include<cstdio> using namespace std; const int Maxn=105; int num[Maxn]; int n; inline void swap(int &x,int &y){ int c=x; x=y;y=c; } int main(){ scanf("%d",&n); for (int i=1;i<=n;i++) scanf("%d",&num[i]); for (int i=1;i<=n;i++) for (int j=1;j<n-i+1;j++) if (num[j]>num[j+1]) { swap(num[j],num[j+1]); printf("%d %d\n",j,j+1); } return 0; } |

原文链接:Codeforces #359 B. Little Robber Girl's Zoo
WNJXYKの博客 版权所有,转载请注明出处。
还没有任何评论,你来说两句吧!