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\n",ans);
44     return 0;
45 }

时间: 2024-10-18 12:29:59

Codeforces 443 B Kolya and Tandem Repeat【暴力】的相关文章

Codeforces 442B Kolya and Tandem Repeat(暴力)

题目连接:Codeforces 442B Kolya and Tandem Repeat 题目大意:给出一个字符串,可以再添加n个字符,问说可以找到SS的子串形式,S尽量长. 解题思路:枚举长度和起点判断即可,超过len的可以作为任意值,但是超过len+n就不行了. #include <cstdio> #include <cstring> const int N = 205; int n, len; char s[N]; bool judge (int l) { if (l <

Codeforces Round #253 (Div. 2) B - Kolya and Tandem Repeat

本题要考虑字符串本身就存在tandem, 如测试用例 aaaaaaaaabbb 3 输出结果应该是8而不是6,因为字符串本身的tanderm时最长的 故要考虑字符串本身的最大的tanderm和添加k个字符后最大的tanderm #include <iostream> #include <vector> #include <algorithm> #include <string> #include <set> using namespace std

CQUOJ 10672 Kolya and Tandem Repeat

A. Kolya and Tandem Repeat Time Limit: 2000ms Memory Limit: 262144KB 64-bit integer IO format: %I64d      Java class name: Any Submit Status PID: 10672 Kolya got string s for his birthday, the string consists of small English letters. He immediately

CF B. Kolya and Tandem Repeat

Kolya got string s for his birthday, the string consists of small English letters. He immediately added k more characters to the right of the string. Then Borya came and said that the new string contained a tandem repeat of length l as a substring. H

CodeForces 443B Kolya and Tandem Repeat

题目:Click here 题意:给定一个字符串(只包含小写字母,并且最长200)和一个n(表示可以在给定字符串后面任意加n(<=200)个字符).问最长的一条子串长度,子串满足前半等于后半. 分析:暴力~~~~~~ #include <bits/stdc++.h> using namespace std; typedef long long ll; const int INF = 0x3f3f3f3f; const int M = 3e5+3; int k; char str[M];

Codeforces 6D Lizards and Basements 2 dfs+暴力

题目链接:点击打开链接 #include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h> #include<queue> #include<string> #include<stdlib.h> #include<a

Codeforces 451C Predict Outcome of the Game(暴力)

题目连接:Codeforces 451C Predict Outcome of the Game 题目大意:题意有点坑,就是三支球队有n场比赛,错过了k场,即这k场比赛不知道输赢,只知道第一支球队和第二支球队胜局情况差d1,第二和第三差d2,问说最后有没有可能三支队伍胜局数相同. 解题思路:考虑四种情况下的场数u,是否为3的倍数,u/3后是否比当前情况下胜局数最高的队伍大,并且还要判断该情况是否可行. #include <cstdio> #include <cstring> #in

Codeforces 778A:String Game(二分暴力)

http://codeforces.com/problemset/problem/778/A 题意:给出字符串s和字符串p,还有n个位置,每一个位置代表删除s串中的第i个字符,问最多可以删除多少个字符使得s串依旧包含p串. 思路:想到二分,以为二分做法依旧很暴力.但是别人的做法确实就是二分暴力搞啊. 枚举删除字符数,然后判断的时候如果s串包含p串,那么可以往右区间找,否则左区间找. 1 #include <bits/stdc++.h> 2 using namespace std; 3 #def

Codeforces Gym 100286J Javanese Cryptoanalysis 傻逼暴力

原题地址:http://codeforces.com/gym/100286/attachments/download/2013/20082009-acmicpc-northeastern-european-regional-contest-neerc-08-en.pdf 此题题意是给你一个单对单密文,让你还原为原文,原文有个性质是,每个单词都是元音和辅音交替组成. 做法是直接5重for,暴力枚举AEIOU分别对应的字母,然后检查,然后输出 详见代码: //#include<iostream>