Codeforces Round #283 (Div. 2)--B. Secret Combination_html/css_WEB-ITnose

WBOY
發布: 2016-06-24 11:52:08
原創
1250 人瀏覽過

B. 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.



水题,把环展开成链,而且最多加9次,所以暴力就行


#include <map>#include <set>#include <list>#include <queue>#include <stack>#include <vector>#include <cmath>#include <cstdio>#include <cstdlib>#include <cstring>#include <iostream>#include <algorithm>using namespace std;char str[3000];char ans[3000];int main(){	int n;	while (~scanf("%d", &n))	{		scanf("%s", str);		for (int i = n; i  i + n - j)				{					flag = true;				}				else if (n - cnt == i + n - j)				{					for (int k = j; k  str[k])						{							flag = true;							break;						}						else						{							break;						}					}				}				if (flag)				{					cnt = 0;					for (int k = i; k   <br>  <br>  <p></p> </algorithm></iostream></cstring></cstdlib></cstdio></cmath></vector></stack></queue></list></set></map>
登入後複製
來源:php.cn
本網站聲明
本文內容由網友自願投稿,版權歸原作者所有。本站不承擔相應的法律責任。如發現涉嫌抄襲或侵權的內容,請聯絡admin@php.cn
熱門教學
更多>
最新下載
更多>
網站特效
網站源碼
網站素材
前端模板
關於我們 免責聲明 Sitemap
PHP中文網:公益線上PHP培訓,幫助PHP學習者快速成長!