传送门

A. Stones

签到。

B. Alice and the List of Presents

单独考虑每个数的贡献即可。

答案为\((2^{m}-1)^n\)。

C. Labs

构造就类似于:

1 6 7

2 5 8

3 4 9

这样就行了。

证明我也不会,但感觉这样能使得每一行都较为均衡。

Code
  1. #include <bits/stdc++.h>
  2. #define MP make_pair
  3. #define fi first
  4. #define se second
  5. #define sz(x) (int)(x).size()
  6. #define all(x) (x).begin(), (x).end()
  7. // #define Local
  8. using namespace std;
  9. typedef long long ll;
  10. typedef pair<int, int> pii;
  11. const int N = 305;
  12. int n;
  13. int mp[N][N];
  14. void run() {
  15. cin >> n;
  16. for(int j = 1; j <= n; j++) {
  17. int st = (j - 1) * n + 1;
  18. if(j & 1) {
  19. for(int i = n; i >= 1; i--, st++) {
  20. mp[i][j] = st;
  21. }
  22. } else {
  23. for(int i = 1; i <= n; i++, st++) {
  24. mp[i][j] = st;
  25. }
  26. }
  27. }
  28. for(int i = 1; i <= n; i++) {
  29. for(int j = 1; j <= n; j++) {
  30. cout << mp[i][j] << " \n"[j == n];
  31. }
  32. }
  33. }
  34. int main() {
  35. ios::sync_with_stdio(false);
  36. cin.tie(0); cout.tie(0);
  37. cout << fixed << setprecision(20);
  38. #ifdef Local
  39. freopen("../input.in", "r", stdin);
  40. freopen("../output.out", "w", stdout);
  41. #endif
  42. while(cin >> n) run();
  43. return 0;
  44. }

D. Alice and the Doll

题意:

给出一个\(n\cdot m,n,m\leq 10^5\)大小的网格图,上面有些位置可能有障碍。

现在要求,每个格子只能经过一次,并且在每个格子有两个选择:直走或者右转。初始位于\((1,1)\)位置,方向为向右。

问能否走遍所有非障碍的点。

思路:

把题读成一个位置可以经过多次,但只能右转一次,想了一小时假题

因为只能经过一次,那么我们路线肯定是“回路”型的,并且肯定是贪心地走。

那么我们每行每列存障碍,然后模拟这个过程就行。

代码中用了一个矩形表示当前范围。注意每次删障碍时肯定要删除一个矩形,矩形内如果有空地那就不合法,因为不可能再走过去了。

注意矩形范围的更新。

细节见代码:

Code
  1. #include <bits/stdc++.h>
  2. #define MP make_pair
  3. #define fi first
  4. #define se second
  5. #define sz(x) (int)(x).size()
  6. #define all(x) (x).begin(), (x).end()
  7. // #define Local
  8. using namespace std;
  9. typedef long long ll;
  10. typedef pair<int, int> pii;
  11. const int N = 1e5 + 5;
  12. int n, m, k;
  13. set <int> col[N], row[N];
  14. bool del(int up, int down, int left, int right) {
  15. for(int i = up; i <= down; i++) {
  16. for(int j = left; j <= right; j++) {
  17. if(row[i].find(j) == row[i].end()) return false;
  18. row[i].erase(j);
  19. col[j].erase(i);
  20. --k;
  21. }
  22. }
  23. return true;
  24. }
  25. void run() {
  26. for(int i = 1; i <= k; i++) {
  27. int x, y; cin >> x >> y;
  28. col[y].insert(x);
  29. row[x].insert(y);
  30. }
  31. int dir = 0;
  32. int up = 1, down = n, left = 1, right = m;
  33. int D = 0;
  34. int x = 1, y = 1;
  35. while(k) {
  36. if(dir == 0) {
  37. auto it = row[x].begin();
  38. if(it == row[x].end()) {
  39. y = right;
  40. } else {
  41. int p = *it;
  42. if(!del(up, down, p, right)) {
  43. cout << "No";
  44. return;
  45. }
  46. right = y = p - 1;
  47. }
  48. left += D;
  49. } else if(dir == 1) {
  50. auto it = col[y].begin();
  51. if(it == col[y].end()) {
  52. x = down;
  53. } else {
  54. int p = *it;
  55. if(!del(p, down, left, right)) {
  56. cout << "No";
  57. return;
  58. }
  59. down = x = p - 1;
  60. }
  61. up += D;
  62. } else if(dir == 2) {
  63. auto it = row[x].rbegin();
  64. if(it == row[x].rend()) {
  65. y = left;
  66. } else {
  67. int p = *it;
  68. if(!del(up, down, left, p)) {
  69. cout << "No";
  70. return;
  71. }
  72. left = y = p + 1;
  73. }
  74. right -= D;
  75. } else {
  76. auto it = col[y].rbegin();
  77. if(it == col[y].rend()) {
  78. x = up;
  79. } else {
  80. int p = *it;
  81. if(!del(up, p, left, right)) {
  82. cout << "No" << '\n';
  83. return;
  84. }
  85. up = x = p + 1;
  86. }
  87. down -= D;
  88. }
  89. dir = (dir + 1) % 4;
  90. D = 1;
  91. // cout << up << ' ' << down << ' ' << left << ' ' << right << '\n';
  92. }
  93. cout << "Yes" << '\n';
  94. }
  95. int main() {
  96. ios::sync_with_stdio(false);
  97. cin.tie(0); cout.tie(0);
  98. cout << fixed << setprecision(20);
  99. #ifdef Local
  100. freopen("../input.in", "r", stdin);
  101. freopen("../output.out", "w", stdout);
  102. #endif
  103. while(cin >> n >> m >> k) run();
  104. return 0;
  105. }

