最新文章专题视频专题问答1问答10问答100问答1000问答2000关键字专题1关键字专题50关键字专题500关键字专题1500TAG最新视频文章推荐1 推荐3 推荐5 推荐7 推荐9 推荐11 推荐13 推荐15 推荐17 推荐19 推荐21 推荐23 推荐25 推荐27 推荐29 推荐31 推荐33 推荐35 推荐37视频文章20视频文章30视频文章40视频文章50视频文章60 视频文章70视频文章80视频文章90视频文章100视频文章120视频文章140 视频2关键字专题关键字专题tag2tag3文章专题文章专题2文章索引1文章索引2文章索引3文章索引4文章索引5123456789101112131415文章专题3
当前位置: 首页 - 科技 - 知识百科 - 正文

CodeforcesRound#283(Div.2)--B.SecretCombination_html/css

来源:动视网 责编:小采 时间:2020-11-27 15:59:47
文档

CodeforcesRound#283(Div.2)--B.SecretCombination_html/css

CodeforcesRound#283(Div.2)--B.SecretCombination_html/css_WEB-ITnose: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
推荐度:
导读CodeforcesRound#283(Div.2)--B.SecretCombination_html/css_WEB-ITnose: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


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 #include #include #include #include #include #include #include #include #include #include #include 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 < 2 * n - 1; ++i)	{	str[i] = str[i - n];	}	str[2 * n - 1] = '\0';	for (int i = 0; i < n; ++i)	{	ans[i] = '9';	}	ans[n] = '\0';	int ret = 1;	while (ret <= 10)	{	for (int i = 0; i < n; ++i)	{	int cnt = 0;	bool flag = false;	while (ans[cnt] == '0')	{	cnt++;	}	int j = i;	while (str[j] == '0')	{	j++;	}	if (n - cnt > i + n - j)	{	flag = true;	}	else if (n - cnt == i + n - j)	{	for (int k = j; k < i + n; ++k)	{	if (ans[cnt] == str[k])	{	cnt++;	}	else if (ans[cnt] > str[k])	{	flag = true;	break;	}	else	{	break;	}	}	}	if (flag)	{	cnt = 0;	for (int k = i; k < i + n; ++k)	{	ans[cnt++] = str[k];	}	}	ans[n] = '\0';	}	for (int i = 0; i < 2 * n - 1; ++i)	{	int tmp = str[i] - '0';	tmp = (tmp + 1) % 10;	str[i] = tmp + '0';	}	str[2 * n - 1] = '\0';	ret++;	}	printf("%s\n", ans);	}	return 0;}

文档

CodeforcesRound#283(Div.2)--B.SecretCombination_html/css

CodeforcesRound#283(Div.2)--B.SecretCombination_html/css_WEB-ITnose: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
推荐度:
  • 热门焦点

最新推荐

猜你喜欢

热门推荐

专题
Top