Saturday, March 2, 2013

ambiguous permutation SPOJ


//http://www.spoj.com/problems/PERMUT2/
/*
the inverse permutation is one where the i-th number is the position of the integer i in the permutation.
 It is ambiguous if it is identical to the normal representation of the permutation.
  For example, if { 2, 3, 4, 5, 1 } is a permutation, then it's inverse is { 5, 1, 2, 3, 4 }
   and in this case is not ambiguous.
*/
#include<stdio.h>
int main()
{
int hash[100005];
int i,n;
scanf("%d",&n);
while(n!=0)
{
int arr[n+1];
for(i=1;i<=n;i++){
scanf("%d",&arr[i]);
hash[arr[i]]=i;
}
for(i=1;i<=n;i++)
{
if(arr[i]!=hash[i])
break;
}
if(i==n+1)
printf("ambiguous\n");
else
printf("not ambiguous\n");
scanf("%d",&n);
}
return 0;
}

No comments:

Post a Comment