【CF1029A】Many Equal Substrings(模拟)
题意:给定一个长度为n的串s,要求构造一个长度最小的使s出现了k次的串,可以重叠
n<=50,k<=50
思路:计算一下前后缀相同长度
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> PII;
typedef vector<int> VI;
#define fi first
#define se second
#define MP make_pair
#define N 5100000
#define MOD 1e9+7
#define eps 1e-8
#define pi acos(-1) char ch[]; int read()
{
int v=,f=;
char c=getchar();
while(c<||<c) {if(c=='-') f=-; c=getchar();}
while(<=c&&c<=) v=(v<<)+v+v+c-,c=getchar();
return v*f;
} void swap(int &x,int &y)
{
int t=x;x=y;y=t;
} int main()
{
//freopen("1.in","r",stdin);
//freopen("1.out","w",stdout);
int n,k1;
scanf("%d%d",&n,&k1);
scanf("%s",ch+);
int st=;
int flag;
for(int i=n-;i>=;i--)
{
flag=;
int j=;
int k=n-i+;
while(k<=n&&j<=i)
{
if(ch[j]!=ch[k]){flag=; break;}
j++; k++;
}
if(flag){st=j-; break;}
} // printf("%d\n",st);
for(int i=;i<=st;i++) printf("%c",ch[i]);
for(int i=;i<=k1;i++)
for(int j=st+;j<=n;j++) printf("%c",ch[j]); return ;
}
【CF1029A】Many Equal Substrings(模拟)的更多相关文章
- CF1029A Many Equal Substrings
题目描述 你有一个字符串t,它由n个字母组成. 定义一个字符串s的子串为s[l...r],表示从位置l到r构成的一个新的串. 你的目标是构造一个字符串s,使得它的可能长度最小,要求s中存在k个位置i, ...
- CodeForces A. Many Equal Substrings
http://codeforces.com/contest/1029/problem/A You are given a string tt consisting of nn lowercase La ...
- CodeForces 550A Two Substrings(模拟)
[题目链接]click here~~ [题目大意]: You are given string s. Your task is to determine if the given string s ...
- 【leetcode】1208. Get Equal Substrings Within Budget
题目如下: You are given two strings s and t of the same length. You want to change s to t. Changing the ...
- A. Many Equal Substrings(水题)
思路: 直接比较橘色框里的取第一次相等,即可. #include<iostream> #include<string> using namespace std; string ...
- PAT甲级1060 Are They Equal【模拟】
题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805413520719872 题意: 给定两个数,表示成0.xxxx ...
- Many Equal Substrings CodeForces - 1029A (kmp next数组应用)
题目大意 题目看样例也能猜到就是输出最短的循环串. 吐槽 明明是div3第一题为啥子还会用到kmp的知识? 解法 这个题仔细看发现是求最长可去除的后缀,也就是说去除跟下一个相同的字符串还能连接起来.这 ...
- 【LeetCode】1208. 尽可能使字符串相等 Get Equal Substrings Within Budget (Python)
作者: 负雪明烛 id: fuxuemingzhu 公众号:每日算法题 本文关键词:LeetCode,力扣,算法,算法题,字符串,并查集,刷题群 目录 题目描述 示例 解题思路 滑动窗口 代码 刷题心 ...
- 【LeetCode】双指针 two_pointers(共47题)
[3]Longest Substring Without Repeating Characters [11]Container With Most Water [15]3Sum (2019年2月26日 ...
随机推荐
- poj3525 Most Distant Point from the Sea
题目描述: vjudge POJ 题解: 二分答案+半平面交. 半径范围在0到5000之间二分,每次取$mid$然后平移所有直线,判断半平面交面积是否为零. 我的eps值取的是$10^{-12}$,3 ...
- mysql命令行复制数据库
为了方便快速复制一个数据库,可以用以下命令将db1数据库的数据以及表结构复制到newdb数据库创建新的数据库#mysql -u root -p123456 mysql>CREATE DATABA ...
- Java 编辑html模板并生成pdf
1.工具类 import com.hujiang.project.zhgd.Util; import com.itextpdf.text.BaseColor; import com.itextpdf. ...
- Tomcat上传文件报错:returned a response status of 403 Forbidden
出现这样的错误是没有权限对服务器进行写操作.需要在这个项目所在的tomcat中配置可写操作即可: 在tomcat的web.xml添加下面代码: <init-param><param- ...
- LeetCode(154) Find Minimum in Rotated Sorted Array II
题目 Follow up for "Find Minimum in Rotated Sorted Array": What if duplicates are allowed? W ...
- Virtual Friends HDU - 3172 (并查集+秩+map)
These days, you can do all sorts of things online. For example, you can use various websites to make ...
- 线段树:CDOJ1591-An easy problem A (RMQ算法和最简单的线段树模板)
An easy problem A Time Limit: 1000/1000MS (Java/Others) Memory Limit: 65535/65535KB (Java/Others) Pr ...
- CodeForces 392C Yet Another Number Sequence 矩阵快速幂
题意: \(F_n\)为斐波那契数列,\(F_1=1,F_2=2\). 给定一个\(k\),定义数列\(A_i=F_i \cdot i^k\). 求\(A_1+A_2+ \cdots + A_n\). ...
- UVa 11552 DP Fewest Flops
题解 #include <cstdio> #include <cstring> #include <algorithm> using namespace std; ...
- 关于freetype在安装中的遇到的问题
本人电脑配置的是Anconda环境+pycharm2017.2.2 comuniity,每次安装什么包就是直接pip install 的,但是这次在安装freetype的安装中却遇到了麻烦. 具体是在 ...