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 k palindromes of
the same length.
The first line of input contains string s containing lowercase English letters (1 ≤ |s| ≤ 1000).
The second line contains integer k (1 ≤ k ≤ 1000).
Print "YES"(without quotes) if he has worn his own back-bag or "NO"(without quotes) otherwise.
saba
2
NO
saddastavvat
2
YES
Palindrome is a string reading the same forward and backward.
In the second sample, the faxes in his back-bag can be "saddas" and "tavvat".
题意:
给出一个字符串,推断是不是由k个等长回文串组成的
思路:
水题,暴力
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <vector>
#include <math.h>
#include <bitset>
#include <algorithm>
#include <climits>
using namespace std; #define LS 2*i
#define RS 2*i+1
#define UP(i,x,y) for(i=x;i<=y;i++)
#define DOWN(i,x,y) for(i=x;i>=y;i--)
#define MEM(a,x) memset(a,x,sizeof(a))
#define W(a) while(a)
#define gcd(a,b) __gcd(a,b)
#define LL long long
#define N 500005
#define MOD 1000000007
#define INF 0x3f3f3f3f
#define EXP 1e-8
#define lowbit(x) (x&-x) char str[1005];
int len;
int main()
{
int i,j,k;
while(~scanf("%s%d",str,&k))
{
len = strlen(str);
if(len%k)
{
printf("NO\n");
continue;
}
int r = len/k,flag = 0;
for(i = 0; i<len; i+=r)
{
for(j=i; j<i+r; j++)
{
if(str[j]!=str[(i+r)-1-j+i])
{
flag = 1;
break;
}
}
if(flag)
break;
}
if(flag)
printf("NO\n");
else
printf("YES\n");
} return 0;
}
Codeforces548A:Mike and Fax的更多相关文章
-
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/pro ...
-
字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax
题目传送门 /* 字符串处理:回文串是串联的,一个一个判断 */ #include <cstdio> #include <cstring> #include <iostr ...
-
A - Mike and Fax
Time Limit:1000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description While ...
-
CodeForces 548A Mike and Fax (回文,水题)
题意:给定一个字符串,问是不是恰好存在 k 个字符串是回文串,并且一样长. 析:没什么好说的,每次截取n/k个,判断是不是回文就好. 代码如下: #include<bits/stdc++.h&g ...
-
CodeForces 548
A. Mike and Fax time limit per test 1 second memory limit per test 256 megabytes input standard inpu ...
-
C# 事件 解析
1.什么是事件,事件和委托什么关系? 事件?事件,就是,比如按一个按钮,弹出你好对话框,就是一个事件. 事件和委托? 事件就是委托的一种呀,委托可以理解为回调机制,回调函数. 2. 怎么理解C#事件, ...
-
cf#305 Mike and Foam(容斥)
C. Mike and Foam time limit per test 2 seconds memory limit per test 256 megabytes input standard in ...
-
CF #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 ...
-
CF #305 (Div. 2) C. Mike and Frog(扩展欧几里得&;&;当然暴力is also no problem)
C. Mike and Frog time limit per test 1 second memory limit per test 256 megabytes input standard inp ...
随机推荐
-
MySql中in和exists效率
mysql中的in语句是把外表和内表作hash 连接,而exists语句是对外表作loop循环,每次loop循环再对内表进行查询.一直大家都认为exists比in语句的效率要高,这种说法其实是不准确的 ...
-
react-native的tabbar和navigator混合使用
前段时间搭建项目使用了navigator和react-native-tab-navigator,现在我教大家搭建一个通用的简单框架. 先把几张图贴在这里,这就是我们今天要搭建的东西,别看页面简单,但是 ...
-
对象复制、克隆、深度clone
-------------------------------------------------------------------------------- ------------------- ...
-
用 React 编写SVG图表
1.代码 <!DOCTYPE html> <html lang="zh-cn"> <head> <meta charset="U ...
-
[转]Oracle开发专题之:%TYPE 和 %ROWTYPE
本文转自:http://www.cnblogs.com/kingjiong/archive/2009/02/19/1393837.html 1. 使用%TYPE 在许多情况下,PL/SQL变量可以用来 ...
-
hadoop搭建在Ubuntu16.04上
一.环境 Ubuntu16.04.Hadoop2.7.3.java8 系统安装完成后建议先更新一下 apt源 1.复制原文件备份 sudo cp /etc/apt/source.list /etc/a ...
-
Linux显示登入系统的帐号名称和总人数
Linux显示登入系统的帐号名称和总人数 youhaidong@youhaidong-ThinkPad-Edge-E545:~$ who -q youhaidong youhaidong # 用户数= ...
-
拥抱.NET Core系列:MemoryCache 缓存选项
在上一篇 "拥抱.NET Core系列:MemoryCache 缓存过期" 中我们详细的了解了缓存过期相关的内容,今天我们来介绍一下 MSCache 中的 Options,由此来介 ...
-
H5 27-优先级之important
27-优先级之important 我是段落 <!DOCTYPE html> <html lang="en"> <head> <meta c ...
-
maven 聚合的含义是父类打包 ,清理等 则子类自动打包;也就是一键打包 方便服务
maven 聚合的含义是父类打包 ,清理等 则子类自动打包:也就是一键打包 方便服务