[关闭]
@Dmaxiya 2018-08-17T02:13:31.000000Z 字数 4402 阅读 1687

Codeforces Round #449(Div.2)

Codeforces


Contests 链接:Codeforces Round #449(Div.2)
过题数:3
排名:549/7594

A. Scarborough Fair

题意

给定一个长度为 的字符串,有 次操作,对于第 次操作,将区间 上的所有的字符 改为字符 。输出最终的字符串。

数据范围


所有字符为小写字符。

题解

数据范围很小,直接 暴力。

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cfloat>
  7. #include <cstring>
  8. #include <string>
  9. #include <sstream>
  10. #include <vector>
  11. #include <list>
  12. #include <queue>
  13. #include <stack>
  14. #include <map>
  15. #include <set>
  16. #include <bitset>
  17. #include <algorithm>
  18. #include <ctime>
  19. #include <functional>
  20. #include <iomanip>
  21. #include <sstream>
  22. using namespace std;
  23. #define LL long long
  24. const int maxn = 200;
  25. int n, m, l, r;
  26. char ch1[5], ch2[5];
  27. char str[maxn];
  28. void change(int l, int r, char c1, char c2) {
  29. for(int i = l; i <= r; ++i) {
  30. if(str[i] == c1) {
  31. str[i] = c2;
  32. }
  33. }
  34. }
  35. int main() {
  36. #ifdef LOCAL
  37. freopen("test.txt", "r", stdin);
  38. // freopen("out.txt", "w", stdout);
  39. #endif // LOCAL
  40. ios::sync_with_stdio(false);
  41. while(scanf("%d%df", &n, &m) != EOF) {
  42. scanf("%s", str + 1);
  43. for(int i = 0; i < m; ++i) {
  44. scanf("%d%d%s%s", &l, &r, ch1, ch2);
  45. change(l, r, ch1[0], ch2[0]);
  46. }
  47. printf("%s\n", str + 1);
  48. }
  49. return 0;
  50. }

B. Chtholly's request

题意

定义 数,如果无前导零的整数位数为偶数,且这个数是回文的,则这个数就是 数。
给定数字 和 ,求前 小的 数求和 的结果。

数据范围

题解

手动对前几个 数排序可得:可以发现,所有的 数前半部分是从 开始的连续的自然数,因此只要从 到 枚举自然数,生成对应的 数,求和再对 取膜就是答案,时间复杂度为 。

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cfloat>
  7. #include <cstring>
  8. #include <string>
  9. #include <sstream>
  10. #include <vector>
  11. #include <list>
  12. #include <queue>
  13. #include <stack>
  14. #include <map>
  15. #include <set>
  16. #include <bitset>
  17. #include <algorithm>
  18. #include <ctime>
  19. #include <functional>
  20. #include <iomanip>
  21. #include <sstream>
  22. using namespace std;
  23. #define LL long long
  24. const int maxn = 100000 + 100;
  25. int n, p;
  26. LL ten[18];
  27. LL num[maxn];
  28. LL get_num(LL thenum) {
  29. LL nn = thenum;
  30. int dig = 0;
  31. while(nn != 0) {
  32. ++dig;
  33. nn /= 10;
  34. }
  35. thenum *= ten[dig];
  36. dig *= 2;
  37. for(int i = dig / 2; i < dig; ++i) {
  38. thenum += thenum / ten[i] % 10 * ten[dig - i - 1];
  39. }
  40. return thenum;
  41. }
  42. void Init() {
  43. LL thenum = 1;
  44. int cnt = 0;
  45. while(cnt < n) {
  46. num[cnt++] = get_num(thenum);
  47. ++thenum;
  48. }
  49. }
  50. int main() {
  51. #ifdef LOCAL
  52. freopen("test.txt", "r", stdin);
  53. // freopen("out.txt", "w", stdout);
  54. #endif // LOCAL
  55. ios::sync_with_stdio(false);
  56. ten[0] = 1;
  57. for(int i = 1; i < 18; ++i) {
  58. ten[i] = ten[i - 1] * 10;
  59. }
  60. while(scanf("%d%d", &n, &p) != EOF) {
  61. Init();
  62. LL ans = 0;
  63. for(int i = 0; i < n; ++i) {
  64. ans = (ans + num[i]) % p;
  65. }
  66. printf("%I64d\n", ans);
  67. }
  68. return 0;
  69. }

