标签:
题目链接:http://acm.swust.edu.cn/problem/403/
5 4
|
137915
95
|
1 #include <iostream> 2 #include <string> 3 #include <cstdio> 4 #include <algorithm> 5 #include <sstream>//int 转 string 6 using namespace std; 7 typedef long long LL; 8 int main(){ 9 int len, m, front, cnt, end; 10 LL x[60010] = { 0, 1 }, a, b; 11 while (cin >> len >> m){ 12 int i = 1, j = 1, k; 13 for (k = 2; k <= len; k++){ 14 a = x[i] * 2 + 1; 15 b = x[j] * 4 + 5; 16 if (a > b){ 17 j++; 18 x[k] = b; 19 } 20 else if (a == b){ 21 i++; 22 j++; 23 x[k] = a; 24 } 25 else{ 26 i++; 27 x[k] = a; 28 } 29 } 30 string s = "", ans = ""; 31 for (i = 1; i <= len; i++){ 32 stringstream ss; 33 string str; 34 ss << x[i]; 35 ss >> str; 36 s += str; 37 } 38 cout << s << endl; 39 string::iterator it = s.begin(); 40 s.insert(it, ‘9‘);//有效序列从1开始,防止front越界 41 len = s.size(); 42 front = cnt = 0, end = 1; 43 while (end <= len && cnt != m){ 44 if (s[end] <= s[front]) 45 s[++front] = s[end++]; 46 else{ 47 front--; 48 cnt++; 49 } 50 } 51 while (end <= len) 52 s[++front] = s[end++]; 53 for (i = 1; i < len - m; i++) 54 cout << s[i]; 55 cout << endl; 56 } 57 return 0; 58 }
标签:
原文地址:http://www.cnblogs.com/zyxStar/p/4609277.html