欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  web前端

Codeforces Round #283 (Div. 2)-B. Secret Combination (暴力)_html/css_WEB-ITnose

程序员文章站 2022-04-04 16:23:45
...
Secret Combination

time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

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 test(s)

input

3579

output

024

input

42014

output

0142




题意:给一串数字,有两个操作,一个是add,可以使每个数字都加1,如果等于10,就变成0;另一个操作是每次让串里面的数字循环右移一位。问用这串数经过若此操作后,可以变成的最小串是多少。


分析:直接暴力搞起。add的变化范围只能是0~9(因为每10个一个循环),shift的范围在0~n。直接枚举即可。注意我们最开始挑选最小的时候,可以把“9......9",当做最大值~~~




AC代码:

#include #include #include #include #include #include #include #include #include #include #include #include using namespace std;#define INF 0x7fffffffint main(){    #ifdef sxk        freopen("in.txt","r",stdin);    #endif    int n;    string s;    while(scanf("%d",&n)!=EOF)    {        cin>>s;        string ans = string(n, '9');        for(int add=0; add '9') s[i] -= 10;            }            for(int shift=0; shift


可惜了,比赛的时候,竟然没敢下手,也是醉了~~~~(>_

Codeforces Round #283 (Div. 2)-B. Secret Combination (暴力)_html/css_WEB-ITnose

声明:本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn核实处理。