zoukankan      html  css  js  c++  java
  • 2020牛客暑期多校训练营(第三场)

    A Clam and Fish
    B Classical String Problem
    C

    Operation Love

    D Points Construction Problem
    E Two Matchings

    我的我的锅,这道题没看,后期约等于挂机了

    题意:给你一个序列a,你要找到两种完全不同的整个序列的两两匹配,使得所有两两匹配差的绝对值的和最小,输出这个和

    思考:因为需要两个不同序列的的绝对值最小,只需要:

    第一个序列价格相邻最小的进行匹配即可

    第二个序列只需要在4和6之间找最小的匹配即可

    卡了一下cin

    #include <iostream>
    #include <cstring>
    #include <string>
    #include <cmath>
    #include <cstdio>
    #include <stdio.h>
    #include <cstdlib>
    #include <algorithm>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #define rep(i,a,b) for(int i = a; i <= b ; i ++ )
    #define pre(i,a,b) for(int i = b ; i >= a ; i --)
    #define ll long long
    #define inf 0x3f3f3f3f3f3f3fll
    #define ull unsigned long long
    #define ios ios::sync_with_stdio(false),cin.tie(0)
    using namespace std;
    typedef pair<int,int> PII ;
    const int N=2e6+10,mod=998244353,p=233;
    
    int t,n;
    int a[N],f[N];
    
    int main()
    {
        ios;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            rep(i,1,n) scanf("%lld",&a[i]);
            sort(a+1,a+1+n);
    
            rep(i,1,n) f[i]=inf;
            f[0]=0;
    
            for(int i = 4; i <= n; i += 2)
            {
                if(i >= 6)
                    f[i] = min(f[i], f[i - 6] + a[i] - a[i - 5]);
                f[i] = min(f[i], f[i - 4] + a[i] - a[i - 3]);
            }
            printf("%lld
    ", 2 * f[n]);
        }
        return 0;
    }
    

      

    F Fraction Construction Problem
    G Operating on a Graph

    题意:

     当时没有看这道题,当时估计是看了也不会,因为不熟悉并查集的操作,注意点:

    1、将相同颜色的使用并查集连接起来就好
    2、然后使用vector或者是list来记录相邻的点就好

    /***
     *               ii.                                         ;9ABH,
     *              SA391,                                    .r9GG35&G
     *                                             i3X31i;:,rB1
     *              iMs,:,i5895,                         .5G91:,:;:s1:8A
     *               33::::,,;5G5,                     ,58Si,,:::,sHX;iH1
     *                Sr.,:;rs13BBX35hh11511h5Shhh5S3GAXS:.,,::,,1AG3i,GG
     *                .G51S511sr;;iiiishS8G89Shsrrsh59S;.,,,,,..5A85Si,h8
     *               :SB9s:,............................,,,.,,,SASh53h,1G.
     *            .r18S;..,,,,,,,,,,,,,,,,,,,,,,,,,,,,,....,,.1H315199,rX,
     *          ;S89s,..,,,,,,,,,,,,,,,,,,,,,,,....,,.......,,,;r1ShS8,;Xi
     *        i55s:.........,,,,,,,,,,,,,,,,.,,,......,.....,,....r9&5.:X1
     *       59;.....,.     .,,,,,,,,,,,...        .............,..:1;.:&s
     *      s8,..;53S5S3s.   .,,,,,,,.,..      i15S5h1:.........,,,..,,:99
     *      93.:39s:rSGB@A;  ..,,,,.....    .SG3hhh9G&BGi..,,,,,,,,,,,,.,83
     *      G5.G8  9#@@@@@X. .,,,,,,.....  iA9,.S&B###@@Mr...,,,,,,,,..,.;Xh
     *      Gs.X8 S@@@@@@@B:..,,,,,,,,,,. rA1 ,A@@@@@@@@@H:........,,,,,,.iX:
     *     ;9. ,8A#@@@@@@#5,.,,,,,,,,,... 9A. 8@@@@@@@@@@M;    ....,,,,,,,,S8
     *     X3    iS8XAHH8s.,,,,,,,,,,...,..58hH@@@@@@@@@Hs       ...,,,,,,,:Gs
     *    r8,        ,,,...,,,,,,,,,,.....  ,h8XABMMHX3r.          .,,,,,,,.rX:
     *   :9, .    .:,..,:;;;::,.,,,,,..          .,,.               ..,,,,,,.59
     *  .Si      ,:.i8HBMMMMMB&5,....                    .            .,,,,,.sMr
     *  SS       :: h@@@@@@@@@@#; .                     ...  .         ..,,,,iM5
     *  91  .    ;:.,1&@@@@@@MXs.                            .          .,,:,:&S
     *  hS ....  .:;,,,i3MMS1;..,..... .  .     ...                     ..,:,.99
     *  ,8; ..... .,:,..,8Ms:;,,,...                                     .,::.83
     *   s&: ....  .sS553B@@HX3s;,.    .,;13h.                            .:::&1
     *    SXr  .  ...;s3G99XA&X88Shss11155hi.                             ,;:h&,
     *     iH8:  . ..   ,;iiii;,::,,,,,.                                 .;irHA
     *      ,8X5;   .     .......                                       ,;iihS8Gi
     *         1831,                                                 .,;irrrrrs&@
     *           ;5A8r.                                            .:;iiiiirrss1H
     *             :X@H3s.......                                .,:;iii;iiiiirsrh
     *              r#h:;,...,,.. .,,:;;;;;:::,...              .:;;;;;;iiiirrss1
     *             ,M8 ..,....,.....,,::::::,,...         .     .,;;;iiiiiirss11h
     *             8B;.,,,,,,,.,.....          .           ..   .:;;;;iirrsss111h
     *            i@5,:::,,,,,,,,.... .                   . .:::;;;;;irrrss111111
     *            9Bi,:,,,,......                        ..r91;;;;;iirrsss1ss1111
     狗头真帅*/
    #include <iostream>
    #include <cstring>
    #include <string>
    #include <cmath>
    #include <cstdio>
    #include <stdio.h>
    #include <cstdlib>
    #include <algorithm>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <list>
    #define pub(n) push_back(n)
    #define pob(n) pop_back(n)
    #define sf(n) scanf("%d",&n)
    #define pf(n) printf("%d
    ",n)
    #define slf(n) scanf("lld",&n)
    #define plf(n) printf("lld
    ",&n)
    #define rep(i,a,b) for(int i = a; i <= b ; i ++ )
    #define pre(i,a,b) for(int i = a ; i >= b ; i --)
    #define ll long long
    #define PII pair<int,int>
    #define inf 0x3f3f3f3f3f3f3fll
    #define ull unsigned long long
    #define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
    using namespace std;
    const int N=2e6+10,mod=1e9+7;
     
    int f[N],t,i,n,m,x,y,q,u;
    int find(int x)
    {
        if (x!=f[x]) f[x]=find(f[x]);
         return f[x];
    }
    list<int> G[N];
    int main()
    {
        sf(t);
        while (t--)
        {
            sf(n),sf(m);
            for (i=0;i<n;i++)
            {
                f[i]=i;
                G[i].clear();
            }
            while (m--)
            {
                sf(x),sf(y);
                G[x].push_back(y);
                G[y].push_back(x);
            }
            sf(q);
            while (q--)
            {
                sf(u);
                if (u!=find(u)) continue;
                list<int> s;
                for (auto v:G[u])
                {
                    x=find(v);
                    if (x==u) continue;
                    else f[x]=u;
                    s.splice(s.end(),G[x]);
                }
                swap(s,G[u]);
            }
            for (i=0;i<n;i++) cout<<find(i)<<" ";
            cout<<endl;
        }
        return 0;
     
    }
    

      

    H Sort the Strings Revision

    补这道题完全是因为我看到笛卡尔树的时候是懵的, 所以想学学,结果细节操作没有学会,只学会了使用板子(差点把我心态搞炸)

    通过二分来解:每次找到最小的Pi,将数列分成两部分,再继续递归,知道只有一个为止,然后比较大小就好
    然后对于快速求区间内pi的值,可以使用笛卡尔树

    /***
     *               ii.                                         ;9ABH,
     *              SA391,                                    .r9GG35&G
     *                                             i3X31i;:,rB1
     *              iMs,:,i5895,                         .5G91:,:;:s1:8A
     *               33::::,,;5G5,                     ,58Si,,:::,sHX;iH1
     *                Sr.,:;rs13BBX35hh11511h5Shhh5S3GAXS:.,,::,,1AG3i,GG
     *                .G51S511sr;;iiiishS8G89Shsrrsh59S;.,,,,,..5A85Si,h8
     *               :SB9s:,............................,,,.,,,SASh53h,1G.
     *            .r18S;..,,,,,,,,,,,,,,,,,,,,,,,,,,,,,....,,.1H315199,rX,
     *          ;S89s,..,,,,,,,,,,,,,,,,,,,,,,,....,,.......,,,;r1ShS8,;Xi
     *        i55s:.........,,,,,,,,,,,,,,,,.,,,......,.....,,....r9&5.:X1
     *       59;.....,.     .,,,,,,,,,,,...        .............,..:1;.:&s
     *      s8,..;53S5S3s.   .,,,,,,,.,..      i15S5h1:.........,,,..,,:99
     *      93.:39s:rSGB@A;  ..,,,,.....    .SG3hhh9G&BGi..,,,,,,,,,,,,.,83
     *      G5.G8  9#@@@@@X. .,,,,,,.....  iA9,.S&B###@@Mr...,,,,,,,,..,.;Xh
     *      Gs.X8 S@@@@@@@B:..,,,,,,,,,,. rA1 ,A@@@@@@@@@H:........,,,,,,.iX:
     *     ;9. ,8A#@@@@@@#5,.,,,,,,,,,... 9A. 8@@@@@@@@@@M;    ....,,,,,,,,S8
     *     X3    iS8XAHH8s.,,,,,,,,,,...,..58hH@@@@@@@@@Hs       ...,,,,,,,:Gs
     *    r8,        ,,,...,,,,,,,,,,.....  ,h8XABMMHX3r.          .,,,,,,,.rX:
     *   :9, .    .:,..,:;;;::,.,,,,,..          .,,.               ..,,,,,,.59
     *  .Si      ,:.i8HBMMMMMB&5,....                    .            .,,,,,.sMr
     *  SS       :: h@@@@@@@@@@#; .                     ...  .         ..,,,,iM5
     *  91  .    ;:.,1&@@@@@@MXs.                            .          .,,:,:&S
     *  hS ....  .:;,,,i3MMS1;..,..... .  .     ...                     ..,:,.99
     *  ,8; ..... .,:,..,8Ms:;,,,...                                     .,::.83
     *   s&: ....  .sS553B@@HX3s;,.    .,;13h.                            .:::&1
     *    SXr  .  ...;s3G99XA&X88Shss11155hi.                             ,;:h&,
     *     iH8:  . ..   ,;iiii;,::,,,,,.                                 .;irHA
     *      ,8X5;   .     .......                                       ,;iihS8Gi
     *         1831,                                                 .,;irrrrrs&@
     *           ;5A8r.                                            .:;iiiiirrss1H
     *             :X@H3s.......                                .,:;iii;iiiiirsrh
     *              r#h:;,...,,.. .,,:;;;;;:::,...              .:;;;;;;iiiirrss1
     *             ,M8 ..,....,.....,,::::::,,...         .     .,;;;iiiiiirss11h
     *             8B;.,,,,,,,.,.....          .           ..   .:;;;;iirrsss111h
     *            i@5,:::,,,,,,,,.... .                   . .:::;;;;;irrrss111111
     *            9Bi,:,,,,......                        ..r91;;;;;iirrsss1ss1111
     Õ桪¡ªÊÖ¶¯¹·Í·*/
    #include <iostream>
    #include <cstring>
    #include <string>
    #include <cmath>
    #include <cstdio>
    #include <stdio.h>
    #include <cstdlib>
    #include <algorithm>
    #include <vector>
    #include <set>
    #include <map>
    #include <queue>
    #include <iomanip>
    #include <list>
    #define pub(n) push_back(n)
    #define pob(n) pop_back(n)
    #define sf(n) scanf("%d",&n)
    #define pf(n) printf("%d
    ",n)
    #define slf(n) scanf("lld",&n)
    #define plf(n) printf("lld
    ",&n)
    #define rep(i,a,b) for(int i = a; i <= b ; i ++ )
    #define pre(i,a,b) for(int i = a ; i >= b ; i --)
    #define ll long long
    #define PII pair<int,int>
    #define inf 0x3f3f3f3f3f3f3fll
    #define ull unsigned long long
    #define ios ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
    // ull gethash(int i,int j) { return hs[j]-hs[i-1]*base[j-i+1]; }
    // int Find(int x) {return fa[x]==x? x : fa[x]=Find(fa[x]);}
    using namespace std;
    const int MAXN=2e6+10;
    const int MOD=1e9+7;
    int st[MAXN],ls[MAXN],rs[MAXN];
    ll p[MAXN],d[MAXN];
    int r[MAXN];
    ll sd,a,b,mod,ans,M;
    int n;
    void init(int n)
    {
        st[0]=0;
        for(int i=0; i<n; i++)
        {
            int k=st[0];
            while(k>0&&p[st[k]]>p[i])
                k--;
            if(k)
                rs[st[k]]=i;
            if(k<st[0])
                ls[i]=st[k+1];
            st[++k]=i;
            st[0]=k;
        }
    }//笛卡尔树
    void dfs(int k,int left,int right,int rnk)
    {
        if(p[k]==inf||left>=right)
        {
            for(int i=left; i<=right; i++)
                r[i]=rnk+(i-left);    //边界直接标记名次
            return;
        }
        dfs(ls[k],left,k,rnk+(p[k]%10>d[k])*(right-k));
        dfs(rs[k],k+1,right,rnk+(p[k]%10<d[k])*(k-left+1));//注意rnk的转移
    }
    int main()
    {
        int t;
        scanf("%d",&t);
        while(t--)
        {
            scanf("%d",&n);
            scanf("%lld%lld%lld%lld",&sd,&a,&b,&mod);
            for(int i=0; i<n; i++)
                p[i]=i;
            for(int i=1; i<n; i++)
                swap(p[sd%(i+1)],p[i]),sd=(sd*a%mod+b)%mod;
            scanf("%lld%lld%lld%lld",&sd,&a,&b,&mod);
            for(int i=0; i<n; i++)
                d[i]=sd%10,sd=(sd*a%mod+b)%mod;
            for(int i=0; i<n; i++)
                if(p[i]%10==d[i])
                    p[i]=inf;//如果无意义设为极大值
            init(n);//建树
            dfs(st[1],0,n,0);//dfs跑分治
            ans=0;
            M=1;
            for(int i=0; i<=n; i++)
                ans=(ans+((r[i])*M)%MOD)%MOD,M=(M*10000019)%MOD;//按题意哈希
            printf("%lld
    ",ans);
        }
    }
    

      

    I Sorting the Array
    J Operating on the Tree
    K Eleven Game
    L Problem L is the Only Lovely Problem

     

     

     

     

     

  • 相关阅读:
    ServiceHelperWindows服务辅助类
    .NET代码生成工具
    在同一个表内显示数据分级
    每天坚持要做的事情
    使用NCover协同NUnit一起工作
    Nant学习总结
    我的新家
    问题(待解决):ISNULL 的使用问题
    问题:String or binary data would be truncated
    问题:关于WCF
  • 原文地址:https://www.cnblogs.com/jxust-Biao/p/13343121.html
Copyright © 2011-2022 走看看