A. Vus the Cossack and a Contest

签。

#include <bits/stdc++.h>
using namespace std; int main() {
int n, m, k;
while (scanf("%d%d%d", &n, &m, &k) != EOF) {
if (min(m, k) >= n) {
puts("YES");
} else {
puts("NO");
}
}
return 0;
}

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\)中的值移过来的时候不会改变答案的奇偶性。

否则会改变。

前缀异或一下即可。

代码:

#include <bits/stdc++.h>
using namespace std; #define N 1000010
char s[N], t[N]; int main() {
while (scanf("%s%s", s + 1, t + 1) != EOF) {
int lens = strlen(s + 1), lent = strlen(t + 1);
int res = 0, Xor = 0, tot = 0;
for (int i = 1; i <= lent; ++i) {
if (s[i] != t[i]) {
tot ^= 1;
}
if (i > 1 && s[i] != s[i - 1]) Xor ^= 1;
}
res += tot ^ 1;
for (int i = lent + 1; i <= lens; ++i) {
if (s[i] != s[i - 1]) Xor ^= 1;
int pre = i - lent;
if (pre > 1 && s[pre] != s[pre - 1]) Xor ^= 1;
tot ^= Xor;
res += tot ^ 1;
}
printf("%d\n", res);
}
return 0;
}

D. Vus the Cossack and Numbers

题意:

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

思路:

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

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

代码:

#include <bits/stdc++.h>
using namespace std; #define ll long long
#define N 100010
int n;
char s[110];
int a[N], b[N], c[N]; int main() {
while (scanf("%d", &n) != EOF) {
int can = 0;
ll sum = 0;
for (int i = 1; i <= n; ++i) {
scanf("%s", s + 1);
a[i] = 0, b[i] = 0;
int j = 1, len = strlen(s + 1);
int f = 1;
if (s[1] == '-') ++j, f = -1;
for (; j <= len && s[j] != '.'; ++j) {
a[i] = a[i] * 10 + s[j] - '0';
}
for (++j; j <= len; ++j) {
b[i] = b[i] * 10 + s[j] - '0';
}
a[i] *= f;
if (b[i] != 0) {
++can;
if (f == -1) {
--a[i];
}
}
sum += a[i];
}
sum = abs(sum);
//assert(sum <= can);
for (int i = 1; i <= n; ++i) {
if (sum > 0 && b[i] != 0) {
++a[i];
--sum;
}
}
for (int i = 1; i <= n; ++i) {
printf("%d\n", a[i]);
}
}
return 0;
}

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\)大的点,这样就可以删两条边,否则只能删一条边。

代码:

#include <bits/stdc++.h>
using namespace std; #define N 1000010
#define pii pair <int, int>
#define fi first
#define se second
int n, m;
int del[N];
vector < vector <pii> > G;
int d[N], a[N];
int e[N][2]; int main() {
while (scanf("%d%d", &n, &m) != EOF) {
memset(del, 0, sizeof del);
memset(d, 0, sizeof d);
G.clear();
G.resize(n + 1);
int needdel = m - (n + m + 1) / 2;
for (int i = 1, u, v; i <= m; ++i) {
scanf("%d%d", &e[i][0], &e[i][1]);
u = e[i][0], v = e[i][1];
G[u].push_back(pii(v, i));
G[v].push_back(pii(u, i));
++d[u]; ++d[v];
}
if (needdel <= 0) {
printf("%d\n", m);
for (int i = 1; i <= m; ++i) {
printf("%d %d\n", e[i][0], e[i][1]);
}
continue;
}
priority_queue <pii, vector <pii>, greater <pii> > pq;
for (int i = 1; i <= n; ++i) {
d[i] = d[i] - (d[i] + 1) / 2;
pq.push(pii(d[i], i));
}
int u, v;
while (needdel > 0) {
u = 0;
while (!pq.empty()) {
u = pq.top().se; pq.pop();
if (d[u] <= 0) {
u = 0;
continue;
}
else break;
}
if (u == 0) break;
sort(G[u].begin(), G[u].end(), [](pii x, pii y) {
return d[x.fi] > d[y.fi];
});
for (auto it : G[u]) {
if (del[it.se]) continue;
v = it.fi;
if (d[v] <= 0) continue;
del[it.se] = 1;
--d[u]; --needdel;
--d[v];
if (d[v] > 0) {
pq.push(pii(d[v], v));
}
if (d[u] <= 0 || needdel <= 0) break;
}
}
int sze = (n + m + 1) / 2;
printf("%d\n", sze);
int cnt = 0;
for (int i = 1; i <= m; ++i) {
if (del[i] == 0) {
++cnt;
printf("%d %d\n", e[i][0], e[i][1]);
}
}
assert(sze == cnt);
}
return 0;
}

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. C#类型转换工具类

    using System; namespace Com.AppCode.Extend { public static partial class Ext { #region 数值转换 /// < ...

  2. hdu 4333 扩展kmp+kmp重复字串去重

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4333 关于kmp next数组求最短重复字串问题请看:http://www.cnblogs.com/z ...

  3. Linux每隔1秒kill掉cpu大于50%的进程

    1.新建/test/killcpu.sh shell脚本 并授予权限0755#!/bin/bashps axf -o "pid %cpu" | awk '{if($2>=50 ...

  4. 有选择性的启用SAP UI5调试版本的源代码

    在低版本的SAP UI5应用中,我们一旦切换成调试模式,那么应用程序源代码和UI5框架程序的源代码的调试版本都会重新加载,耗时很长. 我最近发现UI5新版本1.66.1提供了选择性加载调试版本的源代码 ...

  5. redis集群安装2

      概要:本文主要介绍如何在Centos7中单机搭建redis集群三主三从,按照本文绝对可以实现该需求,至于先搭建单机版主要为了方便理解redis集群,为下一步开发或生产上redis集群做铺垫.同时本 ...

  6. django启动通过ip或是域名访问

    setting.py里面的ALLOWED_HOSTS = ['localhost','域名','本机ip'] 启动时一般都是命令行 python manage.py runserver [端口号]  ...

  7. 微软Surface低端版本将问世

    平板电脑现如今已走进千家万户,其触屏的操作相比笔记本电脑更加方便,屏幕也比手机大很多,是家用玩机的首选.虽然微软也在这一领域有所发力,推出了Surface这一产品,但其高昂的售价使得其在市场上的表现并 ...

  8. contos7下安装redis&redis的主从复制的配置&redis 哨兵(sentinel)

    一.centos7下安装redis 1.解压 redis-5.0.5.tar.gz 压缩文件 解压命令为: .tar.gz -C redis 解压后进入 redis 工作目录,进入 redis-5.0 ...

  9. PAT Basic 1045 快速排序 (25 分)

    著名的快速排序算法里有一个经典的划分过程:我们通常采用某种方法取一个元素作为主元,通过交换,把比主元小的元素放到它的左边,比主元大的元素放到它的右边. 给定划分后的 N 个互不相同的正整数的排列,请问 ...

  10. 用js刷剑指offer(二维数组中的查找)

    题目描述 在一个二维数组中(每个一维数组的长度相同),每一行都按照从左到右递增的顺序排序,每一列都按照从上到下递增的顺序排序.请完成一个函数,输入这样的一个二维数组和一个整数,判断数组中是否含有该整数 ...