【题目简述】:事实上就是依据题目描写叙述: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. explain 分析

    EXPLAIN的结果中,有哪些关键信息值得注意呢? MySQL的EXPLAIN当然和ORACLE的没法比,不过我们从它输出的结果中,也可以得到很多有用的信息. 总的来说,我们只需要关注结果中的几列: ...

  2. graphviz.js划线操作

    digraph A{ graph[color=red bgcolor="cadetblue" label="海阔天空",fontname="FangS ...

  3. oc18--self1

    // // Iphone.h // day13 #import <Foundation/Foundation.h> typedef enum { kFlahlightStatusOpen, ...

  4. c++迭代器失效问题

    参考两篇文章:https://blog.csdn.net/skyroben/article/details/70877008 https://lichanghao.github.io/2016/08/ ...

  5. Swift 3 关于Date的一些操作

    前言 最近在写关于日期的一些操作,所以整理了一下这方面的一些知识 本Demo使用的是playground. 我们以前使用的都是NSDate类进行日期的操作,在Swift 3.0中,我们就可以使用更加S ...

  6. [TB-Technology] 淘宝在数据处理领域的项目及开源产品介绍

    淘宝在数据存储和处理领域在国内互联网公司中一直保持比较靠前的位置,而且由于电子商务领域独特的应用场景,淘宝在数据实时性和大规模计算及挖掘方面一直在国内保持着领先,因此积累了很多的实践的经验和产品. T ...

  7. javascript设计模式-工厂模式(简单工厂)

    接口在工厂模式中起着很重要的作用,如果不对对象进行某种类型检查的以确保其实现了必要的方法,工厂模式的好处也就所剩无几了,举个简单的例子. Interface.js // Constructor. va ...

  8. BZOJ 1041 数学

    思路: $x^2+y^2=r^2$$y=\sqrt{(r+x)(r-x)}$令$ d=gcd(r+x,r-x)$设A=$(r-x)/d$ $B=(r+x)/d$则$gcd(A,B)=1$$y^2=d^ ...

  9. C#控制台显示进度条

    using System; using System.Collections.Generic; using System.Linq; using System.Text; namespace Prog ...

  10. Intel VTune Amplifier XE 使用

    VTune <VTune 开发者手册> 1. 安装 1.1 软件安装 下载: (安装包下载地址) 安装: # 1.解压 tar -zxvf filename.tar.gz # 2.安装 c ...