zoukankan      html  css  js  c++  java
  • [Codeforces #494] Tutorial

    记录下一开始写错的两道

    E:

    先建出直径,然后在保证直径不变的情况下按照最大度数贪心就好了

    注意一下一开始的特判

    #include <bits/stdc++.h>
    
    using namespace std;
    #define X first
    #define Y second
    typedef pair<int,int> P;
    int n,d,k,tot;vector<P> res;
    
    void print()
    {
        puts("YES");
        for(int i=0;i<res.size();i++) 
            printf("%d %d
    ",res[i].X,res[i].Y);
    }
    
    void dfs(int u,int v,int dist,int idx)
    {
        if(u) res.push_back(P(u,v));
        if(tot==n) print(),exit(0);
        if(!dist) return;
        for(int i=1;i<=idx;i++)
            dfs(v,++tot,dist-1,k-1);
    }
    
    int main()
    {
        scanf("%d%d%d",&n,&d,&k);
        if(n<=d||n>2&&k<2) return puts("NO");
        for(int i=1;i<=d;i++) res.push_back(P(i,i+1));
        tot=d+1;if(tot==n) return print(),0;
        for(int i=2;i<=d;i++) 
            if(tot<n&&k>2) dfs(0,i,min(i-1,d-i+1),k-2);
        puts("NO");
        return 0;
    }
    Problem E

    F:

    又双叒叕看错题目了,可以缩减多个相同的串……

    一开始写的$KMP$,后来发现直接字符串$Hash$就能水过了

    注意:此题用$ab$串卡自然溢出,一共只有300个因此单模数就能过

    数据开头$dont hash with overflow$好评!

    #include <bits/stdc++.h>
    
    using namespace std;
    typedef unsigned long long ull;
    typedef pair<int,int> P;
    
    const int MAXN=305;
    ull hs[MAXN],MOD=19260817;char s[100005];
    int n,res,tot,len,pre[MAXN];
    
    ull cal_hash()
    {
        ull ret=0;
        for(int i=0;i<strlen(s);i++)
            ret=(ret*27+(s[i]-'a'+1))%MOD;
        return ret;
    }
    
    int main()
    {
        scanf("%d",&n);
        for(int i=1;i<=n;i++)
        {
            scanf("%s",s);int len=strlen(s);
            tot+=len;pre[i]=pre[i-1]+len;hs[i]=cal_hash();
        }
        tot+=n-1;
        
        for(int i=1;i<=n;i++)
            for(int j=i;j<=n;j++)
            {
                int cnt=1;
                for(int k=j+1;k+j-i<=n;k++)
                {
                    bool f=true;
                    for(int l=0;l<=j-i;l++)
                        if(hs[i+l]!=hs[k+l]) f=false;
                    if(f) cnt++,k+=j-i;
                }
                if(cnt>1) res=max(res,(pre[j]-pre[i-1]-1)*cnt);
            }
        printf("%d",tot-res);
        return 0;
    }
    Problem F
  • 相关阅读:
    LED调光,PFM即pulse frequence modulation
    调光设备术语:调光曲线(转)
    盗梦陀螺攻略5- PID平衡算法(转)
    连接池中的maxIdle,MaxActive,maxWait参数
    MyBatis 延迟加载,一级缓存,二级缓存设置
    maven常用命令介绍
    科目二倒库的感悟(附一个教练独特的调镜方法)
    科目二怎么调整后视镜
    新手学车上车起步步骤
    ActiveMQ 了解
  • 原文地址:https://www.cnblogs.com/newera/p/9339944.html
Copyright © 2011-2022 走看看