日韩性视频-久久久蜜桃-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 (水题,字符串,思维构造,有坑)的全部內容,希望文章能夠幫你解決所遇到的問題。

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

    主站蜘蛛池模板: 久久久天天 | 国产福利视频 | 什么网站可以看毛片 | 全程粗话对白视频videos | 粗大挺进潘金莲身体在线播放 | 国产极品91| 久久精品国产成人av | 一本久道久久综合无码中文 | 日韩精品一区二区亚洲av观看 | 69久久久 | 国产成人久久精品77777综合 | 亚洲免费成人av | 一级特级黄色片 | 二区视频在线 | 香蕉一区二区 | 黄色片网站在线播放 | 超碰成人在线免费观看 | 国产精品第七页 | 男人喷出精子视频 | 久99热 | 亚洲第一第二区 | 超碰在线播放97 | 亚洲精久 | 人物动物互动39集免费观看 | 日韩操操 | 日本黄色免费观看 | 五月天丁香久久 | 中文字幕一区二区三区精华液 | 私人毛片 | 熊出没之冬日乐翻天免费高清观看 | 日本三级大全 | 欧美激情一区二区三级高清视频 | 激情777 | www.天堂av.com | 天天撸天天操 | 天天摸天天爽 | 女人性做爰24姿势视频 | 欧美 亚洲 另类 偷偷 自拍 | 99久久99久久精品国产片桃花 | 亚洲乱码一区二区 | 亚洲乱码视频在线观看 | 操女网站 | 无码人妻久久一区二区三区不卡 | 99ri国产在线 | 一级大毛片 | 国产又粗又猛又爽又黄的视频一 | 七月色| 好吊妞操 | 日韩黄色免费电影 | 亚洲乱码国产乱码精品精软件 | 午夜小视频在线播放 | 日日躁夜夜躁狠狠躁 | 少妇被又大又粗又爽毛片久久黑人 | 香蕉久久网 | 亚洲午夜福利在线观看 | 国产丝袜视频 | 一级免费在线观看 | 国产成人综合欧美精品久久 | 91视频大全 | 91欧美日韩 | 欧美一二三区视频 | 亚洲第一综合网 | 久久久国产成人一区二区三区 | 熟妇熟女乱妇乱女网站 | 国产精品视频在线播放 | 亚洲人成人一区二区在线观看 | 亚洲男人的天堂在线 | 天天射天天射 | 五月综合久久 | 亚洲热在线观看 | 中文字幕人妻一区二区三区视频 | 亚洲美女在线视频 | 狠狠97| 好吊色视频一区二区三区 | 久久精品这里有 | 亚洲第一视频区 | www.日韩精品 | 黄视频免费在线看 | 亚洲色图自拍 | 国产精品91久久久 | 亚洲欧美不卡 | 亚洲精品美女视频 | 日本免费在线播放 | 五月婷婷婷婷 | 国产精品正在播放 | 午夜免费片 | 免费黄色短片 | feel性丰满白嫩嫩hd | 艳妇乳肉亭妇荡乳av | 欧美巨乳在线观看 | 男女做爰猛烈吃奶啪啪喷水网站 | 蜜桃无码一区二区三区 | 欧洲自拍偷拍 | 在线观看h视频 | 国产一区亚洲二区三区 | 一级片www | 日韩欧美亚洲精品 | 最新不卡av| 国产乱淫av麻豆国产免费 |