Maison > interface Web > tutoriel HTML > le corps du texte

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

WBOY
Libérer: 2016-06-24 11:52:11
original
1147 Les gens l'ont consulté

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
Copier après la connexion

output

024
Copier après la connexion

input

42014
Copier après la connexion

output

0142
Copier après la connexion




题意:给一串数字,有两个操作,一个是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>
Copier après la connexion
source:php.cn
Déclaration de ce site Web
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn
Tutoriels populaires
Plus>
Derniers téléchargements
Plus>
effets Web
Code source du site Web
Matériel du site Web
Modèle frontal