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. C# EventWaitHandle类解析

    EventWaitHandle 类用于在异步操作时控制线程间的同步,即控制一个或多个线程继行或者等待其他线程完成. 构造函数 EventWaitHandle(bool initialState, Ev ...

  2. SDN总结

    之前做项目用到了SDN,知道其作用,但是对其不是特别熟悉,今天特来总结一下相关知识点: 1. SDN的典型架构分为哪三层 主要分为应用层,控制层,和基础设施层: 2. SDN技术的关键点是 控制平面和 ...

  3. codeforces 758D

    D. Ability To Convert time limit per test 1 second memory limit per test 256 megabytes input standar ...

  4. Cortex-M系列内核 启动文件分析

    最近终于闲了下来了准备好好学习下Cortex-M3/M4系列处理器的架构,经过各种资料的折磨也没法对它的整个工作过程能有个完整的认知,最后看到一片博客打算从程序的运行过程开始探究,所以首先就找到了启动 ...

  5. UTM & User Tracking Message

    UTM & User Tracking Message utm_source https://marketingplatform.google.com/about/resources/link ...

  6. Raspberry Pi 电路图模拟器

    Raspberry Pi 电路图模拟器 Circuit Diagram / Circuit Graph https://fritzing.org/learning/tutorials/building ...

  7. Alexa website ranking

    Alexa website ranking The top 500 sites on the web https://www.alexa.com/topsites https://www.alexa. ...

  8. yarn & uninstall global & yarn global remove

    yarn uninstall global yarn global remove https://yarnpkg.com/lang/en/docs/cli/remove/ https://yarnpk ...

  9. css delete line text & html del

    css delete line text & html del html <del>¥720</del> demo <span class="ticke ...

  10. how to convert SVG shapes to polygon

    how to convert SVG shapes to polygon 如何将 svg 的 rect 转换成 polygon rect.circle.ellipse.line.polyline.po ...