【AIM Tech Round 4 (Div. 2) C】Sorting by Subsequences

【链接】http://codeforces.com/contest/844/problem/C


【题意】


水题,没有记录意义

【题解】


排序之后,记录每个数字原来在哪里就好.
可以形成环的。
环的个数就是子列个数。

【错的次数】


0

【反思】


在这了写反思

【代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define ms(x,y) memset(x,y,sizeof x)
#define ri(x) scanf("%d",&x)
#define rl(x) scanf("%lld",&x)
#define rs(x) scanf("%s",x)
#define oi(x) printf("%d",x)
#define ol(x) printf("%lld",x)
#define oc putchar(' ')
#define os(x) printf(x)
#define all(x) x.begin(),x.end()
#define Open() freopen("F:\rush.txt","r",stdin)
#define Close() ios::sync_with_stdio(0)


typedef pair<int,int> pii;
typedef pair<LL,LL> pll;


const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e5;


int n,tot = 0;
pii a[N+10];
vector <int> v[N+10];
bool bo[N+10];


int main(){
    //Open();
    //Close();
    ri(n);
    rep1(i,1,n){
        ri(a[i].fi);
        a[i].se = i;
    }
    sort(a+1,a+1+n);
    rep1(i,1,n)
        if (!bo[i]){
            int x = i,cnt = 0;
            tot++;
            while (!bo[x]){
                cnt++;
                bo[x] = true;
                v[tot].pb(x);
                x = a[x].se;
            }
        }
    oi(tot);puts("");
    rep1(i,1,tot){
        int len = v[i].size();
        oi(len);oc;
        rep1(j,0,len-1){
            oi(v[i][j]);
            oc;
        }
        puts("");
    }
    return 0;
}


原文地址:https://www.cnblogs.com/AWCXV/p/7626086.html