构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination

题目传送门

 1 /*
 2     构造+暴力:按照题目意思,只要10次加1就变回原来的数字,暴力枚举所有数字,string大法好!
 3 */
 4 /************************************************
 5 Author        :Running_Time
 6 Created Time  :2015-8-3 8:43:02
 7 File Name     :A.cpp
 8 *************************************************/
 9
10 #include <cstdio>
11 #include <algorithm>
12 #include <iostream>
13 #include <sstream>
14 #include <cstring>
15 #include <cmath>
16 #include <string>
17 #include <vector>
18 #include <queue>
19 #include <deque>
20 #include <stack>
21 #include <list>
22 #include <map>
23 #include <set>
24 #include <bitset>
25 #include <cstdlib>
26 #include <ctime>
27 using namespace std;
28
29 #define lson l, mid, rt << 1
30 #define rson mid + 1, r, rt << 1 | 1
31 typedef long long ll;
32 const int MAXN = 1e3 + 10;
33 const int INF = 0x3f3f3f3f;
34 const int MOD = 1e9 + 7;
35 string mn, now, str;
36 int n;
37
38 int main(void)    {       //Codeforces Round #283 (Div. 2) B. Secret Combination
39     while (cin >> n)   {
40         cin >> str;   mn = str; now = str;
41         for (int i=1; i<=10; ++i)   {
42             for (int j=0; j<n; ++j)  {
43                 if (now[j] == ‘9‘)  now[j] = ‘0‘;
44                 else    now[j]++;
45             }
46             cout << now << endl;
47             for (int j=0; j<n; ++j) {
48                 string tmp = "";
49                 for (int k=j; k<n; ++k) tmp += now[k];
50                 for (int k=0; k<j; ++k) tmp += now[k];
51                 if (tmp < mn)   mn = tmp;
52             }
53         }
54         cout << mn << endl;
55     }
56
57     return 0;
58 }
时间: 2024-10-10 05:02:28

构造+暴力 Codeforces Round #283 (Div. 2) B. Secret Combination的相关文章

暴力+构造 Codeforces Round #283 (Div. 2) C. Removing Columns

题目传送门 1 /* 2 题意:删除若干行,使得n行字符串成递增排序 3 暴力+构造:从前往后枚举列,当之前的顺序已经正确时,之后就不用考虑了,这样删列最小 4 */ 5 /************************************************ 6 Author :Running_Time 7 Created Time :2015-8-3 10:49:53 8 File Name :C.cpp 9 ************************************

Codeforces Round #283 (Div. 2) a

/**  * @brief Codeforces Round #283 (Div. 2) a  * @file a.cpp  * @author mianma  * @created 2014/12/18 17:45  * @edited  2014/12/18 17:45  * @type brute  * @note  */ #include <fstream> #include <iostream> #include <cstring> using namespa

Codeforces Round #283 (Div. 2) c

/**  * @brief Codeforces Round #283 (Div. 2) c  * @file c.cpp  * @author mianma  * @created 2014/12/22 13:38  * @edited  2014/12/22 13:38  * @type greedy  * @time cost time O(m*n)  * @mem  cost mem  2*MAXN^2 + 2*MAXN  * @note  */ #include <fstream>

Codeforces Round #283 (Div. 2) b

/**  * @brief Codeforces Round #283 (Div. 2) b  * @file b.cpp  * @author mianma  * @created 2014/12/19 10:50  * @edited  2014/12/19 10:50  * @type brute  * @note  */ #include <fstream> #include <iostream> #include <cstring> using namespa

数学/找规律/暴力 Codeforces Round #306 (Div. 2) C. Divisibility by Eight

题目传送门 1 /* 2 数学/暴力:只要一个数的最后三位能被8整除,那么它就是答案:用到sprintf把数字转移成字符读入 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <iostream> 8 #include <cmath> 9 #include <vector> 10 using namespace std; 11

暴力 Codeforces Round #305 (Div. 2) B. Mike and Fun

题目传送门 1 /* 2 暴力:每次更新该行的num[],然后暴力找出最优解就可以了:) 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <iostream> 7 #include <algorithm> 8 #include <string> 9 using namespace std; 10 11 const int MAXN = 5e2 + 10; 12 const int

数论/暴力 Codeforces Round #305 (Div. 2) C. Mike and Frog

题目传送门 1 /* 2 数论/暴力:找出第一次到a1,a2的次数,再找到完整周期p1,p2,然后以2*m为范围 3 t1,t2为各自起点开始“赛跑”,谁落后谁加一个周期,等到t1 == t2结束 4 详细解释:http://blog.csdn.net/u014357885/article/details/46044287 5 */ 6 #include <cstdio> 7 #include <algorithm> 8 #include <cstring> 9 #in

暴力 Codeforces Round #183 (Div. 2) A. Pythagorean Theorem II

题目传送门 1 /* 2 暴力:O (n^2) 3 */ 4 #include <cstdio> 5 #include <algorithm> 6 #include <cstring> 7 #include <cmath> 8 #include <vector> 9 using namespace std; 10 11 const int MAXN = 1e4 + 10; 12 const int INF = 0x3f3f3f3f; 13 14

二分查找/暴力 Codeforces Round #166 (Div. 2) B. Prime Matrix

题目传送门 1 /* 2 二分查找/暴力:先埃氏筛选预处理,然后暴力对于每一行每一列的不是素数的二分查找最近的素数,更新最小值 3 */ 4 #include <cstdio> 5 #include <cstring> 6 #include <algorithm> 7 using namespace std; 8 9 const int MAXN = 5e2 + 10; 10 const int MAXM = 1e6 + 10; 11 const int INF = 0