由于每个数字只出现一次,离散化一下,置换求个循环节就好了。

/** @Date    : 2017-08-25 01:39:39
* @FileName: C.cpp
* @Platform: Windows
* @Author : Lweleth (SoungEarlf@gmail.com)
* @Link : https://github.com/
* @Version : $Id$
*/
#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std; const int INF = 0x3f3f3f3f;
const int N = 2e5+20;
const double eps = 1e-8; int a[N];
int pos[N];
vector<int>q[N];
int vis[N];
int main()
{
int n;
while(cin >> n)
{
MMF(vis);
MMF(pos);
map<int,int>s;
for(int i = 1; i <= n; i++)
scanf("%d", a + i), pos[i] = a[i];
sort(a + 1, a + n + 1);
for(int i = 1; i <= n; i++)
s[a[i]] = i;
for(int i = 1; i <= n; i++)
a[i] = s[pos[i]]; int c = 0;
for(int i = 1; i <= n; i++)
{
if(!vis[a[i]] && a[i] != i)
{
int cnt = 2;
int np = a[i];
vis[i] = 1;
while(a[np] != i || !vis[i])
{
cnt++;
vis[np] = 1;
q[c].PB(np);
np = a[np];
}
vis[np] = 1;
q[c].PB(np);
q[c].PB(i);
c++;
}
else if(a[i] == i)
{
q[c++].PB(a[i]);
vis[i] = 1;
}
}
printf("%d\n", c);
for(int i = 0; i < c; i++)
{
printf("%d", q[i].size());
while(!q[i].empty())
{ printf(" %d", q[i].back());
q[i].pop_back();
}
printf("\n");
}
}
return 0;
}

CF844 C 置换 水的更多相关文章

  1. GLSL实现Simple Displace Mapping 水仿真流体绘制 【转】

    http://blog.csdn.net/a3070173/archive/2008/11/20/3342062.aspx Dislace Mapping其实就是在顶点着色器中 对顶点进行置换偏移,经 ...

  2. 2017年浙江理工大学程序设计竞赛校赛 题解&源码(A.水, D. 简单贪心 ,E.数论,I 暴力)

    Problem A: 回文 Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 1719  Solved: 528 Description 小王想知道一个字 ...

  3. Atcoder 水题选做

    为什么是水题选做呢?因为我只会水题啊 ( 为什么是$Atcoder$呢?因为暑假学长来讲课的时候讲了三件事:不要用洛谷,不要用dev-c++,不要用单步调试.$bzoj$太难了,$Topcoder$整 ...

  4. HDOJ 2317. Nasty Hacks 模拟水题

    Nasty Hacks Time Limit: 3000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Tota ...

  5. Openjudge 1.13-21:最大质因子序列(每日两水)

    总时间限制:  1000ms 内存限制:  65536kB 描述 任意输入两个正整数m, n (1 < m < n <= 5000),依次输出m到n之间每个数的最大质因子(包括m和n ...

  6. [LeetCode] LFU Cache 最近最不常用页面置换缓存器

    Design and implement a data structure for Least Frequently Used (LFU) cache. It should support the f ...

  7. [LeetCode] Longest Repeating Character Replacement 最长重复字符置换

    Given a string that consists of only uppercase English letters, you can replace any letter in the st ...

  8. [LeetCode] Container With Most Water 装最多水的容器

    Given n non-negative integers a1, a2, ..., an, where each represents a point at coordinate (i, ai). ...

  9. 如何装最多的水? — leetcode 11. Container With Most Water

    炎炎夏日,还是呆在空调房里切切题吧. Container With Most Water,题意其实有点噱头,简化下就是,给一个数组,恩,就叫 height 吧,从中任选两项 i 和 j(i <= ...

随机推荐

  1. 欢迎来怼第二周Scrum会议六(总第十三次)

    一.小组信息 队名:欢迎来怼小组成员队长:田继平成员:李圆圆,葛美义,王伟东,姜珊,邵朔,冉华 小组照片 二.开会信息 时间:2017/10/25  17:19~17:35(总计16min).地点:东 ...

  2. resx文件引用

    应用场景: 自己在编写双语界面的时候,用到两种语言表. 引用如下: LocRM = new ResourceManager("TMI_E.words_" + lang.ToLowe ...

  3. Right-BICEP测试四则运算2

    根据Right-BICEP单元测试的方法,我对我写的四则运算2的程序进行了测试: 1.测试能否控制使用乘除 有乘除 无乘除 2.测试是否能加括号 不加括号 加括号 3.能否控制结果没有负数 无负数 4 ...

  4. 福大软工1816 ·软工之404NoteFound团队选题报告

    目录 NABCD分析引用 N(Need,需求): A(Approach,做法): B(Benefit,好处): C(Competitors,竞争): D(Delivery,交付): 初期 中期 个人贡 ...

  5. Alpha-end

    前言 失心疯病源10 团队代码管理github 个人感悟 肝不动了,肝不动了.明天如果见不到我,不要太想我. 站立会议 队名:PMS 530雨勤(组长) 今天完成了那些任务 熬夜肝代码 代码签入git ...

  6. 青岛 2016ICPC 区域现场赛题目

    A. Relic Discovery B. Pocket Cube C. Pocky D. Lucky Coins E. Fibonacci F. Lambda Calculus G. Coding ...

  7. mybatis_mysql

    SELECT round(avg(c.AVG_DELAY_TIME)) as AVG_DELAY FROM `result_road_saturation_day` a LEFT JOIN info_ ...

  8. 因为NLS_LANG 造成 Oracle数据库丢失 中文字符集兼容问题的处理.

    接着上一封blog. 因为sqlplus的 乱码问题 我修改了 注册表里面 NLS_LANG 的 value值.主要改动为: NLS_LANG source: SIMPLIFIED CHINESE_C ...

  9. APDU命令与响应格式【转】

    本文转载自:http://map.im/apduintroduce 命令格式 APDU命令由命令头和命令体组成: CLA | INS | P1 | P2 | Lc | DATA | Le命令头: CL ...

  10. 单源最短路径spfa模板(pascal)洛谷P3371

    题目描述 如题,给出一个有向图,请输出从某一点出发到所有点的最短路径长度. 输入输出格式 输入格式: 第一行包含三个整数N.M.S,分别表示点的个数.有向边的个数.出发点的编号. 接下来M行每行包含三 ...