Codeforces Round #177 (Div. 1) / 288A Polo the Penguin and Strings(贪心)

【ORB-SLAM3】使用安卓手机的摄像头运行ORB3 使用安卓手机的摄像头运行ORB-SLAM3单目 阅读详情

A. Polo the Penguin and Strings
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

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:

  1. The string consists of n lowercase English letters (that is, the string's length equals n), exactly k of these letters are distinct.
  2. 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).
  3. 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).

Sample test(s)
input
7 4
output
ababacd
input
4 7
output
-1

大水题。


完整代码:

/*30ms,0KB*/

#include<cstdio>

int main()
{
	int n, k;
	scanf("%d%d", &n, &k);
	if (n < k)
		printf("-1");
	else if (n == k)
		for (int i = 97; i < 97 + k; ++i)
			putchar(i);
	else if (k == 1)
		printf("-1");
	else
	{
		n -= k - 2;
		if (n & 1)
		{
			n = (n - 1) >> 1;
			for (int i = 0; i < n; ++i)
			{
				putchar('a');
				putchar('b');
			}
			putchar('a');
		}
		else
		{
			n >>= 1;
			for (int i = 0; i < n; ++i)
			{
				putchar('a');
				putchar('b');
			}
		}
		for (int i = 99; i < 97 + k; ++i)
			putchar(i);
	}
	return 0;
}



Coze智能体开发:开始使用扣子 扣子全新升级!它不仅能帮你办公、做视频、写代码,更具备自主任务执行、探索进化等能力,真正从“陪你聊”走向“帮你干活”。 阅读详情

相关推荐

Java写一条吃满屏幕的贪吃蛇(A*自动寻路算法和一些简单的策略) 二

上一篇文章介绍了一条贪吃蛇的简单实现,这一篇介绍贪吃蛇的自动寻路算法 ,说是自动寻路其实也就是一种遍历地图的算法,如果玩过游戏肯定知道游戏里面一般会有自动寻路功能,贪吃蛇的自动寻路算法也就是实现这个功能。下面慢慢介绍这种算法吧。    最开始,我没有在网上找资料的时候,我对于设计寻路算法的看法是遍历整个地图,将障碍物做上标记,然后找一条能够到达目的地的线路就可以了。所以最开始我用了特别暴力的方式来...

Sober_yang的博客 3632

Codeforces Round #177 (Div. 1) A - Polo the Penguin and Strings

贪心,尽量把不同的数向后填。。。 #include #include #include #include #include #include #include #include #include #include #include #include #include #define maxn 1000005 #define maxm 2000005 #define ep

yysys 735

Class AB OPA STB仿真相位异常:从corner case到碰撞电离的排查与规避

本文深入分析了Class AB运算放大器(OPA)在STB稳定性仿真中,特定工艺角(corner case)下出现相位从0°开始的异常现象。排查发现,其根本原因在于高Vds引发的碰撞电离效应,通过衬底和电源网络引入了隐藏的正反馈通路。文章对比了修改衬底连接与优化电路降低Vds两种解决方案,并基于工程实践推荐了代价更小、兼容性更好的电路优化方案,成功规避了问题并完成流片验证。

grape的博客 636

UVa 11264 Coin Collector (选硬币&贪心好题)

思路: 1. 你肯定注意到了,面值最大的硬币c[n-1]必须要选。(反证:如果花了sum元却没有选中它,可知sum<c[n-1],于是用m+c[n-1]元去兑换可以得到一个更优解。) 2. 贪心的关键:假设S(i)是c[1]…c[i] 中那些被选中的货币的面值的和。那么一定有 S(i) < c[i+1]。 3. 所以可以构造一个这样的序列出来。按照2中所说,如果有 S(i-1) < c[i]且S(i) =S(i-1)+c[i]<c[i+1],那么c[i]将被选中。 完整代码:

AC,∑ndless 4699

TCGA数据下载保姆级教程:用GDC-client从零搞定,附配置文件避坑指南

