题意:给定一个长度为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(模拟)的更多相关文章

  1. CF1029A Many Equal Substrings

    题目描述 你有一个字符串t,它由n个字母组成. 定义一个字符串s的子串为s[l...r],表示从位置l到r构成的一个新的串. 你的目标是构造一个字符串s,使得它的可能长度最小,要求s中存在k个位置i, ...

  2. CodeForces A. Many Equal Substrings

    http://codeforces.com/contest/1029/problem/A You are given a string tt consisting of nn lowercase La ...

  3. CodeForces 550A Two Substrings(模拟)

    [题目链接]click here~~  [题目大意]:  You are given string s. Your task is to determine if the given string s ...

  4. 【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  ...

  5. A. Many Equal Substrings(水题)

    思路: 直接比较橘色框里的取第一次相等,即可. #include<iostream> #include<string> using namespace std; string ...

  6. PAT甲级1060 Are They Equal【模拟】

    题目:https://pintia.cn/problem-sets/994805342720868352/problems/994805413520719872 题意: 给定两个数,表示成0.xxxx ...

  7. Many Equal Substrings CodeForces - 1029A (kmp next数组应用)

    题目大意 题目看样例也能猜到就是输出最短的循环串. 吐槽 明明是div3第一题为啥子还会用到kmp的知识? 解法 这个题仔细看发现是求最长可去除的后缀,也就是说去除跟下一个相同的字符串还能连接起来.这 ...

  8. 【LeetCode】1208. 尽可能使字符串相等 Get Equal Substrings Within Budget (Python)

    作者: 负雪明烛 id: fuxuemingzhu 公众号:每日算法题 本文关键词:LeetCode,力扣,算法,算法题,字符串,并查集,刷题群 目录 题目描述 示例 解题思路 滑动窗口 代码 刷题心 ...

  9. 【LeetCode】双指针 two_pointers(共47题)

    [3]Longest Substring Without Repeating Characters [11]Container With Most Water [15]3Sum (2019年2月26日 ...

随机推荐

  1. Nginx正向代理代理http和https服务

    Nginx正向代理代理http和https服务 1. 背景需求 通过Nginx正向代理,去访问外网.可实现局域网不能访问外网的能力,以及防止在上网行为上,留下访问痕迹. 2. 安装配置 2.1安装 w ...

  2. iOS 骰子战争 Dice Wars

    占坑 这个游戏之前在网页端玩过,App Store 上没有搜到特别好的,想自己做个类似的iOS APP 游戏 目测实现难度适中,可玩性较高

  3. C#MySQL增删改查

    首先在项目中添加引用 using MySql.Data.MySqlClient; 连接字符串  private string connString="server=localhost;use ...

  4. C/C++ 数组与指针

    #include <iostream>using namespace std;int main(){ char *a[]={"ab","ccs",& ...

  5. Yii2应用的运行过程

    每一个框架都有一个入口脚本,Yii2也不例外.一般来说,对于Web应用的入口脚本是YiiBasePath/frontend/web目录下的index.php. 先观察这个文件: <?php de ...

  6. 双击内容变input框可编辑,失去焦点后修改的数据异步提交

    <html> <head> <meta charset="utf8"> <script src="https://cdn.boo ...

  7. P3369 【模板】普通平衡树 Treap

    P3369 [模板]普通平衡树(Treap/SBT) 题目描述 您需要写一种数据结构(可参考题目标题),来维护一些数,其中需要提供以下操作: 插入x数 删除x数(若有多个相同的数,因只删除一个) 查询 ...

  8. angularjs报错问题记录

    1.[$injector:unpr]:没有找到注入的东西    2.$compile:multidir:多指令编译错误.    3.[ng:areq]:重复定义了ng-controller.    4 ...

  9. [POJ 1002] 487-3279 C++解题报告

        487-3279 Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 228365   Accepted: 39826 D ...

  10. Selenium WebDriver- 使用Frame中的HTML源码内容操作Frame

    #encoding=utf-8 import unittest import time from selenium import webdriver from selenium.webdriver i ...