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

WBOY
Release: 2016-06-24 11:52:11
Original
1147 people have browsed it

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
Copy after login

output

024
Copy after login

input

42014
Copy after login

output

0142
Copy after login




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


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




AC代码:

#include <stdio.h>#include <string.h>#include <iostream>#include <algorithm>#include <vector>#include <queue>#include <set>#include <map>#include <string>#include <math.h>#include <stdlib.h>#include <time.h>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<10; add++){            for(int i=0; i<n; i++){                s[i] ++;                if(s[i] > '9') s[i] -= 10;            }            for(int shift=0; shift<n; shift++)                ans = min(ans, s.substr(shift, n-shift) + s.substr(0, shift));        }        cout<<ans<<endl;    }    return 0;}
Copy after login



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



source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template