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

php中文网
发布: 2016-06-24 11:52:08
原创
1428人浏览过

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.

立即学习前端免费学习笔记(深入)”;


仿B站视频帧预览插件
仿B站视频帧预览插件

仿B站视频帧预览插件

仿B站视频帧预览插件 49
查看详情 仿B站视频帧预览插件


水题,把环展开成链,而且最多加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 < 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;}
登录后复制


HTML速学教程(入门课程)
HTML速学教程(入门课程)

HTML怎么学习?HTML怎么入门?HTML在哪学?HTML怎么学才快?不用担心,这里为大家提供了HTML速学教程(入门课程),有需要的小伙伴保存下载就能学习啦!

下载
来源:php中文网
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
最新问题
开源免费商场系统广告
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责申明 举报中心 意见反馈 讲师合作 广告合作 最新更新 English
php中文网:公益在线php培训,帮助PHP学习者快速成长!
关注服务号 技术交流群
PHP中文网订阅号
每天精选资源文章推送
PHP中文网APP
随时随地碎片化学习

Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号