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

C++零开销抽象实战:走读 FlashAttention-2 核心源码,看编译期特化与寄存器复用如何打破显存 在 A100 上跑原生 FlashAttention-1,Tensor Core 算力利用率常年停在 25% 到 40% 的区间;到了 FlashAttention-2,同样的 FP16 矩阵乘运算,利用率直接跃升到 50% 至 73%,在计算图没有少乘一个元素的前提下实现了 2 倍的端到端吞吐提升。 阅读详情

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;
}



机器人手眼标定快速精度验证方法 阅读详情

相关推荐

希捷硬盘卡死修复实战:U盘启动盘制作与低格清零全流程

机械硬盘使用多年后常出现卡顿、假死、坏道等问题,很多用户在网上搜索“希捷硬盘低格工具”或“U盘硬盘复活器”,却发现要么工具不明,要么操作不当造成二次损伤。其实所谓修复工具,本质是U盘启动环境配合硬盘检测与清零软件,低格并非修复物理坏道,而是通过全盘写零触发主控重映射,隔离不稳定扇区。懂原理后,用官方SeaTools、Ventoy/U盘启动盘、Victoria或Linux dd等组合工具,即可对可抢救的硬盘做清零修复。这一技术适用于逻辑坏道、SMART警告、扇区不稳定等场景,但需先备份数据并判断盘体是否有异响

weixin_30431445的博客 226

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

告别复杂编码!用GNURadio + VLC + USRP三步搞定无线视频“直播”(附ffmpeg转码命令)

本文介绍了一种基于GNURadio、VLC和USRP的无线视频传输方案,无需复杂编码即可实现实时视频传输。通过三步流程(工具准备、音频验证、视频传输)和ffmpeg转码命令,帮助用户快速搭建系统,适用于教学演示和原型开发。方案特别强调实时显示效果和带宽优化技巧。

weixin_31714129的博客 364

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

基于FPGA 外置qspi Flash的读写

fpga上实现flash读写代码

weixin_43498765的博客 4967

Procedural modeling

What is procedural modeling? One content generation option is modeling buildings, plants, clouds, cities, and worlds using an underlying system of rules. 1 Procedural Modeling: Grammars A rule-based generative system loosely organized as: ...

qq_24505417的博客 717

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 3443

.NET MAUI 第13讲 深入探索 .NET MAUI Essentials:让应用感知设备与环境,打造智能体验

摘要:本文介绍了.NET MAUI Essentials库如何赋能移动应用感知设备环境的能力。文章详细讲解了设备信息获取(DeviceInfo)、网络状态监测(Connectivity)、地理位置服务(Geolocation)、地图集成(Map)以及传感器(Accelerometer等)等核心功能的使用方法,并提供了完整的代码示例。通过一个综合练习,展示了如何构建设备信息仪表板,实时显示设备参数和网络状态,并实现位置获取与地图导航功能。这些跨平台API能显著提升应用智能化和用户体验,同时保持代码简洁高效。

AlphaNil的博客 1097

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

Qt5开发从入门到精通——第一篇概述

Qt是一个跨平台的C++图形用户界面应用程序框架。它为应用程序开发者提供建立艺术级图形用户界面所需的所有功能。它是完全面向对象的,很容易扩展,并且允许真正的组件编程。在Qt程序开发过程中,除可以通过手写代码实现软件开发功能外,还可以通过Qt的GUI界面设计器(QtDesigner)进行界面的绘制和布局。该工具提供了Qt的基本可绘制窗口部件,如QWidget、QLabel、QPushButton和QVBoxLayout等。•对象查看器•属性编辑器。.........

weixin_44759598的博客 9522

11、在线已知位置的旅行商问题与社会公平匹配算法研究

本文研究了在线已知位置的旅行商问题和社会公平匹配问题。针对在线TSP,在不同请求释放条件下分析了算法的竞争比,并提出了基于射线长度和等待策略的优化算法,特别是在半直线上给出了竞争比为13/9的算法及其流程图。对于社会公平匹配问题,结合二分图完美匹配与成本公平分配,探讨了其NP难性质,并提出了随机FPTAS和确定性PTAS两种近似求解方法。文章还对比了两个问题的特性,讨论了实际应用中的影响因素及未来研究方向,为组合优化与算法公平性提供了理论支持与应用指导。

ios99的博客 63

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 2786

DeerFlow 系列教程 第十八篇 | 实战案例三——用 DeerFlow 构建自定义 AI 工作流

在实际业务中,许多复杂的内容生产任务不是单一技能就能覆盖的。需要先调研某个主题的最新信息基于调研结果撰写结构化的文章或报告对报告中的数据进行可视化处理最终输出符合品牌风格的排版文档或演示文稿这些环节涉及不同的领域知识和工具链,单个内置技能无法完全覆盖。组合自定义技能、MCP 外部工具和多 Agent 协作,构建端到端的工作流。传统手工流程: DeerFlow 自定义工作流:搜索资料、阅读文献 用户描述需求│ │▼ ▼。

weixin_43674738的博客 208

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

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

AC,∑ndless 2498

Statistics and Machine Learning Toolbox

Statistics and Machine Learning Toolbox(带书签),MATLAB统计学习工具

win10 跳过U8环境检测的IE WebControls.rar

win10 安装u8的时候 提示IE WebControls 不通过,这个工具可以欺骗u8的检查。 跳过U8环境检测的IE WebControls。提示导入失败后,重新检测通过。

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

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

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 2194

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 2123

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

USB接口的电源安全:认识USB限流配电开关芯片CH217

USB接口不仅用于数据传输,还承担供电功能,其安全性至关重要。为防止短路、过流等故障影响系统,需采用USB限流配电开关。沁恒微电子CH217集成可调限流(400mA~2.7A)、过流/短路/过温/欠压保护及使能控制,导通电阻仅70mΩ,支持独立端口管理,适用于USBHUB、计算机及嵌入式设备,提升供电可靠性与系统稳定性。

Amateur6的博客 164

eventpp: 一款纯 Header-Only的高性能C++事件库

eventpp是一款纯Header-Only、零依赖的高性能C++事件库,支持C++11及以上,兼容多平台。核心组件包括CallbackList(同步信号槽)、EventDispatcher(事件分发)和EventQueue(异步队列),均提供线程安全机制与优异性能。通过模板策略可灵活配置线程安全级别,支持多生产者-多消费者模式及批量优化。虽原生不支持返回值聚合,但可通过输出参数、forEach遍历或promise/future等方案实现。适用于解耦组件、跨线程通信等场景,是Qt信号槽的轻量高效替代,尤其在

红军不怕远征难,万水千山只等闲 391
上一篇: 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、付费专栏及课程。

余额充值