A. Vus the Cossack and a Contest

签。

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. int main() {
  4. int n, m, k;
  5. while (scanf("%d%d%d", &n, &m, &k) != EOF) {
  6. if (min(m, k) >= n) {
  7. puts("YES");
  8. } else {
  9. puts("NO");
  10. }
  11. }
  12. return 0;
  13. }

C. Vus the Cossack and Strings

题意:

给出\(a, b\)两个01串,\(|a| \geq |b|\),询问\(a\)中所有长度等于\(|b|\)的子串和\(b\)异或之后\(1\)的个数为偶数的子串有多少个。

思路:

最自然的想法是枚举\(a\)中所有长度为\(|b|\)的子串。

其实最终我们不需要关心\(1\)的个数有多少个,只需要关心奇偶性。

那么我们暴力弄出第一个子串异或之后的\(1\)的个数模2的值。

再考虑,指针往右移动一位,会发生什么?

比如说

011000

00110

01100 -> 11000

会发生什么?

我们注意到,这个过程相当于将\(b\)串往右移动一位,

那么对于\(a\)串来说,是去掉第一个字符和增加最后一个字符,中间的字符不变。

那么对于中间的字符来说,它对应的\(b\)中的值是前一位之前对应的\(b\)中的值,那么你要继承它的状态。

那么如果你和前一位是相同的,那么前一位之前对应的\(b\)中的值移过来的时候不会改变答案的奇偶性。

否则会改变。

前缀异或一下即可。

代码:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define N 1000010
  4. char s[N], t[N];
  5. int main() {
  6. while (scanf("%s%s", s + 1, t + 1) != EOF) {
  7. int lens = strlen(s + 1), lent = strlen(t + 1);
  8. int res = 0, Xor = 0, tot = 0;
  9. for (int i = 1; i <= lent; ++i) {
  10. if (s[i] != t[i]) {
  11. tot ^= 1;
  12. }
  13. if (i > 1 && s[i] != s[i - 1]) Xor ^= 1;
  14. }
  15. res += tot ^ 1;
  16. for (int i = lent + 1; i <= lens; ++i) {
  17. if (s[i] != s[i - 1]) Xor ^= 1;
  18. int pre = i - lent;
  19. if (pre > 1 && s[pre] != s[pre - 1]) Xor ^= 1;
  20. tot ^= Xor;
  21. res += tot ^ 1;
  22. }
  23. printf("%d\n", res);
  24. }
  25. return 0;
  26. }

D. Vus the Cossack and Numbers

题意:

给出\(n\)个实数,他们的和为\(0\),现在要求将每个实数上取整或者下去整,使得它们的和还是为\(0\)。

思路:

先将所有数都下去整,然后看差多少,就补回来。

处理实数的时候用字符串,忘记考虑0和-0的问题FST了。

代码:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define ll long long
  4. #define N 100010
  5. int n;
  6. char s[110];
  7. int a[N], b[N], c[N];
  8. int main() {
  9. while (scanf("%d", &n) != EOF) {
  10. int can = 0;
  11. ll sum = 0;
  12. for (int i = 1; i <= n; ++i) {
  13. scanf("%s", s + 1);
  14. a[i] = 0, b[i] = 0;
  15. int j = 1, len = strlen(s + 1);
  16. int f = 1;
  17. if (s[1] == '-') ++j, f = -1;
  18. for (; j <= len && s[j] != '.'; ++j) {
  19. a[i] = a[i] * 10 + s[j] - '0';
  20. }
  21. for (++j; j <= len; ++j) {
  22. b[i] = b[i] * 10 + s[j] - '0';
  23. }
  24. a[i] *= f;
  25. if (b[i] != 0) {
  26. ++can;
  27. if (f == -1) {
  28. --a[i];
  29. }
  30. }
  31. sum += a[i];
  32. }
  33. sum = abs(sum);
  34. //assert(sum <= can);
  35. for (int i = 1; i <= n; ++i) {
  36. if (sum > 0 && b[i] != 0) {
  37. ++a[i];
  38. --sum;
  39. }
  40. }
  41. for (int i = 1; i <= n; ++i) {
  42. printf("%d\n", a[i]);
  43. }
  44. }
  45. return 0;
  46. }