C. Nephren gives a riddle

题意

首先定义字符串 ="What are you doing at the end of the world? Are you busy? Will you save us?"。
对于任意的 ,有 ="What are you doing while sending ""? Are you busy? Will you send ""?"。
对于 次询问,每次询问输出字符串 的第 个字符。

数据范围

题解

由定义可以知道,字符串的长度呈 指数增长,所以不能递归生成字符串。
通过观察可以发现 ,每个 由五部分组成,所以只要记录这五个部分的起始下标和终止下标,就可以递归找到第 个字符,每个部分的起点和终点都可以由 计算得到,所以从 到 预处理所有字符串五个部分的起点与终点即可。
虽然字符串的长度很快就会爆 ,但是 的范围在 内,所以对于所有超出 的范围,都设为 ,该 应比 的上界 大。
时间复杂度为 。

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cfloat>
  7. #include <cstring>
  8. #include <string>
  9. #include <sstream>
  10. #include <vector>
  11. #include <list>
  12. #include <queue>
  13. #include <stack>
  14. #include <map>
  15. #include <set>
  16. #include <bitset>
  17. #include <algorithm>
  18. #include <ctime>
  19. #include <functional>
  20. #include <iomanip>
  21. #include <sstream>
  22. using namespace std;
  23. #define LL long long
  24. const LL INF = 1e18 + 100;
  25. const int maxn = 100000 + 100;
  26. struct Node {
  27. LL ls, le, ms, me, rs, re;
  28. LL len;
  29. };
  30. int T;
  31. LL n, k;
  32. char str0[100] = " What are you doing at the end of the world? Are you busy? Will you save us?";
  33. char strL[100] = " What are you doing while sending \"";
  34. char strM[100] = " \"? Are you busy? Will you send \"";
  35. char strR[100] = " \"?";
  36. Node node[maxn];
  37. void Init() {
  38. node[0].len = 75;
  39. for(int i = 1; i < maxn; ++i) {
  40. node[i].ls = 1;
  41. node[i].le = 34;
  42. node[i].ms = node[i - 1].len + 34 + 1;
  43. node[i].ms = min(node[i].ms, INF);
  44. node[i].me = node[i].ms + 31;
  45. node[i].me = min(node[i].me, INF);
  46. node[i].rs = node[i].me + node[i - 1].len + 1;
  47. node[i].rs = min(node[i].rs, INF);
  48. node[i].re = node[i].rs + 1;
  49. node[i].re = min(node[i].re, INF);
  50. node[i].len = node[i].re;
  51. }
  52. }
  53. char dfs(LL n, LL k) {
  54. if(n == 0) {
  55. if(k <= node[0].len) {
  56. return str0[k];
  57. }
  58. return '.';
  59. }
  60. if(k <= 34) {
  61. return strL[k];
  62. }
  63. if(k < node[n].ms) {
  64. return dfs(n - 1, k - 34);
  65. }
  66. if(k <= node[n].me) {
  67. return strM[k - node[n].ms + 1];
  68. }
  69. if(k < node[n].rs) {
  70. return dfs(n - 1, k - node[n].me);
  71. }
  72. if(k <= node[n].re) {
  73. return strR[k - node[n].rs + 1];
  74. }
  75. return '.';
  76. }
  77. int main() {
  78. #ifdef LOCAL
  79. freopen("test.txt", "r", stdin);
  80. // freopen("out.txt", "w", stdout);
  81. #endif // LOCAL
  82. // ios::sync_with_stdio(false);
  83. Init();
  84. while(scanf("%d", &T) != EOF) {
  85. while(T--) {
  86. scanf("%I64d%I64d", &n, &k);
  87. printf("%c", dfs(n, k));
  88. }
  89. printf("\n");
  90. }
  91. return 0;
  92. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注