本文提供TCGA数据下载的完整教程,详细讲解如何使用GDC-client工具从零开始配置到高效获取基因组数据。涵盖环境准备、认证配置、数据检索、高效下载及故障处理等关键步骤,并附配置文件避坑指南,帮助生物医学研究者快速掌握TCGA数据下载技巧。

weixin_30892037的博客 262

保姆级教程:在Ubuntu 22.04上搞定PX4 V1.14 + ROS2 Humble的HITL仿真(避坑实录)

本文提供在Ubuntu 22.04上配置PX4 V1.14与ROS2 Humble的HITL仿真环境的详细教程,涵盖环境准备、固件编译、QGroundControl配置、ROS2通信设置及联调测试。特别针对版本兼容性、Gazebo插件构建和MicroDDS配置等常见问题提供避坑指南,帮助开发者高效搭建无人机仿真系统。

weixin_30836759的博客 1004

UVa 256 Quirksome Squares (枚举||二次同余)

直接从0~9999枚举即可,因为等式右边一定是个完全平方数。 PS:此题可抽象成一个数论的问题:(部分解法参考了这篇文章) 求解4个二元二次丢番图方程 (x+y)^2=2mx+y,m=10^k / 2 = 2^(k-1)*5^(2k),k=1,2,3,4 令x+y=t,上式化为 t^2-2mt+(2m-1)y=0(由于0<=t^2<10^2k,所以0<=t<10^k) 进而 (t-m)^2=(1-2m)y+m^2 此方程的等价于求解二次同余式

AC,∑ndless 3440

【异常】Nacos 2.x 核心报错:Server check fail (gRPC 端口连不通) 深度排查

如果 Nacos 运行在 K8s 中,需确保对应的Servicemetadata:spec:ports:port: 8848port: 9848 # 必须暴露此端口selector:app: nacos在 Nacos 2.x 时代,“端口成套出现”是基础设施配置的基本要求。遇到连接失败时,首要检查的不是业务配置,而是网络链路上主端口 + 1000的 TCP 通讯是否被放行。更多关于 AI + 教育领域的干货,可以关注我的微信公众号一时间获取哦~

奶爸的编程之路,也就一周冷个三天 325

UVa 10049 Self-describing Sequence (自描述序列&二分递推)

10049 - Self-describing Sequence Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=34&page=show_problem&problem=990 Solomon Golomb's self­des

AC,∑ndless 3143

反激电源及其变压器计算与绕制

本内容以一个宽电压输入 24V3A 输出的 72W 反激电源为例来计算电路的各个参数和器件选型,包含反激变压器的计算与绕制方法。

让你爱上电路设计 1937

NX二次开发 内部函数鼠标动态位置获取

内部函数鼠标动态位置获取

qq285503851的博客 3337

UVa 108 Maximum Sum (贪心&最大子矩阵和)

108 - Maximum Sum Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=113&page=show_problem&problem=44 Background A problem that is simple

AC,∑ndless 2784

汉书HE8,好用的汇编代码编写工具

汉书HE8,好用的汇编代码编写工具早期编写汇编代码所用功能强大

UVa 10057 A mid-summer night's dream. (二分&可以取哪些作为中位数?)

输出注意: 第一个数是最小的A,第二个数是在数列{Xn}中有多少个数可以是A,第三个数是在有多少个数可以是A。 完整代码:

AC,∑ndless 2495

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

OV9734 DATASHEET,完整规格书

OV9734完整规格书,包括电气参数,尺寸规格,寄存器配置表等

Codeforces Round #105 (Div. 2) / 148A Insomnia cure (枚举 || 数论)

A. Insomnia cure http://codeforces.com/problemset/problem/148/A time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output

AC,∑ndless 2453

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

AOJ 0033 Ball (枚举)

题意: 有一个形似央视大楼(233)的筒,从A口可以放球,放进去的球可通过挡板DE使其掉进B裤管或C裤管里,现有带1-10标号的球按给定顺序从A口放入,问是否有一种控制挡板的策略可以使B裤管和C裤管中的球从下往上标号递增。  输入: 第一行输入数据组数N。接下来N行为N组具体数据,每组数据中有10个整数,代表球的放入顺序。  输出: 对于每组数据,若策略存在,输出YES;若不存在,输

