CodeForces 288A
来源:互联网 发布:淘宝页面图片 编辑:程序博客网 时间:2024/05/22 05:15
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 ass = 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 andx1 = y1, x2 = y2, ... , xp = yp, or there is such number r (r < p, r < q), thatx1 = y1, x2 = y2, ... , xr = yr and xr + 1 < yr + 1. The characters of the strings are compared by their ASCII codes.
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.
In a single line print the required string. If there isn't such string, print "-1" (without the quotes).
Sample test(s)
input
7 4
output
ababacd
input
4 7
output
-1
极为简单的水题:比赛的时候没出,还是因为审题+极端数据的问题。在n>1,并且是m==1时应该输出-1而我输出了N个a..
将思路和重要的条件全部列在纸上。
#include <iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int main(){ int n,m,i,j,k; while(~scanf("%d%d",&n,&m)) { if(n<m) { printf("-1\n"); continue; } else if(m==1) { if(n>1) { printf("-1\n"); continue; } else { printf("a\n"); continue; } } int tmp=m-2; k=n-tmp; if(k%2) { k/=2; while(k--) { printf("ab"); } printf("a"); } else { k/=2; while(k--) { printf("ab"); } } for(i=99; i<tmp+99; i++) { printf("%c",i); } printf("\n"); } return 0;}
- Codeforces #288 A
- CodeForces 288A
- CodeForces 288A--贪心
- CodeForces-a
- Codeforces 903A A
- CodeForces 18A A - Triangle
- CodeForces 133A A. HQ9+
- codeforces 651A A. Joysticks
- 【Codeforces 597A】A. Divisibility
- 【 Codeforces 615A】A. Bulbs
- A. Divisibility CodeForces 597A
- codeforces 417A A. Elimination
- CodeForces 534A A. Exam
- codeforces#98 a
- codeforces#99 a
- codeforces 105 div2 A
- codeforces #121 A
- Codeforces 185A Plant
- Android稳定性
- main方法为何为public static void
- hdu4407容斥原理
- JavaBean基本的内省
- java中的计数信号量(Counting Semaphore)
- CodeForces 288A
- Android四大组件之Activity
- 多线程
- 在VS2013中配置OpenGL及所需库文件下载
- 【C/C++】类和结构
- 【C/C++】成员变量
- 基类
- 【C/C++】构造函数和析构函数
- 【C/C++】拷贝构造函数和赋值函数