[关闭]
@Dmaxiya 2018-08-17T02:14:14.000000Z 字数 3948 阅读 824

Codeforces Round #480 (Div. 2)

Codeforces


Contests 链接:Codeforces Round #480 (Div. 2)
过题数:3
排名:804/9913

题意

给定一个只包含 -o 的字符串,- 表示项链上的链,o 表示项链上的珍珠,将字符串首尾相连表示一条项链,每次操作可以将任意位置的链或珍珠拆下,插入到另一个位置上,问进行任意多次操作后,能否使得项链上任意两个相邻的珍珠之间的链的数量相等。

输入

输入为一个字符串 ,字符串只包含字符 -o

输出

如果可以,则输出 ,否则输出 ,大小写任意。

样例

输入
-o-o--
输出
YES
输入
-o---
输出
YES
输入
-o---o-
输出
NO
输入
ooo
输出
YES

题解

计算项链上 o 的数量 - 的数量 ,满足 的倍数或者 的数量为 ,就输出 ,否则输出

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cstring>
  7. #include <string>
  8. #include <vector>
  9. #include <list>
  10. #include <queue>
  11. #include <stack>
  12. #include <map>
  13. #include <set>
  14. #include <functional>
  15. #include <algorithm>
  16. using namespace std;
  17. #define LL long long
  18. const int maxn = 100 + 100;
  19. int cnt1, cnt2;
  20. char str[maxn];
  21. int main() {
  22. #ifdef LOCAL
  23. freopen("test.txt", "r", stdin);
  24. // freopen("testout.txt", "w", stdout);
  25. #endif // LOCAL
  26. ios::sync_with_stdio(false);
  27. while(scanf("%s", str) != EOF) {
  28. cnt1 = cnt2 = 0;
  29. for(int i = 0; str[i]; ++i) {
  30. if(str[i] == 'o') {
  31. ++cnt1;
  32. } else {
  33. ++cnt2;
  34. }
  35. }
  36. if(cnt1 == 0) {
  37. printf("YES\n");
  38. continue;
  39. }
  40. if(cnt2 % cnt1 == 0) {
  41. printf("YES\n");
  42. } else {
  43. printf("NO\n");
  44. }
  45. }
  46. return 0;
  47. }

B. Marlin

题意

在一个 为奇数)的网格中,需要设置 个障碍,这 个障碍不能设置在网格的边界上,要求从 到达 的最短路径数量等于从 的最短路径数量,两个方格之间的路径长度为 ,当且仅当这两个方格有公共边。

输入

输入只包含两个整数 ,数据保证 为奇数。

输出

如果可以达到要求,第一行输出 ,接下去 行每行 个字符,字符只能包含 .#,其中 . 表示空地,# 表示障碍物。

样例

输入
7 2
输出
YES
.......
.#.....
.#.....
.......
输入
5 3
输出
YES
.....
.###.
.....
.....

题解

对于 为偶数的情况,只需要上下对称分布,对于奇数的情况,以下枚举了 时, 等于 的构造方案:
..... ..... .....
..#.. .###. .###.
..... ..... .#.#.
..... ..... .....
不存在无法构造的情况。

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cstring>
  7. #include <string>
  8. #include <vector>
  9. #include <list>
  10. #include <queue>
  11. #include <stack>
  12. #include <map>
  13. #include <set>
  14. #include <functional>
  15. #include <algorithm>
  16. using namespace std;
  17. #define LL long long
  18. const int maxn = 100 + 100;
  19. int n, k;
  20. char ans[maxn][maxn];
  21. int main() {
  22. #ifdef LOCAL
  23. freopen("test.txt", "r", stdin);
  24. // freopen("testout.txt", "w", stdout);
  25. #endif // LOCAL
  26. ios::sync_with_stdio(false);
  27. while(scanf("%d%d", &n, &k) != EOF) {
  28. for(int i = 1; i <= 4; ++i) {
  29. for(int j = 1; j <= n; ++j) {
  30. ans[i][j] = '.';
  31. }
  32. }
  33. if(k % 2 == 0) {
  34. for(int j = 2; j < k / 2 + 2; ++j) {
  35. for(int i = 2; i <= 3; ++i) {
  36. ans[i][j] = '#';
  37. }
  38. }
  39. } else {
  40. int up = min(n - 2, k);
  41. int mid = n / 2 + 1;
  42. for(int i = 0; i <= up / 2; ++i) {
  43. ans[2][mid + i] = '#';
  44. ans[2][mid - i] = '#';
  45. }
  46. up = max(k - (n - 2), 0);
  47. for(int i = 0; i < up / 2; ++i) {
  48. ans[3][2 + i] = '#';
  49. ans[3][n - 1 - i] = '#';
  50. }
  51. }
  52. printf("YES\n");
  53. for(int i = 1; i <= 4; ++i) {
  54. for(int j = 1; j <= n; ++j) {
  55. printf("%c", ans[i][j]);
  56. }
  57. printf("\n");
  58. }
  59. }
  60. return 0;
  61. }

