[关闭]
@Dmaxiya 2020-12-12T07:26:27.000000Z 字数 6253 阅读 1659

Codeforces Round #439 (Div. 2)

Codeforces


Contests 链接:Codeforces Round #439 (Div. 2)
过题数:3
排名:623/10987

A. The Artful Expedient

题意

和 两个人分别列出 个数字 和 ,其中对于任意 有 ,问对于这个数组中有多少个 对,使得 的值等于这两个序列当中的某一个数字,如果答案为偶数,则 获胜,否则 获胜。

输入

第一行为一个整数 ,第二行为 个互不相等的整数 ,表示 给出的 个数字,第三行为 个互不相等的整数 表示 给出的 个数字,其中

输出

输出获胜者的名字。

样例

输入 输出 提示
3
1 2 3
4 5 6
Karen 有 对整数满足条件: ,而 是一个偶数,所以 获胜。
5
2 4 6 8 10
9 7 5 3 1
Karen 总共有 对整数满足条件,所以获胜者仍然是 。

题解

把所有数字放到 中,然后 枚举所有的数对 。

过题代码

  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 <vector>
  10. #include <list>
  11. #include <queue>
  12. #include <stack>
  13. #include <map>
  14. #include <set>
  15. #include <bitset>
  16. #include <algorithm>
  17. #include <ctime>
  18. #include <functional>
  19. #include <iomanip>
  20. using namespace std;
  21. #define LL long long
  22. const int maxn = 2000 + 100;
  23. int n;
  24. int a[maxn], b[maxn];
  25. set<int> st;
  26. int main() {
  27. #ifdef LOCAL
  28. freopen("test.txt", "r", stdin);
  29. // freopen("out.txt", "w", stdout);
  30. #endif
  31. ios::sync_with_stdio(false);
  32. scanf("%d", &n);
  33. for(int i = 1; i <= n; ++i) {
  34. scanf("%d", &a[i]);
  35. st.insert(a[i]);
  36. }
  37. for(int i = 1; i <= n; ++i) {
  38. scanf("%d", &b[i]);
  39. st.insert(b[i]);
  40. }
  41. int ans = 0;
  42. for(int i = 1; i <= n; ++i) {
  43. for(int j = 1; j <= n; ++j) {
  44. int Xor = a[i] ^ b[j];
  45. if(st.find(Xor) != st.end()) {
  46. ++ans;
  47. }
  48. }
  49. }
  50. if(ans % 2 == 0) {
  51. printf("Karen\n");
  52. } else {
  53. printf("Koyomi\n");
  54. }
  55. return 0;
  56. }

B. The Eternal Immortality

题意

计算 的个位数,其中 ,且 。

输入

输入只包含两个整数 和 。

输出

输出 的个位数。

样例

输入 输出 提示
2 4 2 ,个位数字是 。
0 10 0 ,个位数是 。
107 109 2 ,个位数字是 。

题解

阶乘的个位经常是 ,可以发现,只要 和 之间的距离超过 , 的个位就是 (因为含有因子 和 )。

过题代码

  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 <vector>
  10. #include <list>
  11. #include <queue>
  12. #include <stack>
  13. #include <map>
  14. #include <set>
  15. #include <bitset>
  16. #include <algorithm>
  17. #include <ctime>
  18. #include <functional>
  19. #include <iomanip>
  20. using namespace std;
  21. #define LL long long
  22. LL a, b;
  23. int main() {
  24. #ifdef LOCAL
  25. freopen("test.txt", "r", stdin);
  26. // freopen("out.txt", "w", stdout);
  27. #endif
  28. ios::sync_with_stdio(false);
  29. scanf("%I64d%I64d", &a, &b);
  30. if(b - a > 5) {
  31. printf("0\n");
  32. } else {
  33. LL ans = 1;
  34. for(LL i = a + 1; i <= b; ++i) {
  35. ans *= i;
  36. ans %= 10;
  37. }
  38. printf("%I64d\n", ans);
  39. }
  40. return 0;
  41. }

