zoukankan      html  css  js  c++  java
  • Codeforces Round #107 (Div. 1) 某字符串任何子串都为回文串

    Any its substring with length equal to k is a palindrome.

    对于一个长度为n的串,任何它的长度为k的字串都是回文串。该串具有这样的性质:

    如果k为偶数,母串所有字符都相等;aaaaaa

    如果k为奇数,母串最多由两种字母组成;abababa

    View Code
    #include <iostream>
    #include <math.h>
    #define MOD 1000000007
    using namespace std;
    long long ppow(long long x,long long y){
        long long res=1;
        while(y--){
            res=res*x%MOD;
        }
        return res;
    }
    int main(){
        long long n,m,k;
        while(cin >> n >> m >> k){
            if(k==1 || k>n){
                cout << ppow(m,n) <<endl;
            }
            else if(k==n){
                if(n%2==0){
                    cout << ppow(m,n/2) << endl;
                }
                else{
                    cout << ppow(m,n/2+1) <<endl;
                }
            }
            else{
                if(k%2==0){
                    cout << m <<endl;
                }
                else{
                    cout << m*m <<endl;
                }
            }
        }
        return 0;
    }
  • 相关阅读:
    跨域处理
    intellij idea远程调试
    sring boot特性
    spring mvc与struts2的区别
    jenkins集成sonar
    hibernate笔记
    python脚本
    python 字符框
    python操作
    python环境配置
  • 原文地址:https://www.cnblogs.com/markliu/p/2633262.html
Copyright © 2011-2022 走看看