F. Vus the Cossack and a Graph

题意:

有一张\(n\)个点,\(m\)条边的图。要求最多保留\(\left \lceil \frac{n + m}{2} \right \rceil\)条边,使得每个点的新的度数\(f_i \geq \left \lceil \frac{d_i}{2} \right \rceil\),其中\(d_i\)为原来的度数。

思路:

显然,可以理解为删去\(m - \left \lceil \frac{n + m}{2} \right\rceil\)条边,因为要保留尽量多的边没有坏处,

那么我们可以考虑每个点最多删去的度数为\(D_i = d_i - \left \lceil \frac{d_i}{2} \right \rceil\),那么我们优先删去\(D_i\)小的点邻接的\(D_i\)大的点的边。

因为这样贪心能够保证\(D_i\)小的点邻接的边能够被优先删除,否则这些\(D_i\)小的点邻接的边对应的那个点可能因为被删除了其它边,导致可用度数不够而这些边不能被删除。

而对于可用度数大的点来说,删去哪些边的影响不大。

而我们找到了一个\(D_i\)最小的点,那么要怎么去选择它邻接的边去删除呢?

要选择邻接的边对应的点的\(D_i\)大的删除。

因为如果选择\(D_i\)小的,那可能删完它们的\(D_i\)都变为0,不能删了。

但是可能存在这两个点都邻接一个\(D_i\)大的点,这样就可以删两条边,否则只能删一条边。