C. The Intriguing Obsession

题意

有红、蓝、紫三种颜色的岛屿,岛屿数量分别为 ,要在岛屿之间建桥,每座桥的长度都为 ,问要使所有岛屿满足以下条件,总共有多少种桥的建法:

  1. 同一种颜色的任意两座岛屿之间的距离至少为 ;
  2. 每个岛屿的度最大为 。

输入

输入包含三个整数 ,分别表示三种颜色的岛屿的数量。

输出

输出合法的建桥的方案数对 取模后的结果。

样例

输入 输出 提示
1 1 1 8 能在三个岛屿之间建立的桥有三个,且即使三座桥同时建立也是合法的,所以总共的合法的
方案数为 。
1 2 2 63 对于 的情况,下图中上面的两幅图是合法的建桥方案,下面的两幅图
不是合法的建桥方案:

rV2EGT.png
1 3 5 3264
6 2 9 813023575

题解

通过画样例可以发现,每座岛屿连出的两条边(桥)只能通向另外两种颜色的岛屿,对于任意两种颜色的岛屿 ,它们之间能连的边的数量为 ,可以从 中选出 个点与另一种颜色的 个点中的 连边,左右两边的点一一对应,总共有 种对应方式,所以方案数为 。

过题代码

  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 <vector>
  10. #include <list>
  11. #include <queue>
  12. #include <stack>
  13. #include <map>
  14. #include <set>
  15. #include <bitset>
  16. #include <algorithm>
  17. #include <ctime>
  18. #include <functional>
  19. #include <iomanip>
  20. using namespace std;
  21. #define LL long long
  22. const int maxn = 5000 + 100;
  23. const LL MOD = 998244353LL;
  24. int a, b, c;
  25. LL ans;
  26. LL C[maxn][maxn];
  27. LL fac[maxn];
  28. void Init() {
  29. C[0][0] = 1;
  30. for(int i = 1; i <= 5000; ++i) {
  31. for(int j = 0; j <= i; ++j) {
  32. if(j == 0 || j == i) {
  33. C[i][j] = 1;
  34. } else {
  35. C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]) % MOD;
  36. }
  37. }
  38. }
  39. fac[0] = 1;
  40. for(int i = 1; i <= 5000; ++i) {
  41. fac[i] = (fac[i - 1] * i) % MOD;
  42. }
  43. }
  44. LL solve(int a, int b) {
  45. int Min = min(a, b);
  46. LL ret = 0;
  47. for(int i = 0; i <= Min; ++i) {
  48. ret = (ret + (((C[a][i] * C[b][i]) % MOD) * fac[i]) % MOD) % MOD;
  49. }
  50. return ret;
  51. }
  52. int main() {
  53. #ifdef LOCAL
  54. freopen("test.txt", "r", stdin);
  55. // freopen("out.txt", "w", stdout);
  56. #endif
  57. ios::sync_with_stdio(false);
  58. Init();
  59. scanf("%d%d%d", &a, &b, &c);
  60. ans = solve(a, b);
  61. ans = (ans * solve(b, c)) % MOD;
  62. ans = (ans * solve(a, c)) % MOD;
  63. printf("%I64d\n", ans);
  64. return 0;
  65. }

E. The Untended Antiquity

题意

在一个 的网格上,进行 次操作:

  1. :以在位置 和 上的两个方格为矩形的两个对角,画出矩形的边框,在矩形的边框上设置一圈障碍物;
  2. :以在位置 和 上的两个方格为矩形的两个对角,消去在这个矩形边框上的障碍物;
  3. :询问能否从位置 不穿过障碍地到达位置 。

输入

第一行为三个整数 ,接下去 行每行 个整数 ,表示每次操作的方式与对应的坐标,其中 ,且

  1. 当 时,,数据保证每个矩形的边框不会出现相交、重叠的情况;
  2. 当 时,,数据保证每一个 中的坐标一定在之前的 中出现过;
  3. 当 时,没有额外的限制。

