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 ...
随机推荐
- [Ubuntu] Autostart nginx, php-fpm and mysql in Ubuntu14.04
[nginx] Step 1 Download the shell script wget https://raw.github.com/JasonGiedymin/nginx-init-ubuntu ...
- linux中编译git时提示找不到ssl.h头文件
在centos中的解决方案是安装一个叫 openssl-devel 的包.
- [tp3.2.1]让默认页面: 加载Home模块的Index控制器;而让admin.php默认去加载Admin模块的Adminc控制器.
QQ:让index.php默认加载Home模块的Index控制器;而让admin.php默认去加载Admin模块的Adminc控制器.AA:复制index.php命名为admin.php复制(新建)A ...
- sql 循环语句几种方式
--第一 declare @orderNum varchar(255) create table #ttableName(id int identity(1,1),Orders varchar(2 ...
- 在使用Myeclipse时,用Tomcat添加部署项目的时候报错,或启动tomcat报错
the selected server is enabled,but is not configured properly.deployment to it will not be permitted ...
- Nagios监控远端的mysql
工作原理: 利用特定的用户定期访问指定的mysql数据库.当不能访问或连不通时则报警. 1.在生产库上安装nagios插件 安装略 备注:编译完显示一定要有mysql支持,不然没有chec ...
- Postgres-XL集群搭建
Postgres-XL 是一个完全满足ACID的.开源的.可方便进行水平扩展的.多租户安全的.支持share-nothing;支持海量数据并行处理-MPP(Massively Parallel Pro ...
- js笔记----(运动)淡入淡出
<!DOCTYPE html> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <m ...
- HDU 4707:Pet
Pet Time Limit: 4000/2000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Submis ...
- python安装numpy科学计算模块
解决两个问题: (1)Import Error: No module named numpy (2)Python version 2.7 required, which was not found i ...