E. Alice and the Unfair Game

题意:

现有\(n\)个方格排成一列,同时给出一个序列\(a\),\(a_i\)表示第\(i\)次时敲打\(a_i\)这个方格。

现有个玩偶在这个方格上面走,每次敲打后可以向相邻方格走一步或者留在原地。并规定一开始可以移动一步。

问存在多少对\((x,y)\),表示玩偶一开始在\(x\),最后在\(y\)位置,并且中间不会被敲打。

思路:

有一个观察:

  • 对于一个点\(x\),若其最远向右能走到\(y\),那么最终走到\(x\)~\(y\)之间的方格都为合法答案。
  • 向左延申同理。
感性证明

证明的话可以感性理解一下,因为在一个时间点只能敲打一次,倒过来考虑,因为最后能够停留在$y$,假设我们是从$y-1$走过来,那么必然最后一次不会敲打$y-1$这个位置,那直接停在这个位置即可;如果我们一直卡在$y$,那也是可以往前走的。

 

所以现在问题的关键就是对于每个位置,如何快速找到向左、向右延申的最远位置。

因为这个题跟时间有很大关系,所以我们考虑用二维坐标\((x,y)\)表示在\(x\)时刻位于第\(y\)个方格。那么敲打点就相当于二维平面上的一个障碍。

问题就变为:我们从\((0,y)\)出发,每次可以向上、向右、向下走一步,不能经过障碍,能走到的最上/最下的位置是多少。

以最大举例:我们采用贪心的策略,用vector存储同一斜率上的所有障碍点,然后二分找到障碍点位置\((x_i,y_i)\),那我们只能走到\((x_i,y_i-1)\);之后快速找到下一个\(y_j\not ={y_i}\)的时间点(预处理下一个位置),走过去即可。

详细细节见代码:

Code
  1. #include <bits/stdc++.h>
  2. #define MP make_pair
  3. #define fi first
  4. #define se second
  5. #define sz(x) (int)(x).size()
  6. #define all(x) (x).begin(), (x).end()
  7. // #define Local
  8. using namespace std;
  9. typedef long long ll;
  10. typedef pair<int, int> pii;
  11. const int N = 2e5 + 5, base = 1e5;
  12. int n, m;
  13. int a[N], nxt[N];
  14. vector<int> v1[N], v2[N];
  15. int Max[N], Min[N];
  16. void run() {
  17. for(int i = 1; i < N; i++) v1[i].clear(), v2[i].clear();
  18. for(int i = 1; i <= m; i++) {
  19. int x; cin >> x;
  20. v1[i - x + base].push_back(i);
  21. v2[i + x].push_back(i);
  22. a[i] = x;
  23. }
  24. if(n == 1 && *max_element(a + 1, a + m + 1) == 1) {
  25. cout << 0 << '\n';
  26. return;
  27. }
  28. nxt[m] = m + 1;
  29. for(int i = m - 1; i >= 1; i--) {
  30. if(a[i] == a[i + 1]) nxt[i] = nxt[i + 1];
  31. else nxt[i] = i + 1;
  32. }
  33. for(int i = 1; i <= n; i++) {
  34. int x = 0, y = i;
  35. while(1) {
  36. int k = x - y + base;
  37. auto it = lower_bound(v1[k].begin(), v1[k].end(), x + 1);
  38. if(it == v1[k].end()) {
  39. y += m + 1 - x;
  40. break;
  41. }
  42. int p = it - v1[k].begin();
  43. p = v1[k][p];
  44. x = nxt[p] - 1, y = a[p] - 1;
  45. }
  46. Max[i] = min(y, n);
  47. }
  48. for(int i = 1; i <= n; i++) {
  49. int x = 0, y = i;
  50. while(1) {
  51. int k = x + y;
  52. auto it = lower_bound(v2[k].begin(), v2[k].end(), x + 1);
  53. if(it == v2[k].end()) {
  54. y -= m + 1 - x;
  55. break;
  56. }
  57. int p = it - v2[k].begin();
  58. p = v2[k][p];
  59. x = nxt[p] - 1, y = a[p] + 1;
  60. }
  61. Min[i] = max(1, y);
  62. }
  63. ll ans = 0;
  64. for(int i = 1; i <= n; i++) {
  65. ans += (Max[i] - Min[i] + 1);
  66. }
  67. cout << ans << '\n';
  68. }
  69. int main() {
  70. ios::sync_with_stdio(false);
  71. cin.tie(0); cout.tie(0);
  72. cout << fixed << setprecision(20);
  73. #ifdef Local
  74. freopen("../input.in", "r", stdin);
  75. freopen("../output.out", "w", stdout);
  76. #endif
  77. while(cin >> n >> m) run();
  78. return 0;
  79. }