代码:

  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define N 1000010
  4. #define pii pair <int, int>
  5. #define fi first
  6. #define se second
  7. int n, m;
  8. int del[N];
  9. vector < vector <pii> > G;
  10. int d[N], a[N];
  11. int e[N][2];
  12. int main() {
  13. while (scanf("%d%d", &n, &m) != EOF) {
  14. memset(del, 0, sizeof del);
  15. memset(d, 0, sizeof d);
  16. G.clear();
  17. G.resize(n + 1);
  18. int needdel = m - (n + m + 1) / 2;
  19. for (int i = 1, u, v; i <= m; ++i) {
  20. scanf("%d%d", &e[i][0], &e[i][1]);
  21. u = e[i][0], v = e[i][1];
  22. G[u].push_back(pii(v, i));
  23. G[v].push_back(pii(u, i));
  24. ++d[u]; ++d[v];
  25. }
  26. if (needdel <= 0) {
  27. printf("%d\n", m);
  28. for (int i = 1; i <= m; ++i) {
  29. printf("%d %d\n", e[i][0], e[i][1]);
  30. }
  31. continue;
  32. }
  33. priority_queue <pii, vector <pii>, greater <pii> > pq;
  34. for (int i = 1; i <= n; ++i) {
  35. d[i] = d[i] - (d[i] + 1) / 2;
  36. pq.push(pii(d[i], i));
  37. }
  38. int u, v;
  39. while (needdel > 0) {
  40. u = 0;
  41. while (!pq.empty()) {
  42. u = pq.top().se; pq.pop();
  43. if (d[u] <= 0) {
  44. u = 0;
  45. continue;
  46. }
  47. else break;
  48. }
  49. if (u == 0) break;
  50. sort(G[u].begin(), G[u].end(), [](pii x, pii y) {
  51. return d[x.fi] > d[y.fi];
  52. });
  53. for (auto it : G[u]) {
  54. if (del[it.se]) continue;
  55. v = it.fi;
  56. if (d[v] <= 0) continue;
  57. del[it.se] = 1;
  58. --d[u]; --needdel;
  59. --d[v];
  60. if (d[v] > 0) {
  61. pq.push(pii(d[v], v));
  62. }
  63. if (d[u] <= 0 || needdel <= 0) break;
  64. }
  65. }
  66. int sze = (n + m + 1) / 2;
  67. printf("%d\n", sze);
  68. int cnt = 0;
  69. for (int i = 1; i <= m; ++i) {
  70. if (del[i] == 0) {
  71. ++cnt;
  72. printf("%d %d\n", e[i][0], e[i][1]);
  73. }
  74. }
  75. assert(sze == cnt);
  76. }
  77. return 0;
  78. }

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

  1. Codeforces Round #571 (Div. 2)-D. Vus the Cossack and Numbers

    Vus the Cossack has nn real numbers aiai. It is known that the sum of all numbers is equal to 00. He ...

  2. Vus the Cossack and Strings(Codeforces Round #571 (Div. 2))(大佬的位运算实在是太强了!)

    C. Vus the Cossack and Strings Vus the Cossack has two binary strings, that is, strings that consist ...

  3. 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 ...

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

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

  5. Codeforces Round #368 (Div. 2)

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

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

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

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

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

  8. Codeforces Round #262 (Div. 2) 1003

    Codeforces Round #262 (Div. 2) 1003 C. Present time limit per test 2 seconds memory limit per test 2 ...

  9. Codeforces Round #262 (Div. 2) 1004

    Codeforces Round #262 (Div. 2) 1004 D. Little Victor and Set time limit per test 1 second memory lim ...

随机推荐

  1. mybatis相关知识积累

    mybatis Statement Statement对象用于将 SQL 语句发送到数据库中. 实际上有三种 Statement 对象,它们都作为在给定连接上执行 SQL语句的包容器: Stateme ...

  2. Unity性能优化-DrawCall

    1. DrawCall是啥?其实就是对底层图形程序(比如:OpenGL ES)接口的调用,以在屏幕上画出东西.所以,是谁去调用这些接口呢?CPU.比如有上千个物体,每一个的渲染都需要去调用一次底层接口 ...

  3. 三种TCP协议聊天室实现

    一 概述 使用Java的IO实现聊天室 使用Java的NIO实现聊天室 使用Netty实现聊天室 二 IO聊天室 1 服务器 public class IOServer { public static ...

  4. win10下PLSQL Developer 连接ubuntu上安装的oracle 11g

    说明:过程记录的不是很相信,只记录基本步骤.并不适合想一步一步照做的同学. win10下需要的操作 1.微软官网下载instantclient,然后接到到本地一个文件夹,注意路径不要又空格,中文和括号 ...

  5. JS/js是什么?

    JavaScript 是一种专为与网页交互而设计的脚本语言,由下列三个不同的部分组成: ECMAScript,由 ECMA-262 定义,提供核心语言功能; 文档对象模型(DOM),提供访问和操作网页 ...

  6. Forms Process (FRMWEB) Consumes 100% of CPU in Oracle Applications R12 (文档 ID 745711.1)

    https://support.oracle.com/epmos/faces/DocumentDisplay?_afrLoop=283767243216583&id=745711.1& ...

  7. EventBus使用教程

    如图准备工作: 父子(子父)组件触发 EventBus.$emit('sub') EventBus.$on('sub',()=>{ console.log(1111222232211122) } ...

  8. python自定义小工具:密码匿名化、毫秒时间显示、人类易读字节

    import base64 import time def timestamp2datems(timestamp): ''' 时间戳转为日期字串,精确到ms.单位s :param timestamp: ...

  9. go语言的局部变量在堆上还是栈上?

    在讨论之前,先看如下代码: type treeNode struct { value int left, right *treeNode } func createNode(value int) *t ...

  10. win10开机后将存在多个系统选择,改为直接进入系统无需选择

    win10系统安装后,可能出现每次开机都要选择操作系统,比较麻烦,所以就来设置下如何直接进入系统,无须选择 1.我的电脑右键“属性”—“高级系统设置”—“系统属性” 2.设置“启动和故障恢复”如下 选 ...