zoj 2795 Ambiguous permutations

//这题的大意为:给出一个数组,需要你验证这个数组是否与自己的逆置换数组相等!
//逆置换:例如给出数组1,4,3,2,而原来的数组顺序为1, 2, 3, 4,就根据给出的数组作为原来数组排序的下标,
//得出的逆置换为1, 4, 3, 2,与给出的数组相等,所以就为模糊排序!
#include "iostream"
#include "memory.h"
using namespace std;

int num[100010];
int ans[100010];

int main()
{
	int n, i;
	while (cin >> n && n)
	{
		bool flag = false;
		memset(num, 0, sizeof(num));
		memset(ans, 0, sizeof(ans));
		for (i = 1; i <= n; i++)
			cin >> num[i];
		for (i = 1; i <= n; i++)
			ans[num[i]] = i;
		for (i = 1; i <= n; i++)
		{
			if (ans[i] != num[i])
			{
				flag = true;
				break;
			}
		}
		if (i == n + 1 && !flag)
			cout << "ambiguous" << endl;
		else
			cout << "not ambiguous" << endl;
	}
}

你可能感兴趣的:(zoj 2795 Ambiguous permutations)