Codeforces Round #283 (Div. 2)——B. Secret Combination

本文介绍了一个关于组合锁最小数字开锁的问题。通过将循环展开为链,并利用最多加9次的限制,实现暴力求解。该方法通过复制、循环移位和比较数字来找出最小可能的数字状态,最终输出解。代码示例展示了如何通过简单的循环和条件判断,高效地解决实际问题。
B. Secret Combination
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You got a box with a combination lock. The lock has a display showing n digits. There are two buttons on the box, each button changes digits on the display. You have quickly discovered that the first button adds 1 to all the digits (all digits 9 become digits 0), and the second button shifts all the digits on the display one position to the right (the last digit becomes the first one). For example, if the display is currently showing number 579, then if we push the first button, the display will show 680, and if after that we push the second button, the display will show 068.

You know that the lock will open if the display is showing the smallest possible number that can be obtained by pushing the buttons in some order. The leading zeros are ignored while comparing numbers. Now your task is to find the desired number.

Input

The first line contains a single integer n (1 ≤ n ≤ 1000) — the number of digits on the display.

The second line contains n digits — the initial state of the display.

Output

Print a single line containing n digits — the desired state of the display containing the smallest possible number.



水题,把环展开成链,而且最多加9次,所以暴力就行


#include <map>
#include <set>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <algorithm>

using namespace std;

char str[3000];
char ans[3000];
int main()
{
	int n;
	while (~scanf("%d", &n))
	{
		scanf("%s", str);
		for (int i = n; i < 2 * n - 1; ++i)
		{
			str[i] = str[i - n];
		}
		str[2 * n - 1] = '\0';
		for (int i = 0; i < n; ++i)
		{
			ans[i] = '9';
		}
		ans[n] = '\0';
		int ret = 1;
		while (ret <= 10)
		{
			for (int i = 0; i < n; ++i)
			{
				int cnt = 0;
				bool flag = false;
				while (ans[cnt] == '0')
				{
					cnt++;
				}
				int j = i;
				while (str[j] == '0')
				{
					j++;
				}
				if (n - cnt > i + n - j)
				{
					flag = true;
				}
				else if (n - cnt == i + n - j)
				{
					for (int k = j; k < i + n; ++k)
					{
						if (ans[cnt] == str[k])
						{
							cnt++;
						}
						else if (ans[cnt] > str[k])
						{
							flag = true;
							break;
						}
						else
						{
							break;
						}
					}
				}
				if (flag)
				{
					cnt = 0;
					for (int k = i; k < i + n; ++k)
					{
						ans[cnt++] = str[k];
					}
				}
				ans[n] = '\0';
			}
			for (int i = 0; i < 2 * n - 1; ++i)
			{
				int tmp = str[i] - '0';
				tmp = (tmp + 1) % 10;
				str[i] = tmp + '0';
			}
			str[2 * n - 1] = '\0';
			ret++;
		}
		printf("%s\n", ans);
	}
	return 0;
}


【轴承故障诊断】加权多尺度字典学习模型(WMSDL)及其在轴承故障诊断上的应用(Matlab代码实现)内容概要:本文介绍了加权多尺度字典学习模型(WMSDL)在轴承故障诊断中的应用,并提供了基于Matlab的代码实现。该模型结合多尺度分析与字典学习技术,能够有效提取轴承振动信号中的故障特征,提升故障识别精度。文档重点阐述了WMSDL模型的理论基础、算法流程及其在实际故障诊断中的实施步骤,展示了其相较于传统方法在特征表达能力和诊断准确性方面的优势。同时,文中还提及该资源属于一个涵盖多个科研方向的技术合集,包括智能优化算法、机器学习、信号处理、电力系统等多个领域的Matlab仿真案例。; 适合人群:具备一定信号处理和机器学习基础,从事机械故障诊断、工业自动化、智能制造等相关领域的研究生、科研人员及工程技术人员。; 使用场景及目标:①学习并掌握加权多尺度字典学习模型的基本原理与实现方法;②将其应用于旋转机械的轴承故障特征提取与智能诊断;③结合实际工程数据复现算法,提升故障诊断系统的准确性和鲁棒性。; 阅读建议:建议读者结合提供的Matlab代码进行实践操作,重点关注字典学习的训练过程与多尺度分解的实现细节,同时可参考文中提到的其他相关技术(如VMD、CNN、BILSTM等)进行对比实验与算法优化。
【硕士论文复现】可再生能源发电与电动汽车的协同调度策略研究(Matlab代码实现)内容概要:本文档围绕“可再生能源发电与电动汽车的协同调度策略研究”展开,旨在通过Matlab代码复现硕士论文中的核心模型与算法,探讨可再生能源(如风电、光伏)与大规模电动汽车接入电网后的协同优化调度方法。研究重点包括考虑需求侧响应的多时间尺度调度、电动汽车集群有序充电优化、源荷不确定性建模及鲁棒优化方法的应用。文中提供了完整的Matlab实现代码与仿真模型,涵盖从场景生成、数学建模到求解算法(如NSGA-III、粒子群优化、ADMM等)的全过程,帮助读者深入理解微电网与智能电网中的能量管理机制。; 适合人群:具备一定电力系统基础知识和Matlab编程能力的研究生、科研人员及从事新能源、智能电网、电动汽车等领域技术研发的工程人员。; 使用场景及目标:①用于复现和验证硕士论文中的协同调度模型;②支撑科研工作中关于可再生能源消纳、电动汽车V2G调度、需求响应机制等课题的算法开发与仿真验证;③作为教学案例辅助讲授能源互联网中的优化调度理论与实践。; 阅读建议:建议结合文档提供的网盘资源下载完整代码,按照目录顺序逐步学习各模块实现,重点关注模型构建逻辑与优化算法的Matlab实现细节,并通过修改参数进行仿真实验以加深理解。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值