Codeforces548A:Mike and Fax
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 ...
随机推荐
- socket阻塞IO流程图
单线程 多线程
- SSM框架搭建(Spring+SpringMVC+MyBatis)与easyui集成并实现增删改查实现
一.用myEclipse初始化Web项目 新建一个web project: 二.创建包 controller //控制类 service //服务接口 service.impl //服务 ...
- linux终端自定义命令的别名
alias : 给某个命令定义别名. 如:alias gpush='Git push origin HEAD:refs/for/master'这样在终端中,只需要输入 gpush 就ok了.但是只是这 ...
- Error parsing HTTP request header Note: further occurrences of HTTP header parsing errors...java.lang.IllegalArgumentException: Invalid character found in the request target. The valid characters are
先将异常信息贴出: 该问题是tomcat进行http request解析的时候报的错,网上的解决办法主要是修改Tomcat的server.xml,在<Connector port="8 ...
- ASP.NET Core 认证与授权[5]:初识授权
经过前面几章的姗姗学步,我们了解了在 ASP.NET Core 中是如何认证的,终于来到了授权阶段.在认证阶段我们通过用户令牌获取到用户的Claims,而授权便是对这些的Claims的验证,如:是否拥 ...
- swizzle method 和消息转发机制的实际使用
我的工程结构,如图 1-0 图 1-0 在看具体实现以前,先捋以下 实现思路. ViewController 中有一个-(void)Amethod;A方法. -(void)Amethod{ NSLo ...
- tomcat集群日志切割和远程备份脚本分享
笔者一共有3台tomcat服务器,一共4个tomcat服务,未来还会增加4个作为负载,笔者想通过在存储服务器对tomcat服务的日志进行远程切割和备份到存储上. 文中采用清空日志的方式,优点是不用重启 ...
- Win32API起始处的mov edi, edi与用户空间InlineHook
在x86平台上,无论是在调试器中跟到系统DLL中时,还是反汇编某个系统DLL时,经常会发现很多API的第一条汇编指令都是mov edi, edi.根据经验来讲,C函数的汇编形式,应该是首先push e ...
- 无法将类型为“System.DBNull”的对象强制转换为类型“System.String”
在ERP中做业务类单据,有时候会遇到这样的报错. 无法将类型为"System.DBNull"的对象强制转换为类型"System.String" 去数据库中检 ...
- Regasm
程序集注册工具(Regasm.exe) 读取程序集中的元数据,并将所需的项添加到注册表中.注册表允许COM 客户程序以透明方式创建.NET Framework类.类一经注册,任何COM 客户程序都 ...