CodeForces 496B Secret Combination
来源:互联网 发布:mac app store更改用户 编辑:程序博客网 时间:2024/05/01 02:46
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.
3579
024
42014
0142
#include <cstdio>const int maxn=1005;int a[maxn],b[maxn];int n,min,t=10;char s[maxn];void B(){ int tm=a[n-1],i,p=0;for(i=0;i<n;i++) //b[i]数组记录最小的整数{ if(a[i]<b[i]) { p=1;break; }if(a[i]>b[i]) break;}if(p){ for(i=0;i<n;i++) b[i]=a[i];}for(i=n-1;i>0;i--)a[i]=a[i-1];a[0]=tm; return ;}void A(){int p; while(t--)//10次循环,确保每位上的数字都机会加到0{p=0;for(int i=0;i<n;i++){a[i]=(a[i]+1)%10;if(a[i]==0)p=1;}if(p) //某一位上有0时进入操作2for(int j=0;j<n;j++)B();} return;}int main(){ int i; scanf("%d",&n); scanf("%s",s); for(i=0;i<n;i++) { a[i]=s[i]-'0'; b[i]=a[i]; } A(); int p=0; for(i=0;i<n;i++) printf("%d",b[i]); printf("\n"); return 0;}
- CodeForces 496B Secret Combination
- CodeForces-496B Secret Combination
- codeforces 496B Secret Combination
- B. Secret Combination codeforces-problem-496B
- Codeforces 496B Secret Combination(最小表示法)
- B. Secret Combination
- B. Secret Combination
- Codeforces Round #283 (Div. 2)---B. Secret Combination (暴力)
- Codeforces Round #283 (Div. 2)——B. Secret Combination
- Codeforces Round #283 (Div. 2) B. Secret Combination 构造+枚举
- 【CF-496B】Secret Combination(最小字符串表示法)
- Code Forces 496 B. Secret Combination(水~)
- Codeforces Round #283 (Div. 2) A. Minimum Difficulty B. Secret Combination C. Removing Columns
- Codeforces 155B Combination
- codeforces B. Combination(贪心)
- CodeForces 155B - Combination(贪心)
- B. Combination
- Codeforces Combination Lock
- Android中Context详解
- Java过滤器和拦截器
- Json系列之三 让你打印完美的json格式
- 算法训练 最大最小公倍数(此题是坑)
- iOS开发之数组、字典、集合
- CodeForces 496B Secret Combination
- 内部类和外部类的访问细节
- poj1068Parencodings
- 关于ip route 线路负载均衡的一些总结
- 使用 ip route , ip rule , iptables 配置策略路由
- ORACLE 11g安装图解
- javaweb-day07-1&2(Servlet - Cookie)
- Facebook诞生11周年:那些高潮低谷
- 一张图了解cocos2d坐标系