题解 CF1496A【Split it!】

概述

题号 难度 \(AC\)时间及记录
\(\texttt{CF1496A}\) \(\texttt{洛谷难度:暂无评定}\) \(\texttt{On 2021/03/12}\)

解析

这是一道简单题。
题意不难理解。
数据范围 \(N \le 100\)
所以直接暴力做,
从两端往中间扫,
如果扫到的相等的字符数量大于或等于 \(k\)
就说明有解。
大概就是说判断前 \(k\) 位和后 \(k\) 位是否回文。
不用管什么 \(R(x)\)
我们只需要这样即可xyx

for(i=0,j=S.size()-1;i<K;i++,j--)if(S[i]!=S[j])Flag=false;
if(Flag)cout<<"YES"<<endl;
else cout<<"NO"<<endl;

代码

/*
Author:Xsmyy
Problem:CF1496A
Date:2021/03/10
*/
#include<bits/stdc++.h>
#define BetterIO ios::sync_with_stdio(false)
using namespace std;
int main(void)
{
	BetterIO;
	#ifndef ONLINE_JUDGE
	freopen("SampleIN.in","r",stdin);
	#else		
	#endif
	register int Case;
	cin>>Case;
	while(Case--)
	{
		register int N,K;
		cin>>N>>K;
		register string S;
		cin>>S;
		if(!K)cout<<"YES"<<endl;
		else
		{
			if(N<K*2+1)cout<<"NO"<<endl;
			else
			{
				register int i,j;
				register bool Flag;
				Flag=true;
				for(i=0,j=S.size()-1;i<K;i++,j--)if(S[i]!=S[j])Flag=false;
				if(Flag)cout<<"YES"<<endl;
				else cout<<"NO"<<endl;
			}
		}
	}
	return 0;
}
posted @ 2021-03-12 22:16  Bushuai_Tang  阅读(90)  评论(0编辑  收藏  举报