A. Split it! Codeforces Round #706 (Div. 2)
作者:互联网
A. Split it!
time limit per test
1 second
memory limit per test
256 megabytes
input
standard input
output
standard output
Kawashiro Nitori is a girl who loves competitive programming.
One day she found a string and an integer. As an advanced problem setter, she quickly thought of a problem.
Given a string ss and a parameter kk, you need to check if there exist k+1k+1 non-empty strings a1,a2...,ak+1a1,a2...,ak+1, such that
s=a1+a2+…+ak+ak+1+R(ak)+R(ak−1)+…+R(a1).s=a1+a2+…+ak+ak+1+R(ak)+R(ak−1)+…+R(a1).
Here ++ represents concatenation. We define R(x)R(x) as a reversed string xx. For example R(abcd)=dcbaR(abcd)=dcba. Note that in the formula above the part R(ak+1)R(ak+1) is intentionally skipped.
Input
The input consists of multiple test cases. The first line contains a single integer tt (1≤t≤1001≤t≤100) — the number of test cases. The description of the test cases follows.
The first line of each test case description contains two integers nn, kk (1≤n≤1001≤n≤100, 0≤k≤⌊n2⌋0≤k≤⌊n2⌋) — the length of the string ss and the parameter kk.
The second line of each test case description contains a single string ss of length nn, consisting of lowercase English letters.
Output
For each test case, print "YES" (without quotes), if it is possible to find a1,a2,…,ak+1a1,a2,…,ak+1, and "NO" (without quotes) otherwise.
You can print letters in any case (upper or lower).
Example
input
Copy
7 5 1 qwqwq 2 1 ab 3 1 ioi 4 2 icpc 22 0 dokidokiliteratureclub 19 8 imteamshanghaialice 6 3 aaaaaa
output
Copy
YES NO YES NO YES NO NO
Note
In the first test case, one possible solution is a1=qwa1=qw and a2=qa2=q.
In the third test case, one possible solution is a1=ia1=i and a2=oa2=o.
In the fifth test case, one possible solution is a1=dokidokiliteraturecluba1=dokidokiliteratureclub.
AC代码:
#include <iostream>
#include <algorithm>
#include <map>
#include <string>
using namespace std;
const int MAX = 1e5+5;
int a[MAX];
int main(){
//freopen("a.txt", "r", stdin);
int t;
cin >> t;
while (t--){
bool f = true;
int n, k;
string s;
cin >> n >> k >> s;
if (!k) cout << "YES" << '\n';
else if (n / k > 1 && n != k *2){
for (int i = 0; i < k; i++) {
if (s[i] != s[s.size() - i - 1]){
f = false;
break;
}
}
if (f) cout << "YES\n";
else cout << "NO\n";
}else cout << "NO\n";
}
return 0;
}
标签:case,string,706,a1,a2,Split,test,Div,ak 来源: https://blog.csdn.net/weixin_53484451/article/details/114648889