首页 > web前端 > html教程 > Codeforces Round #283 (Div. 2)-B. Secret Combination (暴力)_html/css_WEB-ITnose

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

WBOY
发布: 2016-06-24 11:52:11
原创
1176 人浏览过

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 <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 '9') s[i] -= 10;            }            for(int shift=0; shift<n shift ans="min(ans," s.substr n-shift cout return>  <br>  <br>  <p></p>  <p><br> </p>  <p>可惜了,比赛的时候,竟然没敢下手,也是醉了~~~~(>_  </p>
<p><br> </p>  <p><br> </p> </n></time.h></stdlib.h></math.h></string></map></set></queue></vector></algorithm></iostream></string.h></stdio.h>
登录后复制
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板