Codeforces Round #283 (Div. 2)——B. Secret Combination
来源:互联网 发布:世界格局 知乎 编辑:程序博客网 时间:2024/04/28 07:11
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 number579, then if we push the first button, the display will show680, and if after that we push the second button, the display will show068.
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.
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.
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 < 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;}
- Codeforces Round #283 (Div. 2)——B. Secret Combination
- Codeforces Round #283 (Div. 2)---B. Secret Combination (暴力)
- Codeforces Round #283 (Div. 2) B. Secret Combination 构造+枚举
- Codeforces Round #283 (Div. 2) A. Minimum Difficulty B. Secret Combination C. Removing Columns
- CodeForces 496B Secret Combination
- CodeForces-496B Secret Combination
- codeforces 496B Secret Combination
- Codeforces Round #166 (Div. 2) c. Secret
- B. Secret Combination codeforces-problem-496B
- Codeforces Round #283 (Div. 2) A B
- Codeforces Round #154 (Div. 2)——B
- Codeforces Round #156 (Div. 2)——B
- Codeforces Round #151 (Div. 2)——B
- Codeforces Round #152 (Div. 2)——B
- Codeforces Round #149 (Div. 2)——B
- Codeforces Round #146 (Div. 2)——B
- Codeforces Round #144 (Div. 2)——B
- Codeforces Round #142 (Div. 2)——B
- 下雨了 中英对照
- JS中offsetTop、clientTop、scrollTop、offsetTop各属性介绍
- 记票统计
- Bigtable:一个分布式的结构化数据存储系统
- Log4j 在项目中的应用
- Codeforces Round #283 (Div. 2)——B. Secret Combination
- BigDecimal高精度编程
- UVA - 10110 Light, more light
- Android Studio选择默认运行build variant(debug,Release...)
- 循环水处理剂:工业循环水处理剂重要性
- 分布式系统阅读笔记(一)-----分布式系统的特征
- Jenkins入门系列之——01第一章 Jenkins是什么?
- java学习--IO流(1)
- oracle 表连接 - hash join 哈希连接