• 【CF1029A】Many Equal Substrings(模拟)


    题意:给定一个长度为n的串s,要求构造一个长度最小的使s出现了k次的串,可以重叠

    n<=50,k<=50

    思路:计算一下前后缀相同长度

     1 #include<cstdio>
     2 #include<cstring>
     3 #include<string>
     4 #include<cmath>
     5 #include<iostream>
     6 #include<algorithm>
     7 #include<map>
     8 #include<set>
     9 #include<queue>
    10 #include<vector>
    11 using namespace std;
    12 typedef long long ll;
    13 typedef unsigned int uint;
    14 typedef unsigned long long ull;
    15 typedef pair<int,int> PII;
    16 typedef vector<int> VI;
    17 #define fi first
    18 #define se second 
    19 #define MP make_pair
    20 #define N   5100000
    21 #define MOD 1e9+7 
    22 #define eps 1e-8 
    23 #define pi acos(-1)
    24 
    25 char ch[100];
    26 
    27             
    28 
    29 int read()
    30 { 
    31    int v=0,f=1;
    32    char c=getchar();
    33    while(c<48||57<c) {if(c=='-') f=-1; c=getchar();}
    34    while(48<=c&&c<=57) v=(v<<3)+v+v+c-48,c=getchar();
    35    return v*f;
    36 }
    37 
    38 void swap(int &x,int &y)
    39 {
    40     int t=x;x=y;y=t;
    41 }
    42 
    43 
    44         
    45 int main()
    46 {
    47     //freopen("1.in","r",stdin);
    48     //freopen("1.out","w",stdout);
    49     int n,k1;
    50     scanf("%d%d",&n,&k1);
    51     scanf("%s",ch+1);
    52     int st=0;
    53     int flag;
    54     for(int i=n-1;i>=1;i--)
    55     {
    56          flag=1;
    57         int j=1;
    58         int k=n-i+1;
    59         while(k<=n&&j<=i)
    60         {
    61             if(ch[j]!=ch[k]){flag=0; break;}
    62             j++; k++; 
    63         }
    64         if(flag){st=j-1; break;}
    65     }
    66 
    67 //    printf("%d
    ",st); 
    68     for(int i=1;i<=st;i++) printf("%c",ch[i]);
    69     for(int i=1;i<=k1;i++) 
    70      for(int j=st+1;j<=n;j++) printf("%c",ch[j]); 
    71     
    72     return 0;
    73 }
  • 相关阅读:
    String和byte互转,Base64正逆向
    Http请求体详解
    ubuntuserver升级内核
    ElementUI Checkbox 多选框
    kubeadm1.20.0+cilium+hubble环境搭建
    ubuntu安装Kubernetes1.20.0
    使用mysql8.0
    用python 分析一段波浪的浪顶和浪底
    TOM 什么是目标运营模式
    Qt Quick 配置android开发环境
  • 原文地址:https://www.cnblogs.com/myx12345/p/9844334.html
Copyright © 2020-2023  润新知