POJ 2470 Ambiguous permutations(简单题 理解题意)
【题目简述】:事实上就是依据题目描写叙述: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(简单题 理解题意)的更多相关文章
- poj 1847 最短路简单题,dijkstra
1.poj 1847 Tram 最短路 2.总结:用dijkstra做的,算出a到其它各个点要改向的次数.其它应该也可以. 题意: 有点难懂.n个结点,每个点可通向ki个相邻点,默认指向第一个 ...
- POJ 3619 Speed Reading(简单题)
[题意简述]:有K头牛,N页书,每次第i头牛每分钟仅仅能读Si页书,连续读Ti分钟,之后歇息Ri分钟.如今问我们第i头牛花费多少时间能够读完这N页书. [分析]:简单的模拟 //220K 32Ms # ...
- POJ 2051 argus(简单题,堆排序or优先队列)
又是一道数据结构题,使用堆来进行权值调整和排序,每次调整都是o(n)的复杂度,非常高效. 第一眼看题觉得可以用优先队列来做,应该也很简单. 事实上多数优先队列都是通过堆来实现的. 写的时候还是出了一些 ...
- POJ 3458 Colour Sequence(简单题)
[题意简述]:事实上题意我也没有特别看懂.可是依据它少许的题目描写叙述加上给的例子.就大胆的做了例如以下的推測: 就是说,如今给出一串字符s.然后紧接着给出可见的字符串visible还有隐藏的字符串h ...
- POJ 2664 Prerequisites?(简单题)
[题意简述]:k:已经选择的科目数:m:选择的科目类别:c:能够选择的科目数.r:要求最少选择的科目数量 在输入的k和m以下的一行是选择的科目号. 比如: 3 2 //3是他选择了3科.2表示选择了两 ...
- poj 2955 Brackets dp简单题
//poj 2955 //sep9 #include <iostream> using namespace std; char s[128]; int dp[128][128]; int ...
- POJ 3589 Number-guessing Game(简单题)
[题目简述]:两个四位数,假设后一个数中的某个数与前一个相应的数的位置和值都相等.则统计数目由几个这种数.记为count1吧. 假设后一个数中的某个数与前一个数的数值相等,但位置不同. 此时这种数的个 ...
- acm.njupt 1001-1026 简单题
点击可展开上面目录 Acm.njupt 1001-1026简单题 第一页许多是简单题,每题拿出来说说,没有必要,也说不了什么. 直接贴上AC的代码.初学者一题题做,看看别人的AC代码,寻找自己的问题. ...
- Codeforces 828B Black Square(简单题)
Codeforces 828B Black Square(简单题) Description Polycarp has a checkered sheet of paper of size n × m. ...
随机推荐
- ACdream 1154 Lowbit Sum (数位DP)
Lowbit Sum Time Limit: 2000/1000MS (Java/Others) Memory Limit: 128000/64000KB (Java/Others) SubmitSt ...
- java中与运算,或运算,异或运算,取反运算
//与运算 & 规则 :都为1时才为1 System.out.println( 7 & 9); /* * 7二进制 0111 ...
- day63-webservice 04.JaxWsServerFactoryBean和SOAP1.2
<wsdl:definitions xmlns:ns1="http://schemas.xmlsoap.org/soap/http" xmlns:soap12="h ...
- 关于ssh加密方式的理解
最近公司服务器被挖矿,所以更换了ssh的连接方式,从之前的密码登陆更换为密钥登陆方式,且禁止了密码登陆.所以在配置这个密钥的过程中,顺带了解了些ssh的原理和相关知识.通用的开源 1.ssh是什么,为 ...
- Mysql外键的变种 三种关系
一.介绍 因为有foreign key的约束,使得两张表形成了三种了关系: 多对一 多对多 一对一 二.重点理解如果找出两张表之间的关系 分析步骤: #1.先站在左表的角度去找 是否左表的多条记录可以 ...
- 取消页面按钮的enter按下事件
<script src="../../@Javascript/jquery-1.8.1.js"></script> <script lan ...
- Npgsql使用入门(三)【批量导入数据】
Program.cs代码: class Program { static void Main(string[] args) { var test = new PgBulkCopyHelper<S ...
- NFS 开机自动挂载共享目录
开机自动挂载: 如果服务端或客户端的服务器重启之后需要手动挂载,我们可以加入到开机自动挂载 在服务端/客户端的/etc/fstab里添加 192.168.22.204:/opt/filestore ...
- 《剑指offer 第二版》题解
剑指Offer 按题号排序 面试题 3:数组中重复的数字 面试题 4:二维数组中的查找 面试题 5:替换空格 面试题 6:从头到尾打印链表 面试题 7:重建二叉树 面试题 8:二叉树的下一个节点 面试 ...
- WPF 标题栏 右键窗口标题添加关于对话框
/// <summary> /// wpf标题栏 右键菜单 中添加新项 /// </summary> public partial class MainWindow : Win ...