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 ...
随机推荐
- .NET开发一个微信跳一跳辅助程序
昨天微信更新了,出现了一个小游戏"跳一跳",玩了一下 赶紧还蛮有意思的 但纯粹是拼手感的,玩了好久,终于搞了个135分拿了个第一名,没想到过一会就被朋友刷下去了,最高的也就200来 ...
- 如何给动态添加的form表单控件添加表单验证
最近使用jQuery Validate做表单验证很方便,api地址为http://www.runoob.com/jquery/jquery-plugin-validate.html 但是在使用的时候也 ...
- 前端MVC Vue2学习总结(五)——表单输入绑定、组件
一.表单输入绑定 1.1.基础用法 你可以用 v-model 指令在表单控件元素上创建双向数据绑定.它会根据控件类型自动选取正确的方法来更新元素.尽管有些神奇,但 v-model 本质上不过是语法糖, ...
- Windows,Mac与Linux哪个更适合开发者?
以前写的,怕引来口水战,干脆不发.这段时间面试了十来人,用Mac的开发水平明显高于Windows的,挺多感想的,于是改改发了吧. Windows: 对普通用户而言体验最友好,对开发者 ...
- Macaca自动化工具之uirecorder脚本录制
UI Recorder功能介绍 支持所有用户行为: 键盘事件, 鼠标事件, alert, 文件上传, 拖放, svg, shadow dom 支持无线native app录制, 基于macaca实现: ...
- Python第二十二天 stat模块 os.chmod方法 os.stat方法 pwd grp模块
Python第二十二天 stat模块 os.chmod方法 os.stat方法 pwd grp模块 stat模块描述了os.stat(filename)返回的文件属性列表中各值的意义,根据 ...
- 关于java 定时任务
几种任务调度的 Java 实现方法与比较 综观目前的 Web 应用,多数应用都具备任务调度的功能.本文由浅入深介绍了几种任务调度的 Java 实现方法,包括 Timer,Scheduler, Quar ...
- 图解JQUERY尺寸及位置定义
最近在学习JQUERY的一些应用,接触到了JQUERY对于元素尺寸及位置定义,还有就是配合浏览器尺 寸及状态的计算所做出的一些动画特效.其实像这类JQUERY应用无外乎涉及这些属性的调用:innerH ...
- JavaScript的DOM编程--03--读写属性节点
读写属性节点: 1)可以直接通过 cityNode.id 这样的方式来获取和设置属性节点的值 2)通过元素节点的 getAttributeNode 方法来获取属性节点, 然后在通过 nodeValue ...
- linux 操作中命令备忘
1 使用grep 查询关键内容 如果你想在当前目录下 查找"hello,world!"字符串,可以这样: grep -rn "hello,world!" * * ...