CodeForces A. Many Equal Substrings
http://codeforces.com/contest/1029/problem/A
You are given a string tt consisting of nn lowercase Latin letters and an integer number kk.
Let's define a substring of some string ss with indices from ll to rr as s[l…r]s[l…r].
Your task is to construct such string ss of minimum possible length that there are exactly kk positions ii such that s[i…i+n−1]=ts[i…i+n−1]=t. In other words, your task is to construct such string ss of minimum possible length that there are exactly kk substrings of ss equal to tt.
It is guaranteed that the answer is always unique.
The first line of the input contains two integers nn and kk (1≤n,k≤501≤n,k≤50) — the length of the string tt and the number of substrings.
The second line of the input contains the string tt consisting of exactly nn lowercase Latin letters.
Print such string ss of minimum possible length that there are exactly kk substrings of ss equal to tt.
It is guaranteed that the answer is always unique.
3 4
aba
ababababa
3 2
cat
catcat
代码:
#include <bits/stdc++.h>
using namespace std; int N, M;
string s; int main() {
scanf("%d%d", &N, &M);
cin >> s;
int temp;
for(int i = 0; i < N; i ++) {
if(s.substr(0, i) == s.substr(N - i, i))
temp = i;
}
for(int i = 1; i < M; i ++)
cout << s.substr(0, N - temp);
cout << s <<endl;
return 0;
}
CodeForces A. Many Equal Substrings的更多相关文章
- Many Equal Substrings CodeForces - 1029A (kmp next数组应用)
题目大意 题目看样例也能猜到就是输出最短的循环串. 吐槽 明明是div3第一题为啥子还会用到kmp的知识? 解法 这个题仔细看发现是求最长可去除的后缀,也就是说去除跟下一个相同的字符串还能连接起来.这 ...
- Codeforces gym101612 E.Equal Numbers(贪心)
传送:http://codeforces.com/gym/101612 题意:给出一个大小为n的序列a[i],每次选其中一个数乘以一个正整数,问进行k步操作后最少剩下多少种数字,输出0≤k≤n,所有的 ...
- codeforces D. Count Good Substrings
http://codeforces.com/contest/451/problem/D 题意:给你一个字符串,然后找出奇数和偶数长度的子串的个数,这些字串符合,通过一些连续相同的字符合并后是回文串. ...
- 【CodeForces】914 F. Substrings in a String bitset
[题目]F. Substrings in a String [题意]给定小写字母字符串s,支持两种操作:1.修改某个位置的字符,2.给定字符串y,查询区间[l,r]内出现y多少次.|s|,Σ|y|&l ...
- Codeforces 622C Not Equal on a Segment 【线段树 Or DP】
题目链接: http://codeforces.com/problemset/problem/622/C 题意: 给定序列,若干查询,每个查询给定区间和t,输出区间内任意一个不等于t的元素的位置. 分 ...
- 【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 ...
- Codeforces 1188D Make Equal DP
题意:给你个序列,你可以给某个数加上2的幂次,问最少多少次可以让所有的数相等. 思路(官方题解):我们先给序列排序,假设bit(c)为c的二进制数中1的个数,假设所有的数最后都成为了x, 显然x &g ...
- Codeforces C. Almost Equal (数学规律)
题目链接:http://codeforces.com/contest/1206/problem/C 题解 : 观察可以发现当n为偶数时,1 - 2n是不满足题意的,可以举例n = 2,n = 4试一试 ...
- Codeforces 1188D - Make Equal(dp)
Codeforces 题目传送门 & 洛谷题目传送门 首先我们考虑枚举最后这 \(n\) 个数变成的值 \(v\),那么需要的操作次数即为 \(\sum\limits_{i=1}^n\text ...
随机推荐
- c/c++基础
如果有你认为重要的知识点,而我这却没有记录下来的,那么期待你分享给我(^U^)ノ~YO. 1.在结构体中,符号->的前面是指针变量,符号.的前面是普通变量. 程序中a->b等价于(*a ...
- DateTools,可能是最好用的iOS日期工具库
项目简介 DateTools 用于提高Objective-C中日期和时间相关操作的效率.灵感来源于 DateTime和Time Period Library. 项目主页: DateTools 最新示例 ...
- BZOJ1509: [NOI2003]逃学的小孩(树的直径)
Time Limit: 5 Sec Memory Limit: 64 MBSubmit: 1126 Solved: 567[Submit][Status][Discuss] Description ...
- 基于 win7下虚拟机的 GNSS-SDR安装过程
最近在安装 GNSS-SDR软件时,遇到了很多问题,这里回顾了我的安装过程,罗列了所遇到的问题和解决办法.希望后来者不要再踩这些坑了! 首先,在官方文档中看到,GNSS-SDR目前并不支持直接在 Wi ...
- lintcode_397_最长上升连续子序列
最长上升连续子序列 描述 笔记 数据 评测 给定一个整数数组(下标从 0 到 n-1, n 表示整个数组的规模),请找出该数组中的最长上升连续子序列.(最长上升连续子序列可以定义为从右到左或从左到 ...
- Servlet学习笔记06——什么是转发,路径,状态管理?
1.include指令 (1)作用: 告诉容器,在将jsp转换成Servlet时,将 某个文件的内容插入到该指令所在的位置. (2)语法: <%@ include file="&quo ...
- Servlet学习笔记04——什么是重定向,servlet生命周期?
1.重定向 (1)什么是重定向? 服务器通知浏览器访问一个新的地址. 注: 服务器可以通过发送一个302状态码及一个 Location消息头(该消息头的值是一个地址,一般 称之为重定向地址)给浏览器, ...
- 常见Linux的发行版有哪些?并描述不同发行版之间的联系与区别。
一.按系列罗列linux的发行版,并描述不同发行版之间的联系和区别 Linux发行版=Linux内核+商业软件 linux的发行版: RedHat.Fedora.suse.红旗.debian.Ubun ...
- linux redis5.0 集群搭建
一.下载 wget http://download.redis.io/releases/redis-5.0.0.tar.gz 二.解压.编译 #解押到 /usr/local/ 文件夹 tar -zxv ...
- 【版本控制——svn】
reposity_name //版本库 { Passwd //验证密码文件 Authz //权限控制 Server.conf //主配置 } Authz //权限控制 //由[groups]标签控 ...