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 ...
随机推荐
- Python中的dict
dict_lst = [ ('字典的键必须可哈希',), ('字典的键重复覆盖',), ('字典可迭代') ('增',), ('删',), ('改',), ('查',), ('练习',), ] 字典的 ...
- django开发傻瓜教程-1-安装和HelloWorld
安装 sudo pip install Django 新建项目 django-admin startproject XXX 启动项目 进入主目录下 python manage.py runserver ...
- P1309 瑞士轮
题目背景 在双人对决的竞技性比赛,如乒乓球.羽毛球.国际象棋中,最常见的赛制是淘汰赛和循环赛.前者的特点是比赛场数少,每场都紧张刺激,但偶然性较高.后者的特点是较为公平,偶然性较低,但比赛过程往往十分 ...
- 笔记-编程-IO模型
笔记-编程-IO模型 1. 简介 常用IO模型 1) 同步阻塞IO(Blocking IO) 2) 同步非阻塞IO(Non-blocking IO) 3) IO ...
- TCP/IP网络编程之基于UDP的服务端/客户端
理解UDP 在之前学习TCP的过程中,我们还了解了TCP/IP协议栈.在四层TCP/IP模型中,传输层分为TCP和UDP这两种.数据交换过程可以分为通过TCP套接字完成的TCP方式和通过UDP套接字完 ...
- loj2062 [HAOI2016]地图
ref #include <algorithm> #include <iostream> #include <cstdio> #include <cmath& ...
- 图文教程:为认证考试搭建Hyper-V家庭实验室
[TechTarget中国原创] 在过去20年里,我已经帮助成千上万人准备他们的IT认证考试.虽然有很多方法通过技术来获得经验,组建一个Hyper-V家庭实验室是个利用不同应用程序来获得经验的廉价并有 ...
- Oracle数据库迁移--->从Windows到Linux
I did a practice to migrate the oracle database from windows to linux operation system. The followin ...
- 使用 SpiritManager 类管理在 XNA 游戏中的精灵(十四)
平方已经开发了一些 Windows Phone 上的一些游戏,算不上什么技术大牛.在这里分享一下经验,仅为了和各位朋友交流经验.平方会逐步将自己编写的类上传到托管项目中,没有什么好名字,就叫 WPXN ...
- IntelliJ IDEA下maven Spring MVC配置
1. 导入工程:或者新建Spring web工程,可以参考博客中的Eclipse Spring MVC的方式: 2.配置Tomcat服务器,有两种方式:一是配置maven插件,而是配置本地Tomcat ...