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)的更多相关文章

  1. Codeforces Round #683 (Div. 2, by Meet IT)【ABCD】

    比赛链接:https://codeforces.com/contest/1447 A. Add Candies 题意 \(1\) 到 \(n\) 个袋子里依次有 \(1\) 到 \(n\) 个糖果,可 ...

  2. 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写法,然后在此基 ...

  3. Codeforces Round #683 (Div. 1) Solution

    A. Knapsack 猜个结论--先把所有的东西加起来,如果小于 \(\frac{1}{2}m\) 就输出不合法:如果在 \([\frac{1}{2}m, m]\)之间直接全部输出:若大于 \(m\ ...

  4. 贪心/数学 Codeforces Round #212 (Div. 2) A. Two Semiknights Meet

    题目传送门 /* 贪心/数学:还以为是BFS,其实x1 + 4 * k = x2, y1 + 4 * l = y2 */ #include <cstdio> #include <al ...

  5. Codeforces Round #367 (Div. 2) B. Interesting drink (模拟)

    Interesting drink 题目链接: http://codeforces.com/contest/706/problem/B Description Vasiliy likes to res ...

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

  7. Codeforces Round #533 (Div. 2)题解

    link orz olinr AK Codeforces Round #533 (Div. 2) 中文水平和英文水平都太渣..翻译不准确见谅 T1.给定n<=1000个整数,你需要钦定一个值t, ...

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

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

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

随机推荐

  1. JVM你了解?

    1.谈谈你对JAVA的理解 平台无关性(一次编译,到处运行) GC(不必手动释放堆内存) 语言特性(泛型.lambda) 面向对象(继承,封装,多态) 类库 异常处理 2.平台无关性怎么实现

  2. CF1478-B. Nezzar and Lucky Number

    CF1478-B. Nezzar and Lucky Number 题意: 题目给出一个数字\(d(1\leq d \leq 9)\)代表某个人最喜欢的数字. 题目定义了幸运数字,它的含义为:若一个数 ...

  3. Kubernets二进制安装(11)之部署Node节点服务的kubelet

    集群规划 主机名 角色 IP地址 mfyxw30.mfyxw.com kubelet 192.168.80.30 mfyxw40.mfyxw.com kubelet 192.168.80.40 注意: ...

  4. Ubuntu 下更改pip源使用清华源

    一.新建目录 sudo -s mkdisk ~./pip vim ~./pip/pip.conf 二.复制下面代码,并保存 [global] index-url = https://pypi.tuna ...

  5. 牛年 dotnet云原生技术趋势

    首先祝大家:新年快乐,牛年大吉,牛年发发发! 2020年的春节,新冠疫情使得全球业务停滞不前,那时候,没有人知道会发生什么,因此会议被取消,合同被搁置,项目被推迟,一切似乎都停止了.但是我们却见证了I ...

  6. bzoj4355 Play with sequence(吉司机线段树)题解

    题意: 已知\(n\)个数字,进行以下操作: \(1.\)区间\([L,R]\) 赋值为\(x\) \(2.\)区间\([L,R]\) 赋值为\(max(a[i] + x, 0)\) \(3.\)区间 ...

  7. tfrecords转np.array

    import tensorflow as tf import numpy as np from keras.utils import to_categorical import sys def tfr ...

  8. git & Angular git commit 规范

    git & Angular git commit 规范 https://github.com/angular/angular/commits/master https://github.com ...

  9. web testing

    web testing cypress https://www.cypress.io/ https://github.com/cypress-io/cypress https://docs.cypre ...

  10. vue v-io 父子组件双向绑定多个数据

    vue-io-directive 可以减少使用emit,组件自带的v-model好像也只能设置一个 安装 npm i vue-io-directive 使用 import Vue from 'vue' ...