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 ...
随机推荐
- JAVA多线程统计日志计数时的线程安全及效率问题
最近工作上遇到一个需求:需要根据nginx日志去统计每个域名的qps(Query Per Second,每秒查询率)数据. 解决了日志读取等问题之后,为了写一个尽可能高效的统计模块,我决定用多线程去计 ...
- 9.11 test
题面.pdf T1:通过打表发现,从一个点出发只有距离为1,2,3,5,6,9,10,13,17的点才不能到达: 那么我们转移的时候只有距离在20以内才不一定能直接转移,那么我们离散化之后; 对于每一 ...
- 重写JS的鼠标右键点击菜单
重写JS的鼠标右键点击菜单 该效果主要有三点,一是对重写的下拉菜单的隐藏和显示:二是屏蔽默认的鼠标右键事件:三是鼠标左键点击页面下拉菜单隐藏. 不多说,上html代码: 1 <ul id=&qu ...
- Python 接口测试(十)
这里对接口测试9 进行优化升级,前端进行重构后的代码,源码已经开源 经过将近一个月的编写 , TIAPTest 接口测试平台 , 已经部署到服务器,开始运行了. http://60.205.187.1 ...
- Ubuntu16.04 添加 Docker用户组
Ubuntu16.04 添加 Docker用户组 将用户添加到docker用户组就不用每次都 sudo了. ### 首先创建用户组 sudo groupadd docker 将用户加如组 sudo g ...
- KMP 算法 C++
#include <iostream>#include<string.h>#include<stdio.h>using namespace std; void Co ...
- redis实现分布式可重入锁
利用redis可以实现分布式锁,demo如下: /** * 保存每个线程独有的token */ private static ThreadLocal<String> tokenMap = ...
- C#用DataTable实现Group by数据统计
http://www.cnblogs.com/sydeveloper/archive/2013/03/29/2988669.html 1.用两层循环计算,前提条件是数据已经按分组的列排好序的. Dat ...
- SqlServer Partition 分区表
分区表 测试版本: Microsoft SQL Server 2014 - 12.0.2000.8 (X64) Feb 20 2014 20:04:26 Copy ...
- MySQL优化二 缓存参数优化
数据库属于 IO密集型的应用程序,其主要职责就是数据的管理及存储工作.而我们知道,从内存中读取一个数据库的时间是微秒级别,而从一块普通硬盘上读取一个IO是在毫秒级别,二者相差3个数量级.所以,要优化数 ...