Codeforces Round #305 (Div. 2) A. Mike and Fax 暴力回文串
2015-05-27 07:28
555 查看
[b] A. Mike and Fax[/b]
Time Limit: 20 Sec Memory Limit: 256 MB题目连接
http://codeforces.com/contest/548/problem/ADescription
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.
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.[b]Sample Input[/b]
saba 2
Sample Output
NO
HINT
[b]题意 [/b]给你个字符串,告诉你这个字符串是由k个相同长度的回文串构成的,判断是否正确
[b]题解:[/b]
数据范围很小,暴力判断就好了
[b]代码:[/b]
//qscqesze #include <cstdio> #include <cmath> #include <cstring> #include <ctime> #include <iostream> #include <algorithm> #include <set> #include <vector> #include <sstream> #include <queue> #include <typeinfo> #include <fstream> #include <map> #include <stack> typedef long long ll; using namespace std; //freopen("D.in","r",stdin); //freopen("D.out","w",stdout); #define sspeed ios_base::sync_with_stdio(0);cin.tie(0) #define test freopen("test.txt","r",stdin) #define maxn 200001 #define mod 1000000007 #define eps 1e-9 int Num; char CH[20]; //const int inf=0x7fffffff; //нчоч╢С const int inf=0x3f3f3f3f; inline ll read() { ll x=0,f=1;char ch=getchar(); while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();} while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();} return x*f; } inline void P(int x) { Num=0;if(!x){putchar('0');puts("");return;} while(x>0)CH[++Num]=x%10,x/=10; while(Num)putchar(CH[Num--]+48); puts(""); } //************************************************************************************** string s; int k; int main() { //test; cin>>s>>k; if(s.size()%k!=0) { cout<<"NO"<<endl; return 0; } int len=s.size()/k; for(int i=0;i<k;i++) { for(int j=0;j<len;j++) { if(s[i*len+j]!=s[i*len+len-j-1]) { cout<<"NO"<<endl; return 0; } } } cout<<"YES"<<endl; }
相关文章推荐
- Codeforces Round #305 (Div. 2)A. Mike and Fax
- Codeforces Round #305 (Div. 2)--A. Mike and Fax
- Codeforces Round #305 (Div. 1) A. Mike and Frog 暴力
- Codeforces Round #305 (Div. 2), problem: (A) Mike and Fax
- Codeforces Round #305 (Div. 2), problem: (A) Mike and Fax
- Codeforces Round #410 (Div. 2)B. Mike and strings(暴力)
- Codeforces Round #305 (Div. 1)E. Mike and Friends 后缀数组+RMQ+线段树
- Codeforces Round #305 (Div. 2) D. Mike and Feet 单调栈
- Codeforces Round #305 (Div. 2) C. Mike and Frog +B. Mike and Fun
- Codeforces Round #305 (Div. 1) B. Mike and Feet(单调栈)
- Codeforces Round #305 (Div. 1) B. Mike and Feet(思路)
- Codeforces Round #305 (Div. 2)B. Mike and Fun
- Codeforces Round #305 (Div. 2)D---Mike and Feet(单调栈)
- Codeforces Round #305 (Div. 2)——D单调/路径压缩——Mike and Feet
- Codeforces Round #305 (Div. 2) C. Mike and Frog
- Codeforces Round #325 (Div. 2) B. Laurenty and Shop(暴力)
- Codeforces Round #318 [RussianCodeCup Thanks-Round] (Div. 2) B. Bear and Three Musketeers(STL_暴力)
- Codeforces Round #430 (Div. 2) C Ilya And The Tree SET暴力
- Codeforces Round #264 (Div. 2) C Gargari and Bishops 【暴力】
- Codeforces Round #312 (Div. 2) C. Amr and Chemistry 暴力