Codeforces Round #305 (Div. 2) A. Mike and Fax 暴力回文串
A. Mike and Fax
Time Limit: 20 Sec Memory Limit: 256 MB
题目连接
http://codeforces.com/contest/548/problem/A
Description
While Mike was walking in the subway, all the stuff in his back-bag dropped on the ground. There were several fax messages among them. He concatenated these strings in some order and now he has string s.
He is not sure if this is his own back-bag or someone else's. He remembered that there were exactly k messages in his own bag, each was a palindrome string and all those strings had the same length.
He asked you to help him and tell him if he has worn his own back-bag. Check if the given string s is a concatenation of kpalindromes of the same length.
Input
The first line of input contains string s containing lowercase English letters (1 ≤ |s| ≤ 1000).
The second line contains integer k (1 ≤ k ≤ 1000).
Output
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
Sample Input
saba
2
Sample Output
NO
HINT
题意
给你个字符串,告诉你这个字符串是由k个相同长度的回文串构成的,判断是否正确
题解:
数据范围很小,暴力判断就好了
#include<bits/stdc++.h>
using namespace std; int main() {
string str;
int k,n;
int id;
cin>>str>>k;
/**如果恰没有k个的时候是输出NO 没考虑这个条件一直wa*/
if(str.length()%k != ) {
cout<<"NO"<<endl;
return ;
}
n = str.length()/k;
bool ans = false;
/**分成K组进行判断 如果有一组不满足回文串条件 则确定输出NO*/
for(int i = ; i <= k; i++) {
int bi = (i-)*n;
int ei = i*n-;
while(bi <= ei) {
if(str[bi] != str[ei]) {
ans = true;
break;
}
ei--;
bi++;
}
if(ans) break;
}
if(ans) cout<<"NO"<<endl;
else cout<<"YES"<<endl;
return ;
}
Codeforces Round #305 (Div. 2) A. Mike and Fax 暴力回文串的更多相关文章
- 字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax
题目传送门 /* 字符串处理:回文串是串联的,一个一个判断 */ #include <cstdio> #include <cstring> #include <iostr ...
- Codeforces Round #305 (Div. 2) B. Mike and Fun 暴力
B. Mike and Fun Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/548/pro ...
- Codeforces Round #305 (Div. 1) A. Mike and Frog 暴力
A. Mike and Frog Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/pr ...
- set+线段树 Codeforces Round #305 (Div. 2) D. Mike and Feet
题目传送门 /* 题意:对于长度为x的子序列,每个序列存放为最小值,输出长度为x的子序列的最大值 set+线段树:线段树每个结点存放长度为rt的最大值,更新:先升序排序,逐个添加到set中 查找左右相 ...
- 数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog
题目传送门 /* 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 详细解释:ht ...
- 暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun
题目传送门 /* 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) */ #include <cstdio> #include <cstring> #includ ...
- Codeforces Round #305 (Div. 1) B. Mike and Feet 单调栈
B. Mike and Feet Time Limit: 20 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/547/pro ...
- Codeforces Round #305 (Div. 2) D. Mike and Feet 单调栈
D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
- Codeforces Round #305 (Div. 2) D. Mike and Feet
D. Mike and Feet time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
随机推荐
- tensorflow让程序学习到函数y = ax + b中a和b的值
今天我们通过tensorflow来实现一个简单的小例子: 假如我定义一个一元一次函数y = 0.1x + 0.3,然后我在程序中定义两个变量 Weight 和 biases 怎么让我的这两个变量自己学 ...
- linux系统下的SVN安装
1.直接安装 # sudo apt-get install subversion 2. 创建版本库 # sudo mkdir /home/svn # sudo svnadmin create /hom ...
- requests.post发送字典套字典
import requests import json a = { "data": { "project": { "url": " ...
- https://segmentfault.com/a/1190000004518374#articleHeader3
https://segmentfault.com/a/1190000004518374#articleHeader3 https://segmentfault.com/q/10100000049065 ...
- jquery mouseout mouseover 多次执行
用jquery,mouseout,mouseover,随着鼠标移动,事件被触发了多次(冒泡),换成js onmouseover,onmouseout也是一样.最终的解决办法是,用jquery,mous ...
- C#之冒泡排序
以前在学校的时候看过冒泡排序,看的时候挺明白的,但是自己写的时候就写不出来,在网上搜索了一下,发现网上的冒泡排序算法几乎都不符合冒泡排序的原理,虽然也能实现,但是不正宗. 冒泡排序从字面意思理解:应该 ...
- es6中参数【默认值,扩展运算符】
参数默认值 1.普通参数 function info(age,name="grace"){ console.log(name); } info(); //输入:grace 2.对象 ...
- DDD实战进阶第一波(五):开发一般业务的大健康行业直销系统(实现产品上下文领域层)
从这篇文章开始,我们根据前面的DDD理论与DDD框架的约束,正式进入直销系统案例的开发. 本篇文章主要讲产品上下文中的领域层的主要实现,先简单讲下业务方面的需求:产品SPU与产品SKU,产品SPU主要 ...
- ios开发-将false和true,当做字典的值,并将字典转成字符串,上传到服务器
今天遇到一个需求,将false和true,当做字典的值,并将字典转成字符串,上传到服务器. 可能这个需求大家遇到过,大部分原因是安卓的同事已经按这样的需求开发完了.我们只能跟随安卓的脚步了. (一)处 ...
- python字符串-内置方法用法分析
1.字母大小写相关(中文无效) 1.1 S.upper() -> string 返回一个字母全部大写的副本