输出

对于每次 的询问,如果可以不穿过障地从 到达 ,就输出 ,否则输出 。

样例

输入 输出 提示
5 6 5
1 2 2 4 5
1 3 3 3 3
3 4 4 1 1
2 2 2 4 5
3 1 1 4 4
No
Yes
两次询问时的示意图如下:
2500 2500 8
1 549 1279 1263 2189
1 303 795 1888 2432
1 2227 622 2418 1161
3 771 2492 1335 1433
1 2017 2100 2408 2160
3 48 60 798 729
1 347 708 1868 792
3 1940 2080 377 1546
No
Yes
No

题解

先考虑一个更简单些的问题,如果每次操作 是将矩形区域上的所有数字都 ,每次操作 是 ,而操作 是询问两点上的值是否相等,就是一个二维树状数组的问题。现在再来思考这个问题,这两个问题其实是相似的,在题给问题中,对每个矩形编号,添加某个矩形的边框时将矩形区域内的数字都加上这个矩形的编号,删除某个矩形的边框时将矩形区域内的数字都减去这个矩形的编号。我们无法设计出一个编号方式使得对所有的矩形编号都不出现 ,只要出现这种情况,就会发生冲突,造成判断的结果出错,但是我们可以用随机编号的方式将这些编号求和出现冲突的概率降低,对每个新的矩形,将其编号为 ,就可以将冲突的概率降低到 。

过题代码

  1. #include <iostream>
  2. #include <cstdio>
  3. #include <cstdlib>
  4. #include <cmath>
  5. #include <sstream>
  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 <algorithm>
  15. #include <ctime>
  16. using namespace std;
  17. #define LL long long
  18. const int maxn = 2500 + 100;
  19. int n, m, q, t, r1, r2, c1, c2;
  20. int sum[maxn][maxn], num[maxn][maxn];
  21. int lowbit(int x) {
  22. return x & (-x);
  23. }
  24. void update(int i, int j, int x) {
  25. while(i <= n) {
  26. int jj = j;
  27. while(jj <= m) {
  28. sum[i][jj] += x;
  29. jj += lowbit(jj);
  30. }
  31. i += lowbit(i);
  32. }
  33. }
  34. int query(int i, int j) {
  35. int ret = 0;
  36. while(i > 0) {
  37. int jj = j;
  38. while(jj > 0) {
  39. ret += sum[i][jj];
  40. jj -= lowbit(jj);
  41. }
  42. i -= lowbit(i);
  43. }
  44. return ret;
  45. }
  46. int main() {
  47. #ifdef Dmaxiya
  48. freopen("test.txt", "r", stdin);
  49. #endif // Dmaxiya
  50. ios::sync_with_stdio(false);
  51. srand((unsigned)time(NULL));
  52. while(scanf("%d%d%d", &n, &m, &q) != EOF) {
  53. memset(sum, 0, sizeof(sum));
  54. for(int i = 0; i < q; ++i) {
  55. scanf("%d%d%d%d%d", &t, &r1, &c1, &r2, &c2);
  56. int x;
  57. if(t == 1) {
  58. x = rand() * rand();
  59. num[r1][c1] = x;
  60. } else if(t == 2) {
  61. x = -num[r1][c1];
  62. }
  63. if(t != 3) {
  64. update(r1, c1, x);
  65. update(r1, c2 + 1, -x);
  66. update(r2 + 1, c1, -x);
  67. update(r2 + 1, c2 + 1, x);
  68. } else {
  69. int tmp1 = query(r1, c1);
  70. int tmp2 = query(r2, c2);
  71. if(tmp1 == tmp2) {
  72. printf("Yes\n");
  73. } else {
  74. printf("No\n");
  75. }
  76. }
  77. }
  78. }
  79. return 0;
  80. }
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注