【题目简述】:事实上就是依据题目描写叙述:A permutation of the integers 1 to n is an ordering of these integers. So the natural way to represent a permutation is to list the integers in this order. With n = 5, a permutation might look like 2, 3, 4, 5,
1.

However, there is another possibility of representing a permutation: You create a list of numbers where the i-th number is the position of the integer i in the permutation. Let us call this second possibility an inverse permutation. The inverse permutation
for the sequence above is 5, 1, 2, 3, 4.

An ambiguous permutation is a permutation which cannot be distinguished from its inverse permutation.The permutation 1, 4, 3, 2 for example is ambiguous,because its
inverse permutation is the same. To get rid of such annoying sample test cases, you have to write a program which detects if a given permutation is ambiguous or not.

【分析】:看我加红的部分。就是说假设叫做ambiguous permutation的话,就要通过这种变换方式后还是same.否则的话就是not
ambiguous。

这样的方式就是例如以下:

数字的新旧位置互换,即是数组的下标是所谓旧位置。而这个数列本身的数字又代表一种新的位置。我们依照数字所显示的。将该数字所相应的下标变成序列中的值,便形成了新的序列。

如: 2    3    4   5    1      //  原序列

[1]   [2]  [3]  [4] [5]    //  数组下标

经过变换后:

[5]  [1]  [2]  [3]  [4]    //  此时新的序列就是  5  1   2  3   4。由于与原序列 2  3  4  5  1不同,所以就是not  ambiguous

1    2    3    4     5

见代码:

注:c++的输入输出会超时!

// 524K  219Ms
#include<iostream>
using namespace std;
int a[100005];
int main()
{
int i,j,n;
while(scanf("%d",&n)&&n!=0)
{
int flag=1;
for(i=1;i<=n;i++)
scanf("%d",&a[i]);
for(i=1;i<=n;i++)
{
if(a[a[i]]!=i)
{
flag=0;
break;
}
}
if(flag==0)
printf("not ambiguous\n");
else
printf("ambiguous\n");
}
return 0;
}

POJ 2470 Ambiguous permutations(简单题 理解题意)的更多相关文章

  1. poj 1847 最短路简单题,dijkstra

    1.poj  1847  Tram   最短路 2.总结:用dijkstra做的,算出a到其它各个点要改向的次数.其它应该也可以. 题意: 有点难懂.n个结点,每个点可通向ki个相邻点,默认指向第一个 ...

  2. POJ 3619 Speed Reading(简单题)

    [题意简述]:有K头牛,N页书,每次第i头牛每分钟仅仅能读Si页书,连续读Ti分钟,之后歇息Ri分钟.如今问我们第i头牛花费多少时间能够读完这N页书. [分析]:简单的模拟 //220K 32Ms # ...

  3. POJ 2051 argus(简单题,堆排序or优先队列)

    又是一道数据结构题,使用堆来进行权值调整和排序,每次调整都是o(n)的复杂度,非常高效. 第一眼看题觉得可以用优先队列来做,应该也很简单. 事实上多数优先队列都是通过堆来实现的. 写的时候还是出了一些 ...

  4. POJ 3458 Colour Sequence(简单题)

    [题意简述]:事实上题意我也没有特别看懂.可是依据它少许的题目描写叙述加上给的例子.就大胆的做了例如以下的推測: 就是说,如今给出一串字符s.然后紧接着给出可见的字符串visible还有隐藏的字符串h ...

  5. POJ 2664 Prerequisites?(简单题)

    [题意简述]:k:已经选择的科目数:m:选择的科目类别:c:能够选择的科目数.r:要求最少选择的科目数量 在输入的k和m以下的一行是选择的科目号. 比如: 3 2 //3是他选择了3科.2表示选择了两 ...

  6. poj 2955 Brackets dp简单题

    //poj 2955 //sep9 #include <iostream> using namespace std; char s[128]; int dp[128][128]; int ...

  7. POJ 3589 Number-guessing Game(简单题)

    [题目简述]:两个四位数,假设后一个数中的某个数与前一个相应的数的位置和值都相等.则统计数目由几个这种数.记为count1吧. 假设后一个数中的某个数与前一个数的数值相等,但位置不同. 此时这种数的个 ...

  8. acm.njupt 1001-1026 简单题

    点击可展开上面目录 Acm.njupt 1001-1026简单题 第一页许多是简单题,每题拿出来说说,没有必要,也说不了什么. 直接贴上AC的代码.初学者一题题做,看看别人的AC代码,寻找自己的问题. ...

  9. Codeforces 828B Black Square(简单题)

    Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n × m. ...

随机推荐

  1. 对Java单继承的弥补——接口

    接口主要用来实现多重继承,它是常量和方法的集合,这些方法只有声明没有实现,即接口本身是抽象的,系统默认用abstract修饰. 1.接口的定义: public interface A{ int A=1 ...

  2. Makefile中用宏定义进行条件编译(gcc -D)/在Makefile中进行宏定义-D【转】

    本文转载自:http://blog.csdn.net/maopig/article/details/7230311 在源代码里面如果这样是定义的:#ifdef   MACRONAME//可选代码#en ...

  3. win10查看系统启动项,并且禁用

    打开任务管理器,有一个叫做start up的选项卡,里面的东西就是启动项. 右键选中需要disable的,然后禁用.

  4. SwiftUI 官方教程(三)

    3. 用 Stacks 组合 View 在上一节创建标题 view 后,我们来添加 text view,它用来显示地标的详细信息,比如公园的名称和所在的州. 在创建 SwiftUI view 时,我们 ...

  5. xBIM 基础02 快速入门

    系列目录    [已更新最新开发文章,点击查看详细]  一.新建项目 Visual Studio 新建项目.项目创建完成后 Nuget ,项目添加 Xbim.Essentials,那么如果项目需要几何 ...

  6. [转]Microsoft Solutions Framework (MSF) Overview

    本文转自:http://msdn.microsoft.com/zh-CN/library/jj161047(v=vs.120).aspx [This documentation is for prev ...

  7. Centos7下Docker的使用

    一.安装Docker 1.1.查看原有系统是否已经安装docker yum list installed | grep docker 1.2.如果有则不需要继续安装,想重新安装,先卸载 yum -y ...

  8. hiho一下 第173周

    题目1 : A Game 时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 Little Hi and Little Ho are playing a game. Ther ...

  9. jQuery中事件模块介绍

    事件模块 1.提供其他DOM方法 包括:next 和 nextAll方法 1.1 next方法实现 目标:扩展框架方法,获取当前元素的下一个元素 问题:如何获取下一个元素? 1.1.1 提供 next ...

  10. AngularJs轻松入门

    AngularJs轻松入门系列博文:http://blog.csdn.net/column/details/angular.html AngularJs轻松入门(一)创建第一个应用 AngularJs ...