C. Posterized

题意

给出 个整数和一个阈值 ,所有整数都在 的范围内,要求将所有整数分到一个不阈值大于 的区间内,并从这个阈值内选出一个数字代表这个阈值中的所有数字, 内每个整数都只能属于一个阈值,问将 个整数都用所属阈值的代表数字替换后,字典序最小的结果。

输入

第一行为两个整数 ,第二行为 个整数

输出

输出字典序最小的结果。

样例

输入
4 3
2 14 3 4
输出
0 12 3 3
提示
属于 ,代表数字为 属于 ,代表数字为 属于 ,代表数字为 ,即得到最小字典序结果。
输入
5 2
0 2 1 255 254
输出
0 1 1 254 254

题解

最初每个数字都属于自身阈值(长度为 ),从前往后,每碰到一个数字,先检查这个数字是否已经属于某一个阈值,如果已经属于,则只能用该阈值的代表数字替换,否则往前找 个数字,保证前 个数字都没有属于某阈值的情况下,贪心地找到最小的能代表的数字,将这一段的代表数字同设置为该数字,一直往后。

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <climits>
  6. #include <cstring>
  7. #include <string>
  8. #include <vector>
  9. #include <list>
  10. #include <queue>
  11. #include <stack>
  12. #include <map>
  13. #include <set>
  14. #include <functional>
  15. #include <algorithm>
  16. using namespace std;
  17. #define LL long long
  18. const int maxn = 100000 + 100;
  19. int n, k;
  20. int num[maxn];
  21. int head[1000];
  22. int Find(int x) {
  23. int ret = x;
  24. int kk = k;
  25. while(ret != 0) {
  26. --ret;
  27. --kk;
  28. if(head[ret] != -1) {
  29. ++ret;
  30. break;
  31. }
  32. if(kk == 0) {
  33. ++ret;
  34. break;
  35. }
  36. }
  37. if(ret == 0) {
  38. return ret;
  39. }
  40. if(x - head[ret - 1] + 1 <= k) {
  41. return head[ret - 1];
  42. } else {
  43. return ret;
  44. }
  45. }
  46. int main() {
  47. #ifdef LOCAL
  48. freopen("test.txt", "r", stdin);
  49. // freopen("testout.txt", "w", stdout);
  50. #endif // LOCAL
  51. ios::sync_with_stdio(false);
  52. while(scanf("%d%d", &n, &k) != EOF) {
  53. memset(head, -1, sizeof(head));
  54. for(int i = 1; i <= n; ++i) {
  55. scanf("%d", &num[i]);
  56. if(head[num[i]] != -1) {
  57. continue;
  58. }
  59. int Index = Find(num[i]);
  60. for(int j = Index; j <= num[i]; ++j) {
  61. head[j] = Index;
  62. }
  63. }
  64. for(int i = 1; i <= n; ++i) {
  65. if(i != 1) {
  66. printf(" ");
  67. }
  68. printf("%d", head[num[i]]);
  69. }
  70. printf("\n");
  71. }
  72. return 0;
  73. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注