hdu 4985(模拟)
Little Pony and Permutation
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 639 Accepted Submission(s): 342

As
a unicorn, the ability of using magic is the distinguishing feature
among other kind of pony. Being familiar with composition and
decomposition is the fundamental course for a young unicorn. Twilight
Sparkle is interested in the decomposition of permutations. A
permutation of a set S = {1, 2, ..., n} is a bijection from S to itself.
In the great magician —— Cauchy's two-line notation, one lists the
elements of set S in the first row, and then for each element, writes
its image under the permutation below it in the second row. For
instance, a permutation of set {1, 2, 3, 4, 5} σ can be written as:
Here σ(1) = 2, σ(2) = 5, σ(3) = 4, σ(4) = 3, and σ(5) = 1.
Twilight
Sparkle is going to decompose the permutation into some disjoint
cycles. For instance, the above permutation can be rewritten as:
Help Twilight Sparkle find the lexicographic smallest solution. (Only considering numbers).
contains multiple test cases (less than 10). For each test case, the
first line contains one number n (1<=n<=10^5). The second line
contains n numbers which the i-th of them(start from 1) is σ(i).
2 5 4 3 1
3
1 2 3
(1)(2)(3)
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
using namespace std;
const int N = ;
bool vis[N];
int res[N],a[N];
int main()
{
int n;
while(scanf("%d",&n)!=EOF){
for(int i=;i<=n;i++){
scanf("%d",&a[i]);
}
memset(vis,false,sizeof(vis));
for(int i=;i<=n;i++){
int j=i;
if(vis[j]) continue;
int id = ;
while(!vis[j]){
res[id++] = j;
vis[j]=true;
j = a[j];
}
printf("(");
for(int i=;i<id-;i++){
printf("%d ",res[i]);
}
printf("%d)",res[id-]);
}
printf("\n");
}
return ;
}
hdu 4985(模拟)的更多相关文章
- hdu 4891 模拟水题
http://acm.hdu.edu.cn/showproblem.php?pid=4891 给出一个文本,问说有多少种理解方式. 1. $$中间的,(s1+1) * (s2+1) * ...*(sn ...
- hdu 5012 模拟+bfs
http://acm.hdu.edu.cn/showproblem.php?pid=5012 模拟出骰子四种反转方式,bfs,最多不会走超过6步 #include <cstdio> #in ...
- BestCoder7 1001 Little Pony and Permutation(hdu 4985) 解题报告
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4985 题目意思:有 n 个数,对于第 i 个数给出 σ(i) 的值.求出互不相交的循环的个数,并输出每 ...
- hdu 4669 模拟
思路: 主要就是模拟这些操作,用链表果断超时.改用堆栈模拟就过了 #include<map> #include<set> #include<stack> #incl ...
- 2013杭州网络赛C题HDU 4640(模拟)
The Donkey of Gui Zhou Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/O ...
- HDU/5499/模拟
题目链接 模拟题,直接看代码. £:分数的计算方法,要用double; #include <set> #include <map> #include <cmath> ...
- hdu 5003 模拟水题
http://acm.hdu.edu.cn/showproblem.php?pid=5003 记得排序后输出 #include <cstdio> #include <cstring& ...
- hdu 5033 模拟+单调优化
http://acm.hdu.edu.cn/showproblem.php?pid=5033 平面上有n个建筑,每个建筑由(xi,hi)表示,m组询问在某一个点能看到天空的视角范围大小. 维护一个凸包 ...
- HDU 2860 (模拟+并查集)
Regroup Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Sub ...
随机推荐
- JZOJ 5793. 【NOIP2008模拟】小S练跑步
5793. [NOIP2008模拟]小S练跑步 (File IO): input:run.in output:run.out Time Limits: 2000 ms Memory Limits: ...
- yii2 RUL的生成
通常情况下,会使用 yii\helpers\Url 使用Url类来生成想要的URL地址(链接) Url提供的方法大都是静态方法,不需要对类进行实例化 1.1 最常用的 Url::to() 1.2. b ...
- Python虚拟机类机制之instance对象(六)
instance对象中的__dict__ 在Python虚拟机类机制之从class对象到instance对象(五)这一章中最后的属性访问算法中,我们看到“a.__dict__”这样的形式. # 首先寻 ...
- C#环境下使用Windows消息传递字符串数据的研究
前言: 日前,师兄交给了我一个课题,将一个后台运行的Console程序,修改为WindowsForm程序,并在其界面上增加配置设置,以及运行记录。 原来的Console程序,后台运行的流程在其中一个类 ...
- IOS笔记048-数据存储
IOS数据存储的几种方式 XML属性列表(plist) 归档 Preference(偏好设置) NSKeyedArchiver归档(NSCodin ...
- c++ primer plus 第6版 部分三 9章 - 章
c++ primer plus 第6版 部分三 9章 - 章 第9章 内存模型和名称空间 1.单独编译 ...
- Java开发微信公众号(二)---开启开发者模式,接入微信公众平台开发
接入微信公众平台开发,开发者需要按照如下步骤完成: 1.填写服务器配置 2.验证服务器地址的有效性 3.依据接口文档实现业务逻辑 资料准备: 1.一个可以访问的外网,即80的访问端口,因为微信公众号接 ...
- nyoj 题目7 街区最短路径问题
街区最短路径问题 时间限制:3000 ms | 内存限制:65535 KB 难度:4 描述 一个街区有很多住户,街区的街道只能为东西.南北两种方向. 住户只可以沿着街道行走. 各个街道之间的间 ...
- C#从大图中截取一部分图片
#region 从大图中截取一部分图片 /// <summary> /// 从大图中截取一部分图片 /// </summary> /// <param name=&quo ...
- 【转】C# client 与java netty 服务端的简单通信,客户端采用Unity
http://blog.csdn.net/wilsonke/article/details/24721057 近日根据官方提供的通信例子自己写了一个关于Unity(C#)和后台通信的类,拿出来和大家分 ...