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 ...
随机推荐
- SDP(0):Streaming-Data-Processor - Data Processing with Akka-Stream
再有两天就进入2018了,想想还是要准备一下明年的工作方向.回想当初开始学习函数式编程时的主要目的是想设计一套标准API給那些习惯了OOP方式开发商业应用软件的程序员们,使他们能用一种接近传统数据库软 ...
- 一个APP页面一个接口
目前所在的公司做的是健康产业方面的APP,这个产品包括了安卓和IOS还有web三方面,除了要写后台管理的系统外,还要写移动端的接口.第一次写移动端接口就犯了一个错误,以为和web一样是怎么方便怎么来, ...
- 使用CSS画图之三角形(一)
简单的画一个三角形,代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset ...
- My Go Resolutions for 2017(from Russ cox's blog)
我的2017年Go决议 一年之季始于春,我认为写一些今年我希望在Go上做的东西是有意义的. 我每年的目标是帮助Go开发人员.我想确保我们在Go团队中所做的工作对Go开发者有重大的积极影响.可能听起来很 ...
- 使用trim_galore软件遇到的问题
我的原始测序数据是双端测序,在用trim_galore软件去接头的这一步,使用的命令行是 time nohup trim_galore R17002628-SKOV3-m6A_combined_R1. ...
- idea为tomcat设置虚拟地址
1.设置tomcat的server.xml <Host name="localhost" appBase="webapps" unpackWARs=&qu ...
- CRM项目总结
CRM项目总结 一:开发背景 在公司日益扩大的过程中,不可避免的会伴随着更多问题出现. 对外 : 如何更好的管理客户与公司的关系?如何更及时的了解客户日益发展的需求变 ...
- Linux学习笔记整理
2.1BASH命令行基本操作 [用户@主机~]$ # //$#为提示符 $代表普通用户 #代表root用户 ~代表当前目录 ls //list相当于DOS的dir 显示当前目录列表 -a // ...
- mysql创建远程登陆用户并授权
在创建安装微擎的过程中,针对第四步 创建远程登陆用户并授权 > grant all PRIVILEGES on database.* to root@'127.0.0.1' id ...
- .net随笔--不好归类的
1..cs .Designer.cs .resx三种文件 cs是类文件,不介绍了.Designer.cs是visual studio对cs类文件的自动生成代码的一种补充,在编辑器里用视图的方式对win ...