• 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个相同长度的回文串构成的,判断是否正确

    题解:

     数据范围很小,暴力判断就好了

     1 #include<bits/stdc++.h>
     2 using namespace std;
     3 
     4 int main() {
     5     string str;
     6     int k,n;
     7     int id;
     8     cin>>str>>k;
     9     /**如果恰没有k个的时候是输出NO 没考虑这个条件一直wa*/
    10     if(str.length()%k != 0) {
    11         cout<<"NO"<<endl;
    12         return 0;
    13     } 
    14     n = str.length()/k;
    15     bool ans = false;
    16     /**分成K组进行判断 如果有一组不满足回文串条件  则确定输出NO*/ 
    17     for(int i = 1; i <= k; i++) {
    18         int bi = (i-1)*n;
    19         int ei =  i*n-1;
    20         while(bi <= ei) {
    21             if(str[bi] != str[ei]) {
    22                 ans = true;
    23                 break;
    24             }
    25             ei--;
    26             bi++;
    27         }
    28         if(ans) break;
    29     }
    30     if(ans) cout<<"NO"<<endl;
    31     else cout<<"YES"<<endl;
    32     return 0;
    33 }
  • 相关阅读:
    CentOS安装配置Tomcat-7
    CentOS搭建VSFTP服务器
    使用DDMS测试安卓手机APP的性能(android)
    Linux常见问题及解决方案
    数据库版本控制工具:NeXtep Designer
    身份证号码编码规则
    无网络安装mysql步骤
    HTTP协议详解
    Jenkins持续集成构建
    Gulp和Webpack对比
  • 原文地址:https://www.cnblogs.com/jj81/p/8893678.html
Copyright © 2020-2023  润新知