CF 548A Mike and Fax

Descripe

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.

Sample test(s)

Input

saba2

Output

NO

Input

saddastavvat2

Output

YES

Note

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".

CODE:

#include <iostream>
#include <cstdio>
#include <cstring>
#define REP(i, s, n) for(int i = s; i <= n; i ++)
#define REP_(i, s, n) for(int i = n; i >= s; i --)
#define MAX_N 1000 + 10

using namespace std;

char ts[MAX_N], s[MAX_N];
int len[MAX_N], k;

bool check(int l, int r){
    int i = l, j = r;
    bool tmp = 1;
    while(i < j){
        if(s[i] != s[j]){
            tmp = 0; break;
        }
        i ++; j --;
    }
    if(tmp) return true;
    return false;
}

int main(){
    scanf("%s", s + 1); scanf("%d", &k);
    int l = strlen(s + 1);
    if(l % k != 0){printf("NO\n"); return 0;}
    int num = l / k;

    int i = 1; bool ok = 1;
    while(i < l){
        if(!check(i, i + num - 1)) ok = 0;
        i += num;
    }

    if(ok) printf("YES\n");
    else printf("NO\n");

    return 0;
}
    
时间: 2024-08-29 16:08:58

CF 548A Mike and Fax的相关文章

CodeForces 548A Mike and Fax (回文,水题)

题意:给定一个字符串,问是不是恰好存在 k 个字符串是回文串,并且一样长. 析:没什么好说的,每次截取n/k个,判断是不是回文就好. 代码如下: #include<bits/stdc++.h> using namespace std; string s; bool judge(string s){ for(int i = 0, j = s.size()-1; i < s.size(); ++i, --j){ if(s[i] != s[j]) return false; } return

字符串处理 Codeforces Round #305 (Div. 2) A. Mike and Fax

题目传送门 1 /* 2 字符串处理:回文串是串联的,一个一个判断 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <iostream> 7 #include <algorithm> 8 #include <string> 9 using namespace std; 10 11 const int MAXN = 1e3 + 10; 12 const int INF = 0x3f3

A - Mike and Fax

Time Limit:1000MS     Memory Limit:262144KB     64bit IO Format:%I64d & %I64u 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 str

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

CF 548B Mike and Fun

Descripe Mike and some bears are playing a game just for fun. Mike is the judge. All bears except Mike are standing in an n × m grid, there's exactly one bear in each cell. We denote the bear standing in column number j of row number i by (i, j). Mik

cf 547B. Mike and Feet dp

题意: n个矩阵排成一排,n<=2e5,高度分别为hei[i],宽度为1 对于一些连续的矩阵,矩阵的size为矩阵的个数,矩阵的strength为这些矩阵中高度最低的那一个高度 求:for each x such that 1 ≤ x ≤ n the maximum strength among all groups of size x. 对于每一个矩阵,我们先求出这个矩阵的l,r l表示这个矩阵左边最靠近它的小于它的矩阵的下标 r表示这个矩阵右边最靠近它的小于它的矩阵的下标 即在区间(l,r)

Codeforces Round #305 (Div. 2), problem: (A) Mike and Fax

#include<iostream> #include<cstdio> #include<cstring> using namespace std; char a[1000+100]; bool judge(int m,int n) { for(int i=m;i<=(m+n)/2;i++) if(a[i]!=a[m+n-i]) return 0; return 1; } int main() { int k; while(~scanf("%s"

CF 345A Mike and Frog

题目 自己歪歪的做法WA了好多发. 原题中每一秒都相当于 x1 = f1(x1) x2 = f2(x2) 然后这是一个定义域和值域都在[0,m-1]的函数,显而易见其会形成一个环. 而且环长不超过m,所以实际上问题就分为了两部分: 1.x1变到a1,x2变到a2(h -> a的长度) 2.x1做循环,x2做循环直到同时为a1,a2.(a -> a的长度) 我们设第一步分别用了m1 s, m2 s,第二步用了 t1 s ,t2 s. 对于第一部分我们可以直接枚举吗,因为长度不超过m. 对于第二部

2017-4-21-Train:Codeforces Round #305 (Div. 2)

A. Mike and Fax(模拟 + two points) 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 sur