lightoj1166Old Sorting

思路:直接暴力查找,交换就好了。

// #pragma comment(linker, "/STACK:1024000000,1024000000")
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <sstream>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>
// #define DEBUG
#ifdef DEBUG
#define debug(...) printf( __VA_ARGS__ )
#else
#define debug(...)
#endif
#define MEM(x,y) memset(x, y,sizeof x)
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int,int> ii;
const int inf = 1 << 30;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
int a[110];
int main()
{	
	// freopen("in.txt","r",stdin);
	// freopen("out.txt","w",stdout);
	int t, n;
	int icase = 0;
	scanf("%d",&t);
	while(t--){
		scanf("%d",&n);
		for (int i = 1;i <= n;++i)
			scanf("%d",&a[i]);
		int ans = 0;
		for (int i = 1;i <= n;++i){
			if (a[i] != i){
				ans++;
				for (int j = 1;j <= n;++j){
					if (a[j] == i){
						swap(a[i],a[j]);
					}
				}
			}
		}
		printf("Case %d: %d\n",++icase,ans);
	}
	return 0;
}


你可能感兴趣的:(模拟,贪心,lightoj)