Codeforces Round #683 (Div. 2, by Meet IT)
A
初始情况\(1\) ~ \(n\)堆分别有 \(1\) ~ \(n\) 个糖果,第\(i\)次操作给除了所选堆的糖果数 \(+ i\), 找到一种方案可以使得所有堆糖果数相同,输出操作次数和每次选定不变的堆.
选定当前堆不变,其他堆\(+ i\)等价于将选定堆\(-i\), 故只需要考虑如何将所有堆减到\(0\)即可, 即操作\(n\)次,第\(i\)次选择第\(i\)堆.
#include <bits/stdc++.h>
using namespace std;
int main()
{
int T;
scanf("%d", &T);
while(T -- )
{
int n;
scanf("%d", &n);
printf("%d\n", n);
for(int i = 1; i <= n; ++ i) printf("%d%c", i, i == n ? '\n' : ' ');
}
return 0;
}
B
给一个矩阵,每次操作可以选中相邻的两个元素,将他们都乘\(-1\), 可以进行无限次操作, 问矩阵中所有元素和的最大值
负号可以两两抵消,故考虑负号的个数,如果是偶数,全部抵消,求所有元素绝对值的和;如果是奇数, 最后剩一个负号, 选择绝对值最小的为负数即可
#include <bits/stdc++.h>
using namespace std;
const int N = 10 + 3;
int n, m;
int main()
{
int T;
scanf("%d", &T);
while(T -- )
{
int x, sum = 0, num = 0, minx = 1e9;
scanf("%d%d", &n, &m);
for(int i = 1; i <= n; ++ i)
for(int j = 1; j <= m; ++ j)
{
scanf("%d", &x);
sum += abs(x);
num += x < 0;
minx = min(minx, abs(x));
}
if(num & 1) printf("%d\n", sum - 2 * minx);
else printf("%d\n", sum);
}
return 0;
}
C
给\(n\)个数\(a_1\) ~ \(a_n\),给定\(W\), 判断能否从中选出几个数使得它们的和\(sum\)满足: \(\left\lceil\dfrac{W}{2}\right\rceil \le sum \le W\),如果可以,输出选择的数的编号
从大到小枚举即可,若本身超过\(W\)跳过即可,若不足\(\left\lceil\dfrac{W}{2}\right\rceil\), 继续枚举求和, 两个\(< \left\lceil\dfrac{W}{2}\right\rceil\)的数求和不会超过\(W\)
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 20;
int n;
LL W;
pair w[N];
int main()
{
int T;
scanf("%d", &T);
while(T -- )
{
scanf("%d%lld", &n, &W);
for(int i = 1; i <= n; ++ i)
{
scanf("%d", &w[i].first);
w[i].second = i;
}
sort(w + 1, w + n + 1, greater>());
vector vec;
LL sum = 0;
for(int i = 1; i <= n; ++ i)
{
if(w[i].first > W) continue;
sum += w[i].first; vec.push_back(w[i].second);
if(sum >= (W + 1) / 2) break;
}
if(sum < (W + 1) / 2) { printf("-1\n"); continue; }
printf("%d\n", vec.size());
for(auto x: vec) printf("%d ", x);
puts("");
}
return 0;
}
D
给两个字符串,定义\(S(C, D) = 4 \times LCS(C, D) - \left|C\right| - \left|D\right|\), 求两个字符串的子串\(C, D\)的最大\(S\)
定义\(f[i][j]\)为以\(A_i\)和\(B_j\)作为结尾的最大值
当\(A_i = B_j\)时, \(f[i][j]\) 可以从 \(f[i - 1][j - 1] + 4 - 2\)转移
当\(A_i \ne B_j\)时, \(f[i][j]\) 可以从 \(f[i - 1][j] - 1\) 和 \(f[i][j - 1] - 1\)转移
#include <bits/stdc++.h>
using namespace std;
const int N = 5000 + 20;
char a[N], b[N];
int n, m, f[N][N];
int main()
{
scanf("%d%d", &n, &m);
scanf("%s%s", a + 1, b + 1);
int res = 0;
for(int i = 1; i <= n; ++ i)
for(int j = 1; j <= m; ++ j)
{
if(a[i] == b[j])
f[i][j] = max(f[i][j], f[i - 1][j - 1] + 2);
f[i][j] = max(f[i][j], max(f[i - 1][j], f[i][j - 1]) - 1);
res = max(f[i][j], res);
}
printf("%d\n", res);
return 0;
}
E
对于第\(i\)个数来说,找到\(a_i \ xor \ a_j\)最小的连边\((i, j)\),只有最后形成一棵树才是合法的,问最少删去几个数,可以使得序列合法,\(a_i\)互不相同
01 trie建树,每次分叉的时候,只保留一个子树和另一个子树的一条链,递归求最大可保留点数即可.
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5 * 31 + 10;
int son[N][2], idx, n;
void insert(int x)
{
int p = 0;
for(int i = 30; i >= 0; -- i)
{
int u = x >> i & 1;
if(!son[p][u]) son[p][u] = ++ idx;
p = son[p][u];
}
}
int query(int p)
{
if(!son[p][1] && !son[p][0]) return 1;
else if(!son[p][1]) return query(son[p][0]);
else if(!son[p][0]) return query(son[p][1]);
else return max(query(son[p][0]) + 1, query(son[p][1]) + 1);
}
int main()
{
scanf("%d", &n);
for(int i = 1; i <= n; ++ i)
{
int x;
scanf("%d", &x);
insert(x);
}
printf("%d\n", n - query(0));
return 0;
}
2020.11.17
Codeforces Round #683 (Div. 2, by Meet IT)的更多相关文章
- Codeforces Round #683 (Div. 2, by Meet IT)【ABCD】
比赛链接:https://codeforces.com/contest/1447 A. Add Candies 题意 \(1\) 到 \(n\) 个袋子里依次有 \(1\) 到 \(n\) 个糖果,可 ...
- Codeforces Round #683 (Div. 2, by Meet IT) D. Catching Cheaters (DP)
题意:给你两个字符串,每次取它们的子串C和D,然后求LCS,得到的贡献为\(4*LCS(C,D)-|C|-|D|\),求最大贡献. 题解:首先应该了解\(O(n^2)\)的LCS的dp写法,然后在此基 ...
- Codeforces Round #683 (Div. 1) Solution
A. Knapsack 猜个结论--先把所有的东西加起来,如果小于 \(\frac{1}{2}m\) 就输出不合法:如果在 \([\frac{1}{2}m, m]\)之间直接全部输出:若大于 \(m\ ...
- 贪心/数学 Codeforces Round #212 (Div. 2) A. Two Semiknights Meet
题目传送门 /* 贪心/数学:还以为是BFS,其实x1 + 4 * k = x2, y1 + 4 * l = y2 */ #include <cstdio> #include <al ...
- Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)
Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...
- Codeforces Round #257 (Div. 1)A~C(DIV.2-C~E)题解
今天老师(orz sansirowaltz)让我们做了很久之前的一场Codeforces Round #257 (Div. 1),这里给出A~C的题解,对应DIV2的C~E. A.Jzzhu and ...
- Codeforces Round #533 (Div. 2)题解
link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...
- 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 ...
- Codeforces Round #354 (Div. 2) ABCD
Codeforces Round #354 (Div. 2) Problems # Name A Nicholas and Permutation standard input/out ...
随机推荐
- MySQL 回表查询 & 索引覆盖优化
回表查询 先通过普通索引的值定位聚簇索引值,再通过聚簇索引的值定位行记录数据 建表示例 mysql> create table user( -> id int(10) auto_incre ...
- anaconda python3.7 安装 tensorflow-gpu 2.0.0 beta1 配置PyCharm
参考tensorflow 公众号<tensorflow2.0 安装指南> https://mp.weixin.qq.com/s/7rNXFEC5HYe91RJ0-9CKdQ # 1. NV ...
- codeforces 868B
B. Race Against Time time limit per test 2 seconds memory limit per test 256 megabytes input standar ...
- redis持久化-AOF
1.aof文件写入与同步 2.aof重写 重写的目的是为了减小aof文件的体积,redis服务器可以创建一个新的aof文件来代替现有的aof文件,新文件不会有冗余的命令. BGREWRITEAOF:遍 ...
- 求第n行杨辉三角(n很大,取模
1 #include <iostream> 2 #include <cstdio> 3 4 using namespace std; 5 typedef long long l ...
- Os-hackNos-1(drupal7+suid提权)
一.信息收集 得到 ip是 192.168.56.101 , 端口开启了22和80,扫目录发现drupal 7 访问一下呢 在exploit-db上面搜索到存在相关的漏洞,而且是用直接上msf 使用第 ...
- 写给程序员的机器学习入门 (十一) - 对象识别 YOLO - 识别人脸位置与是否戴口罩
这篇将会介绍目前最流行的对象识别模型 YOLO,YOLO 的特征是快,识别速度非常快
- Go string 一清二楚
前言 字符串(string) 作为 go 语言的基本数据类型,在开发中必不可少,我们务必深入学习一下,做到一清二楚. 本文假设读者已经知道切片(slice)的使用,如不了解,可阅读 Go 切片 基本知 ...
- WIN10修改应用的默认打开方式
如图所示: 选中想要替换成为的应用程序, 在其中勾选想设默认应用的文件类型即可.
- NoSQL 数据库案例实战 -- MongoDB数据备份、恢复
MySQL数据迁移到MongoDB数据库中 前言 一.数据备份 二.数据恢复 前言 本环境是基于 Centos 7.8 系统构建mongodb-enterprise-4.2.8学习环境具体构建,请参考 ...