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 ...
随机推荐
- getResource().getPath()返回的路径空格变成了 %20
this.getClass().getResource(“/”).getPath()使用者方法查看文件在服务器上的地址,但是地址中的空格会被转化为%20. 解决办法1: URI uri = new U ...
- 让未激活的win8.1不再跳出提示激活的窗口
以管理员运行命令行: 输入以下命令: slmgr.vbs -upk
- 【crunch bang】文件管理器-thunar
Thunar拥有的实用功能: 缩略图查看 批量重命名 安装: $ sudo apt-get install thunar 加速thunar启动速度 sudo leafpad /usr/share/gv ...
- Bonbo Git Server
Install This page covers simple Bonobo Git Server installation. Be sure to check prerequisites page ...
- 【python cookbook】【字符串与文本】11.从字符串中去掉不需要的字符
问题:在字符串的开始.结尾或中间去掉不需要的字符,比如说空格符 解决方案: 1.字符串开始或结尾处去掉字符:str.strip() 2.从左或从右侧开始执行去除字符:str.lstrip().str. ...
- 160902、Ionic、Angularjs、Cordova搭建Android开发环境
1.jdk 环境变量配置 path:C:\Program Files\Java\jdk1.7.0_79\bin 2.node.js 因为安装cordova时要用到node.js的npm 下载地址: h ...
- 前端js,css文件合并三种方式,bat命令
前端js,css文件合并三种方式,bat命令 前端js文件该如何合并三个方式如下:1. 一个大文件,所有js合并成一个大文件,所有页面都引用它.2. 各个页面大文件,各自页面合并生成自己所需js的大文 ...
- Mac下好用的取色器 Sip
总有很多东西,你只是望一眼就已经神魂颠倒.措施有这样的App做的真的是用心的很,养眼,触发你内心冲动的美感.先留下一个,备忘. 太精致了 操作简单,左上角的有心圆点击就可以在任何地方取色了,取色点会z ...
- linux问题汇总---如何生成密钥对
准备:2台机器,ip分别为:192.168.0.195 192.168.1.210目的:通过195ssh远程访问210.无需输入密码 1.首先在195上生成密钥对.#cd /root/.ssh ...
- zabbix监控nginx
nginx status详解 active connections – 活跃的连接数量server accepts handled requests — 总共处理了11989个连接 , 成功创建11 ...