AC,∑ndless 2325

UVa 12261 High Score (贪心&“向左走,向右走”)

12261 - High Score Time limit: 3.000 seconds  http://uva.onlinejudge.org/index.php?option=onlinejudge&Itemid=99999999&category=244&page=show_problem&problem=3413 思路:注意名字中有若干个A的情况,这时对每串连续的A进行“向左走,

AC,∑ndless 2310

UVa 10125 Sumsets (折半枚举&二分查找)

10125 - Sumsets Time limit: 3.000 seconds  http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=1066 Given S, a set of integers, find the largest d such that a + b +

AC,∑ndless 2305

UVa 1042 Lots of Sunlight (枚举&最优斜率)

1042 - Lots of Sunlight Time limit: 3.000 seconds  http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=3483 思路:对于给定的楼层,枚举左、右的最大斜率。 at

AC,∑ndless 2222

USACO The Clocks 一种O(1)的算法

The Clocks IOI'94 - Day 2 Consider nine clocks arranged in a 3x3 array thusly: |-------| |-------| |-------| | | | | | | | |---O | |---O | | O |

AC,∑ndless 2192

UVa 200 Rare Order (拓扑排序)

200 - Rare Order Time limit: 3.000 seconds  http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=24&page=show_problem&problem=136 题意:给一列单词,这些单词是按一种未知的字典顺序排列的,要求输出这些字母

AC,∑ndless 2122

UVa 1193 / POJ 1328 / Beijing 2002 Radar Installation (贪心&区间选点)

1193 - Radar Installation Time limit: 3.000 seconds http://uva.onlinejudge.org/index.php?option=onlinejudge&page=show_problem&problem=3634 http://poj.org/problem?id=1328 Assume the coasting

AC,∑ndless 2081

UVa 340 Master-Mind Hints (优化查找&复制数组)

学英语: 1. Match (i,j) is called strong when i =j, and is called weak otherwise. 当i=j时,匹配(i,j)被叫做强匹配,反之叫做弱匹配。 2. Two matches (i,j) and (p,q) are called independent when i = p if and only if j = q. A set of matches is called independent when all of its members

AC,∑ndless 2063

Codeforces Round #194 (Div. 1) / 333A Secrets(贪心)

A. Secrets http://codeforces.com/contest/333/problem/A time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Ge

AC,∑ndless 2041

深挖C++:类和对象(中)

(先进后出)

xys_678的博客 248

ThunderKittens 深度解析:一个不基于 MLIR 的 C++ 模板 GPU DSL

Triton 是"让更多人能写 GPU kernel",ThunderKittens 是"让会写的人写得更爽"。前者用 MLIR 换易用性,后者用 C++ 模板换可控性。它们不是替代关系,而是覆盖了 GPU 编程光谱的两端。ThunderKittens 的出现,本质上是对"GPU DSL 必须基于 MLIR"这一默认假设的挑战。编译期类型系统本身就可以是一个强大的 DSL 基础设施,不需要中间 IR,不需要黑盒 pass,也能实现 tile 级抽象和零运行时开销。

Maxwell_Newton的博客 345

C++移动构造函数详解

移动构造函数是C++11引入的一种特殊构造函数,用于从临时对象(右值)"窃取"资源来初始化新对象,而不是进行昂贵的深拷贝。char* data;public:// 移动构造函数:参数是右值引用 &&// 关键:把源对象的资源置空。

拒绝AI文,努力在AI时代写出感动人心的好文章 392
上一篇: Codeforces Round #195 (Div. 2) / 336A Vasily the Bear and Triangle(模拟&数学)
下一篇: Codeforces Round #182 (Div. 2) / 302A Eugeny and Array(模拟)
synapse7
博客等级 码龄14年 432粉丝 701原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值