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. ...
随机推荐
- 自己实现android側滑菜单
当今的android应用设计中.一种主流的设计方式就是会拥有一个側滑菜单,以图为证: 实现这种側滑效果,在5.0曾经我们用的最多的就是SlidingMenu这个开源框架,而5.0之后.goog ...
- 【POJ 1222】 EXTENDED LIGHTS OUT
[题目链接] http://poj.org/problem?id=1222 [算法] 列出异或方程组,用高斯消元求解即可 [代码] #include <algorithm> #includ ...
- encodeURIComponent编码java后台解码出现乱码问题
问题:JavaScript请求后台带着name参数,有中文进行编码:url?name=" + encodeURIComponent(name):java后台直接使用name或者name=ja ...
- 最详细的CentOS 6与7对比(一):常见设置对比
本主题将从3个角度进行对比 常见设置(CentOS 6 vs CentOS 7) 服务管理(Sysvinit vs Upstart vs Systemd) 性能测试(cpu/mem/io/oltp) ...
- 爬虫中之Requests 模块的进阶
requests进阶内容 session处理cookie proxies参数设置请求代理ip 基于线程池的数据爬取 引入 有些时候,我们在使用爬虫程序去爬取一些用户相关信息的数据(爬取张三“人人网”个 ...
- MSDN性能分析相关网站收集
Visual Studio 性能分析初学者指南 | Microsoft Docshttps://docs.microsoft.com/zh-cn/visualstudio/profiling/begi ...
- 织梦dedecms红黑配图片模板源码v2.0
dedecms红黑配风格美女图片站是采用dedecms程序搭建的图片网站源码,网站感觉很大气,简约但是不简单,适合做图片网站.网站模板是收集其他网站的模板,感谢原网站提供者.在安装过程中出现问题,现已 ...
- 解决Android单个dex文件不能超过65535个方法问题
一.找坑:谷歌规定单个dex文件中的方法不能超过65536的限制 我们编写项目过程中在工程的lib文件夹下引用的第三方插件jar包太多或者项目过大,编译运行时就有可能报出com.android.dex ...
- Android开发笔记(7)——Intent启用应用软件
转载请注明:http://www.cnblogs.com/igoslly/p/6844154.html Intent启用应用软件 intent可以用来要求其他应用组件完成特定工作,如相机.电话.地图等 ...
- CUDA与OpenCL架构
CUDA与OpenCL架构 目录 CUDA与OpenCL架构 目录 1 GPU的体系结构 1.1 GPU简介 1.2 GPU与CPU的差异 2 CUDA架构 2.1 硬件架构 2.1.1 GPU困境 ...