【题目简述】:事实上就是依据题目描写叙述: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. 错误: su: 无法设置组: 不允许的操作

    到 /bin目录下,用ls -l 看下su文件的权限是不是rwxr-xr-x或者-rwxrwxrwx 执行这条命令chmod ug+s su

  2. luogu1908 逆序对 树状数组

    题目大意:对于给定的一段正整数序列,逆序对就是序列中ai>aj且i<j的有序对.求一段序列的逆序对数. 对于一个数组T,其一个点的值为值与该点下标相等的A序列中点的个数.对T维护一个树状数 ...

  3. vue+element-ui实现前端分页

    按照他的文档来写分页 最主要的是  el-table里面展示的数据怎么处理 <el-table :data="AllCommodityList.slice((currentPage-1 ...

  4. css3 animate基本属性

    Css3animate属性 属性 描述 Css Animation 所有动画属性的简写属性,除了animation-play-state属性 Animation:name duration timin ...

  5. colab使用谷歌云中的文件

    colab使用谷歌云中文件 无法一劳永逸 Google Colab最大的不足就是使用虚拟机,这意味着我们自行安装的库虚拟机重启之后,就会被复原,比如keras,数据无法持久化.为了能够持久保存数据,我 ...

  6. 常用JQUERY插件大全

    jQuery内容滚动插件-BoxSlider jQuery artDialog对话框插件 移动端日期选择组件 图像延迟加载库Echo.js 轮播图FlexSlider插件 Slick.js幻灯片使用方 ...

  7. java 读取配置文件(nx就转了)

    借鉴别人的 package test; import java.io.FileInputStream; import java.io.FileNotFoundException; import jav ...

  8. 使用序列号激活优动漫PAINT(附激活码)

    优动漫PAINT是一款功能强大的动漫绘图软件,简单的中文界面和丰富的笔刷操纵,再次为设计工作者带来非一般的感受!最近,有不少小伙伴提出这样的疑问:购买安装优动漫PAINT之后,不知道如何激活,在哪里输 ...

  9. img标签过滤加fs模块实现图片文件缓存

    方法一:function iCache(selector) { selector.each(function(data) { //msg(data); ! function(data) { var u ...

  10. webstorm主题网址

    http://www.phpstorm-themes.com/ http://www.riaway.com/theme.php