zoukankan      html  css  js  c++  java
  • CF 548A

    A. Mike and Fax
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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
    saba
     1 #include <algorithm>
     2 #include <cstdio>
     3 #include <iostream>
     4 #include <cstring>
     5 #include <string>
     6 #include <cmath>
     7 #include <map>
     8 
     9 using namespace std;
    10 const int N=1E3+5;
    11 char st[N];
    12 int k,len,ave;
    13 bool ok(int l,int r)
    14 {
    15     for (int i = l ; i<=(l+r)/2;i++)
    16         if (st[i]!=st[l+r-i])
    17             return false;
    18     return true;
    19 }
    20 
    21 int main()
    22 {
    23     cin>>st;
    24     cin>>k;
    25     len = strlen(st);
    26     ave= len/k;
    27     if (k*ave!=len){cout<<"NO"<<endl;return 0;}
    28     for (int i = 1 ; i<=k;i++ )
    29     {
    30             if (!ok((i-1)*ave,i*ave-1))
    31                 {
    32                     cout<<"NO"<<endl;
    33                     //cout<<i<<endl;
    34                     return 0;
    35                 }
    36 
    37     }
    38     cout<<"YES"<<endl;
    39 
    40 
    41 
    42     return 0;
    43 }

    2
    output
    NO
    input
    saddastavvat
    2
    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".

    水题。分割成K个,每个串判断是否回文,如果都是就yes,否则no

    需要注意的是,可能不能正好分成长度相同的K个,这个时候也要No 

  • 相关阅读:
    企业如何在智能制造的时代保持竞争力?
    汽车行业MES系统在产品追溯方面的应用分析
    你能想象未来的MES系统是什么样吗?
    智能制造进入下半场?APS如何进行优化
    【案例】如何让阀门制造提高排产效率?APS系统帮你实现
    APS系统的现状以及与MES系统的关联
    MES被重新定义?做到这几点才算智能制造
    python部分笔记
    BUUCTF Hack World
    BUUCTF--checkin
  • 原文地址:https://www.cnblogs.com/111qqz/p/4534631.html
Copyright © 2011-2022 走看看