zoukankan      html  css  js  c++  java
  • 【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;
    }
    


  • 相关阅读:
    点击回到顶部
    rem根据屏幕大小适配字体大小
    使用layui-tree美化左侧菜单,点击生成tab选项
    字符串
    mysql ORDER BY field(STATUS, 0,1) 根据字段特定排序问题
    js防止短时间内重复点击
    tp5 where a and (b or c)
    array_diff遇到的坑
    前端开发必配置:html5shiv.js和respond.min.js的作用说明!
    phpmailer QQ邮件发送
  • 原文地址:https://www.cnblogs.com/AWCXV/p/7626086.html
Copyright © 2011-2022 走看看