zoukankan      html  css  js  c++  java
  • Codeforces 443 B Kolya and Tandem Repeat【暴力】

    题意:给出一个字符串,给出k,可以向该字符串尾部添加k个字符串,求最长的连续重复两次的子串

    没有想出来= =不知道最后添加的那k个字符应该怎么处理

    后来看了题解,可以先把这k个字符填成'*',再暴力枚举起点和长度,找出最大的长度

     1 #include<iostream>  
     2 #include<cstdio>  
     3 #include<cstring> 
     4 #include <cmath> 
     5 #include<stack>
     6 #include<vector>
     7 #include<map> 
     8 #include<set>
     9 #include<queue> 
    10 #include<algorithm>  
    11 using namespace std;
    12 
    13 typedef long long LL;
    14 const int INF = (1<<30)-1;
    15 const int mod=1000000007;
    16 const int maxn=100005;
    17 char s[maxn];
    18 int len;
    19 
    20 
    21 int main(){
    22     int k;
    23     cin>>s;
    24     int len=strlen(s);
    25     cin>>k;
    26     for(int i=len;i<len+k;i++) s[i]='*';
    27      
    28      int  ans=-1;
    29      len=len+k;
    30     for(int i=0;i<len;i++){
    31         for(int j=1;2*j+i<=len;j++){
    32             int flag=1;
    33             for(int t=i;t<i+j;t++){
    34                 if(s[t]!=s[t+j]&&s[t+j]!='*') {
    35                     flag=0;
    36                     break;
    37                 }
    38             }
    39             if(flag) ans=max(ans,j*2);
    40         }
    41     }
    42     
    43     printf("%d
    ",ans);
    44     return 0;    
    45 }
    View Code
  • 相关阅读:
    前端工程师入门的阶段
    学习能力与思考能力
    翻译 前端面试题目
    css规范
    html规范
    javascript中apply、call和bind的区别
    Javascript高级程序设计学习笔记一
    css学习笔记四
    [LC] 23. Merge k Sorted Lists
    [LC] 234. Palindrome Linked List
  • 原文地址:https://www.cnblogs.com/wuyuewoniu/p/4433930.html
Copyright © 2011-2022 走看看