您的位置:首页 > 移动开发

pku 1674 Sorting by Swapping

2009-04-24 10:29 537 查看
#include <iostream>
#include <climits>
#include <algorithm>
using namespace std;
int map[10005];
int main()
{
int N, n;
scanf("%d", &N);
while(N--)
{
scanf("%d", &n);
for(int i = 1; i <= n; ++i)
scanf("%d", &map[i]);

int cnt = 0;
for(int i = 1; i < n; ++i)
if(map[i] != i)
{
swap(map[i], *(find(map+i+1, map+n+1, i)));
cnt++;
}
printf("%d/n", cnt);
}
return 0;
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: