日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

【CodeForces - 289C】Polo the Penguin and Strings (水题,字符串,思维构造,有坑)

發布時間:2023/12/10 编程问答 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 【CodeForces - 289C】Polo the Penguin and Strings (水题,字符串,思维构造,有坑) 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

題干:

Little penguin Polo adores strings. But most of all he adores strings of length?n.

One day he wanted to find a string that meets the following conditions:

  • The string consists of?n?lowercase English letters (that is, the string's length equals?n), exactly?k?of these letters are distinct.
  • No two neighbouring letters of a string coincide; that is, if we represent a string as?s?=?s1s2...?sn, then the following inequality holds,?si?≠?si?+?1(1?≤?i?<?n).
  • Among all strings that meet points 1 and 2, the required string is lexicographically smallest.
  • Help him find such string or state that such string doesn't exist.

    String?x?=?x1x2...?xp?is?lexicographically less?than string?y?=?y1y2...?yq, if either?p?<?q?and?x1?=?y1,?x2?=?y2,?... ,?xp?=?yp, or there is such number?r?(r?<?p,?r?<?q), that?x1?=?y1,?x2?=?y2,?... ,?xr?=?yr?and?xr?+?1?<?yr?+?1. The characters of the strings are compared by their ASCII codes.

    Input

    A single line contains two positive integers?n?and?k?(1?≤?n?≤?106,?1?≤?k?≤?26)?— the string's length and the number of distinct letters.

    Output

    In a single line print the required string. If there isn't such string, print "-1" (without the quotes).

    Examples

    Input

    7 4

    Output

    ababacd

    Input

    4 7

    Output

    -1

    題目大意:(摘抄)

    給定一個長度為n的字符串,讓你用前k種小寫字母將字符串排成一個長度為n的,左右相鄰字母不相同的,且字典序最小的字符串。注意必須要用K種。如果不能做到則輸出-1.

    解題報告:

    ? ?水題,,但是還是有些粗心的,,k==1的時候也需要特判啊!!

    AC代碼:

    #include<cstdio> #include<iostream> #include<algorithm> #include<queue> #include<map> #include<vector> #include<set> #include<string> #include<cmath> #include<cstring> #define ll long long #define pb push_back #define pm make_pair #define fi first #define se second using namespace std; const int MAX = 1e6 + 5; int n,k; char s[MAX]; int main() {cin>>n>>k;if(k>n) {puts("-1");return 0 ;}if(n == 1) {printf("a");return 0 ;}if(n>1 && k==1) {puts("-1");return 0 ;}int tmp = k-2;int tt=tmp+2;for(int i = n; i>=n-tmp+1; i--) {s[i] = 'a'-1 + tt;tt--;}for(int i = 1; i<=n-tmp; i++) {if(i%2==1) s[i] = 'a';else s[i]='b';}printf("%s\n",s+1);return 0 ;}

    ?

    總結

    以上是生活随笔為你收集整理的【CodeForces - 289C】Polo the Penguin and Strings (水题,字符串,思维构造,有坑)的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。