CodeForces 496B Secret Combination
Time Limit:2000MS Memory Limit:262144KB 64bit IO Format:%I64d & %I64u
Description
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.
Sample Input
3
579
024
4
2014
0142
#include <stdio.h>
#include <string.h>
int main()
{
int n;
int i,j,k;
char a[];
int b[];
while(scanf("%d",&n)!=EOF)
{
b[]=;
for(i=;i<;i++)
b[i]=;
scanf("%s",a);
for(i=;i<n;i++)
{
int x=''-a[i]+;
for(j=;j<n;j++)
{
int y=(a[(i+j)%n]-''+x)%;
if(y<b[j])
{
for(k=;k<n;k++)
{
b[k]=(a[(i+k)%n]-''+x)%;
}
break;
}
else if(y>b[j])
{
break;
}
}
}
for(i=;i<n;i++)
printf("%d",b[i]);
printf("\n");
}
return ;
}
CodeForces 496B Secret Combination的更多相关文章
- codeforces 496B. Secret Combination 解题报告
题目链接:http://codeforces.com/problemset/problem/496/B 题目意思:给出 n 位数你,有两种操作:1.将每一位数字加一(当某一位 > 9 时只保存个 ...
- 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
题目传送门 /* 构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好! */ /************************************** ...
- 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 ...
- B. Secret Combination
B. Secret Combination time limit per test 2 seconds memory limit per test 256 megabytes input standa ...
- [Codeforces]1263D Secret Passwords
题目 One unknown hacker wants to get the admin's password of AtForces testing system, to get problems ...
- 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 ...
- Codeforces 540A - Combination Lock
Scrooge McDuck keeps his most treasured savings in a home safe with a combination lock. Each time he ...
- Codeforces Round #301 (Div. 2)(A,【模拟】B,【贪心构造】C,【DFS】)
A. Combination Lock time limit per test:2 seconds memory limit per test:256 megabytes input:standard ...
随机推荐
- 夺命雷公狗---Thinkphp----3之后台搭建
我们这里来搭建我们网站所需要用到的后台: 我们直接打开WEB目录,然后直接赋值Home文件粘贴并改名为Admin,效果如下所示: 然后修改他的控制器: 代码修改成如下所示: <?php name ...
- css 标签 垂直居中
<!DOCTYPE html > <html xmlns="http://www.w3.org/1999/xhtml"> <head> < ...
- [Ubuntu] ubuntu13.04 从php5.4降级到php5.3
ubuntu12.10以后,默认的deb安装库上面的php版本已经是5.4了,公司的项目使用5.4的时候,还是会出现很多问题,所以不得不降级安装5.3 顺便说一句,我原来的环境是nginx + php ...
- DataGridView 些许事件测试
原始设计需求:当单元格内容是空白时,鼠标进入之后,显示一些数据 直观的第一感觉必然是用CellClick,细想,如果用户不用鼠标,直接按Tab键切换单元格呢?又或者,用户直接双击涅~ 主要测试的是: ...
- PS4 的下载速度问题
折腾了好久了 AC68u路由自启动修改 hosts 问题,打算FQ另外改善 ps4 下载速度太慢问题. 后来看到几个dns, 直接修改后就速度超快,也不用在路由中添加了, 直接在 ps4 中网络设置中 ...
- Erlang-特性
一.模式匹配: 模式匹配作为Erlang的基础,用来完成很多不同的任务:可以用它从数据结构中提取字段值,在函数中进行流程控制,或者当你向一个进程发送消息时,从并行程序刷选那些需要处理的消息: 二.函数 ...
- Android 常用工具类之 DimenUtil
public class DimenUtil { /** sp转换成px */ public static int sp2px(float spValue) { float fontScale = M ...
- export
export export PATH=$PATH:/ROOT
- PHP使用PHPExcel删除Excel单元格指定列的方法是怎样
有一个系统仅公司内部和外部经销商使用,在一个导出功能中公司内部员工跟外部经销商导出的列是不一样的(某些数据是不能提供给经销商的)因为导出的数据都是一样的(某些列外数据外部没有)因此并没有单独处理,而是 ...
- anroid 查看签名信息的方法
1.把app改成压缩文件 2.解压以后找到META-INF\CERT.RSA 3.在CMD命令行里面输入: keytool -printcert -file E:\META-INF\CERT.RS ...