注意一下,当\(n>1\)时,每个位置肯定至少存在一个解。但是当\(n=1\)时,因为没有周转的地方,所以可能没有解,所以我们需要特判一下。

Codeforces Round #593 (Div. 2)的更多相关文章

  1. Codeforces Round #593 (Div. 2) D. Alice and the Doll

    题目:http://codeforces.com/problemset/problem/1236/D思路:机器人只能按照→↓←↑这个规律移动,所以在当前方向能够前进的最远处即为界限,到达最远处右转,并 ...

  2. Codeforces Round #593 (Div. 2) C. Labs A. Stones

    题目:https://codeforces.com/contest/1236/problem/A 思路:两种操作收益都是3 且都会消耗b 操作2对b消耗较小 则可优先选择操作2 再进行操作1 即可得到 ...

  3. Codeforces Round #593 (Div. 2) C. Labs

    题目:https://codeforces.com/contest/1236/problem/C 思路:将 n ^ 2 个 lab 平分为 n 个 group group A 和 B 组成的 有序对 ...

  4. Codeforces Round #593 (Div. 2)D(螺旋形模拟)

    #define HAVE_STRUCT_TIMESPEC#include<bits/stdc++.h>using namespace std;vector<int>po[100 ...

  5. Codeforces Round #366 (Div. 2) ABC

    Codeforces Round #366 (Div. 2) A I hate that I love that I hate it水题 #I hate that I love that I hate ...

  6. Codeforces Round #354 (Div. 2) ABCD

    Codeforces Round #354 (Div. 2) Problems     # Name     A Nicholas and Permutation standard input/out ...

  7. Codeforces Round #368 (Div. 2)

    直达–>Codeforces Round #368 (Div. 2) A Brain’s Photos 给你一个NxM的矩阵,一个字母代表一种颜色,如果有”C”,”M”,”Y”三种中任意一种就输 ...

  8. cf之路,1,Codeforces Round #345 (Div. 2)

     cf之路,1,Codeforces Round #345 (Div. 2) ps:昨天第一次参加cf比赛,比赛之前为了熟悉下cf比赛题目的难度.所以做了round#345连试试水的深浅.....   ...

  9. Codeforces Round #279 (Div. 2) ABCDE

    Codeforces Round #279 (Div. 2) 做得我都变绿了! Problems     # Name     A Team Olympiad standard input/outpu ...

随机推荐

  1. Azure上的时序见解,Time series insights

    5G来了,广连接(mmTC)可以实现每平方千米100万的连接数(理论值),是4G的10倍,5G网络出现,配合其他技术,空间将在数据意义上剧烈压缩,车联网.智能家居.智能安防.智慧工厂.智慧能源都可能带 ...

  2. CSS(2)---css字体、文本样式属性

    css字体.文本样式属性 这篇主要讲CSS文本属性中的:字体样式属性 和 文本样式属性. 一.字体样式属性 CSS 字体属性主要包括:字体设置(font-family).字号大小(font-size) ...

  3. WPF 3D Cube及点击交互

    在WPF中构建一个简单的立方体比较容易实现,可参考资料也比较众多.比较麻烦的是处理点击交互. 我在WPF中用两种方式实现了3DCube,效果图如下: 方式一: 最常见的3D内容构建模式,结构如下图. ...

  4. FCC---CSS Flexbox: Add Flex Superpowers to the Tweet Embed

    To the right is the tweet embed that will be used as the practical example. Some of the elements wou ...

  5. ES6-WeakSet数组结构

    WeakSet 也会去重 总结: 1.成员都是对象: 2.成员都是弱引用,可以被垃圾回收机制回收,可以用来保存 DOM 节点,不容易造成内存泄漏: 3.不能遍历,方法有 add.delete.has. ...

  6. IS Kali: installed chiess messy code problem

    apt-get install ttf-wqy-microhei ttf-wqy-zenhei xfonts-wqy init 6

  7. 华为2019年NE40E-X8,承诺命令

    commit每敲一行命令,都得确认一下.以防误操作.

  8. 如何在Oracle 12C中Drop/Truncate多个分区 (Doc ID 1482264.1)

    How to Drop/Truncate Multiple Partitions in Oracle 12C (Doc ID 1482264.1) APPLIES TO: Oracle Databas ...

  9. 13. java String类

    一.字符串类 /* java.lang.String类代表字符串 程序中所有的双引号字符串,都是String类的对象.就算没有new 字符串中的内容,永不变:不可变 字符串效果上相当于是char[]字 ...

  10. openpyxl基本操作

    参考资料:OpenPyXL的使用教程(一) openpyxl 基本操作 # 创建xml from openpyxl import Workbook # 创建工作簿 wb = Workbook() # ...