zoukankan      html  css  js  c++  java
  • CodeForces 288A Polo the Penguin and Strings (水题)

    题意:给定一个字符,让你用前 k 个字符把它排成 n 长度,相邻的字符不能相等,并且把字典序最小。

    析:其实很简单么,我们只要多循环ab,就行,最后再把剩下的放上,要注意k为1的时候。

    代码如下:

    #include <bits/stdc++.h>
    
    using namespace std;
    typedef long long LL;
    const int maxn = 10000 + 5;
    const int INF = 0x3f3f3f3f;
    const int dr[] = {0, 0, 1, -1};
    const int dc[] = {1, -1, 0, 0};
    int a[maxn];
    vector<int> ans;
    
    int main(){
        int n, m, d, k;
        scanf("%d %d", &n, &k);
        if(n < k){
            printf("-1
    ");
            return 0;
        }
        if(k == 1){
            if(n > 1){
                printf("-1
    ");
            }
            else printf("a");
            return 0;
        }
        for(int i = 0; i < n-k+2; ++i){
            if(i % 2)  ans.push_back(1);
            else ans.push_back(0);
        }
        for(int i = n-k+2; i < n; ++i)
            ans.push_back(i-n+k);
        for(int i = 0; i < n; ++i)
            printf("%c", ans[i] + 'a');
        return 0;
    }
    
  • 相关阅读:
    跨域问题
    window7_64+python3.6安装Twisted
    resful协议1
    Http状态码
    数据库学习笔记
    linux学习笔记
    前端学习笔记
    python学习笔记
    mongoDB
    git的使用方法
  • 原文地址:https://www.cnblogs.com/dwtfukgv/p/5705423.html
Copyright © 2011-2022 走看看