B. Secret Combination
2 seconds
256 megabytes
standard input
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.
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.
Print a single line containing n digits — the desired state of the display containing the smallest possible number.
3
579
024
4
2014
0142
/*题目大意:给一整数,有两种方式、1、每位加1,其中9变为0,但不进位。2、整体向后移动一位、最后一位移动到首位
* 问经过若干操作1与2后得到的最小数是多少
*算法分析:可将环问题转换为链进行解决。然后每位累加,加10次依次进行比较即可,暴力完成
*/ #include <bits/stdc++.h>
using namespace std; char a[2200];
char b[2200], ans[2200]; int main() {
int n;
scanf("%d ",&n);
memset(a, 0, sizeof(a));
memset(b, 0, sizeof(b));
memset(ans, 0, sizeof(ans));
for (int i = 0; i<n; i++) scanf("%c",&a[i]);
strcpy(ans, a);
//cout << ans << endl;
for (int i = 0; i<n; i++) a[n+i] = a[i]; int t = 0;
while (t <= 9) {
for (int i = 0; i<2*n; i++) {
int tmp = a[i] - 48;
tmp = (tmp+1) % 10;
a[i] ='0' + tmp;
}
//cout << a << endl;
t ++ ;
for (int i = 0; i<n; i++) {
int flag = 0;
for (int j = i; j<i+n; j++) b[flag++] = a[j];
if (strcmp(ans, b) > 0) strcpy(ans, b);
//cout << b << endl;
}
//cout << ans << endl;
}
cout << ans << endl;
return 0;
}
B. Secret Combination的更多相关文章
- CodeForces 496B Secret Combination
Secret Combination Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u ...
- cf 496B Secret Combination
题目链接:B. Secret Combination You got a box with a combination lock. The lock has a display showing n d ...
- Codeforces Round #283 (Div. 2) B. Secret Combination 暴力水题
B. Secret Combination time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- 构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination
题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...
- codeforces 496B. Secret Combination 解题报告
题目链接:http://codeforces.com/problemset/problem/496/B 题目意思:给出 n 位数你,有两种操作:1.将每一位数字加一(当某一位 > 9 时只保存个 ...
- Codeforces Round #301 (Div. 2) A. Combination Lock 暴力
A. Combination Lock Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/540/p ...
- A - Combination Lock
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u Description Scroog ...
- Codeforces 540A - Combination Lock
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he ...
- CodeForces 540
A. Combination Lock time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- Hawk原理:通过IEnumerable实现通用的ETL管道
针对IEnumerable已经有多篇文章,本篇介绍如何使用IEnumerable实现ETL. ETL,是英文 Extract-Transform-Load 的缩写,用来描述将数据从来源端经过萃取(ex ...
- ubuntu设置静态ip
设置固定ip地址 >>>>>>>>>> ifconfig -a, (注:p1p1为网卡名称) 配置静态ip vim /etc/networ ...
- .bashrc:16: command not found: shopt配置环境变量时出错
source .bashrc ------------------------------------------------------- .bashrc:: command not found: ...
- IIS加载JSON文件 错误 404
问题描述 在发布项目的时候,有一些文件是json文件,在网页中进行加载,但是在IIS7发布的时候,json文件居然是404,无法找到,在URL上输入地址也一样. 错误原因 IIS内部机制,不支持直接访 ...
- git 的回退
今天下午写了一下午的代码给合并没了 然后晚上觉得还是要好好学习一下git的使用 推荐几个git的教程 https://www.liaoxuefeng.com/wiki/0013739516305929 ...
- LindDotNetCore~基于模块化注入的介绍
LindDotNetCore相关介绍 相关模块 全局都是依赖DI 消息队列 NoSql Caching 仓储 服务总线 Solr 调度 日志 Asspect拦截组件 UAA授权 各种组件环境的搭建 各 ...
- python字符集的转换(mysql数据乱码的处理)
本文参考:http://blog.csdn.net/crazyhacking/article/details/39375535 chardet模块:http://blog.csdn.net/tianz ...
- HTML5新特性:元素的classList属性与应用
在html5新增的classList之前, 操作元素的class用的是className这个属性,而如果要向jquery封装的hasClass, removeClass, addClass, togg ...
- vue2.0 页面A跳转到页面B,B页面停留在A页面的滚动位置的解决方法
如果页面A沿Y轴滚动一段距离,然后跳转到页面B: 在进入B页面时,B页面已经滚到页面A的距离,返回页面A,发现A还在之前的滚动位置: 这样体验就很不好,所以我们要进行一些处理: 我的方法是:在路由守卫 ...
- Java学习笔记4(方法)
方法和c++中的函数类似,区别在于java的方法定义不限位置,而c++中的定义在主函数后面的函数调用前要声明: 求矩形面积方法示例: public class MethodDemo{ public s ...