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 ...
随机推荐
- exec , 元类,__new__, __call__ , 单例模式 , 异常
1,类也是对象 ''' 动态语言 可以在运行期间 动态生成类 修改对象属性 静态语言 ''''' ''' type(object_or_name, bases, dict) type(object) ...
- stark组件前戏(1)之项目启动前加载指定文件
django项目启动时,可以自定义执行某个py文件,这需要在任意app的apps.py中的Config类定义ready方法,并调用. from django.apps import AppConf ...
- linux硬件基础
1. 服务器分类 机架式服务器(主要用这个). 刀片式服务器. 塔式服务器. 2. 机架式服务器 服务器的尺: U - 2U. 服务器核心之电源: 双电源 AB 路. 服务器核心之 CPU-计算 CP ...
- has value '1.8', but '1.7' is required
使用java7,自己又想在空闲时间学一些java8的新特性,故在安装完1.7之后又安装了1.8 eclispe在启动时报’has value ‘1.8’,but’1.7’ is required’的错 ...
- 安装ANSYS19.0的正确方法(附下载)
安装ANSYS19.0的正确方法 卸载干净旧版本ANSYS 安装或重新安装之前必须先卸载干净,安装过旧版本ANSYS的也要确保卸载干净.电脑环境准备参考以下内容 ANSYS 卸载后重装需要注意的问题_ ...
- P1605迷宫
题目背景 迷宫 [问题描述] 给定一个N*M方格的迷宫,迷宫里有T处障碍,障碍处不可通过.给定起点坐标和 终点坐标,问: 每个方格最多经过1次,有多少种从起点坐标到终点坐标的方案.在迷宫 中移动有上下 ...
- javaScripct入门教程
1.JavaScript环境安装 JavaScript是一个轻量级的编程语言,安装自然很简单. a.打开你的电脑,找到一个Web浏览器,再找一个文本编辑器(比如记事本) b.没有了... 2.Java ...
- Java面向对象---类
类的定义 class 类名称{ 变量: 方法: } 声明一个类需要一个关键字:class 类的命名规则:组成类名称的所有单词首字母都必须大写.如UserDao
- TCP/IP网络编程之域名及网络地址
域名系统 DNS是对IP地址和域名进行互相转换的系统,其核心是DNS服务器.提供网络服务的服务端也是通过IP地址来区分的,但由于IP地址难于记忆,因此通过容易记忆并表述的域名来取代IP地址 在浏览器地 ...
- IT帮2019年2月线下活动【定义工作,解读自我】之站桩练习
2019年2月IT帮线下活动[定义工作,解读自我] 昨天的活动收获很大,全面的总结周老师会另写一篇来帮助大家回顾.我想说一下其中最打动我的一句话:“只有你能决定你有多优秀!” “工作中把自己当成企业家 ...