codeforces resort round 878

SMU Autumn 2023 Round 1(Div.1)

SMU Autumn 2023 Round 1(Div.1) A. Set or Decrease(枚举) 题意就是你可以进行两种操作,将\(a_i-1\)或者令\(a_i\)等于\(a_j\),然后使得\(\sum\limits_{i=1}^{n}a_i \leq k\),求最少的操作步数 首先我 ......
Autumn Round 2023 SMU Div

Codeforces Round 895 (Div. 3)

# Codeforces Round 895 (Div. 3) [比赛链接](https://codeforces.com/contest/1872) ## A. Two Vessels [题目链接](https://codeforces.com/contest/1872/problem/A) 给你 ......
Codeforces Round 895 Div

Codeforces Round 895 (Div. 3)

## B. The Corridor or There and Back Again >![image-20230908015323851](https://zeoy-typora.oss-cn-hangzhou.aliyuncs.com/image-20230908015323851.png) # ......
Codeforces Round 895 Div

$Codeforces Round 895 (Div. 3)$

## $A. Two Vessels$ 一开始我以为那个 $c$ 桶只能装满,看了好久。 范围内的任意容量都可以取的话,那么只要看需要转移多少量,然后看需要多少次。 ```cpp void solve(){ int n=read(),m=read(),k=read(); double nd=abs( ......
Codeforces Round 895 Div

$Educational Codeforces Round 138 (Rated for Div. 2)$

## $A. Cowardly Rooks$ 我模拟了一遍,因为我没看到题目中*给出的矩阵已经合法*, $a$ 题第一次写这么多。 实验室同事跟我说只要判断 $n$ 和 $m$ 的大小关系就行了。 ```cpp int x[N],y[N],m,n; bool check(){ for(int i=1 ......
Educational Codeforces Round Rated 138

Codeforces Round 798 (Div. 2) C (树形DP、思维、*1600)

[C. Infected Tree](https://codeforces.com/problemset/problem/1689/C "C. Infected Tree") > 题意:给定一棵树, 钦定 $ 1 $ 号点为根节点, 一开始根节点中毒了, 接下来的 $ n $ 个时刻, 每一时刻可以 ......
树形 Codeforces 思维 Round 1600

【题解】Educational Codeforces Round 144(CF1796)

被 C 卡了。 最后被 E 的各种分讨劝退,但是同时也学习到了一种换根 dp 的简单写法。 评价:It's educational for me. ## A.Typical Interview Problem ### 题目描述: 有一个包含 F 和 B 的字符串,最开始是空的。我们开始从 $1$ 向 ......
题解 Educational Codeforces Round 1796

The 16-th BIT Campus Programming Contest - Onsite Round

链接:[https://codeforces.com/gym/104025](https://codeforces.com/gym/104025) ## A. Gifts in box ```cpp #include "bits/stdc++.h" using namespace std; usin ......
Programming Contest Campus Onsite Round

# Codeforces Round 887 E Ina of the Mountain(反悔贪心)

~~被这个题折磨了好久,决定写一篇题解~~ 先考虑没有这个$k$的限制的情况,等价于对原来的$a_i$序列的差分数组$b_i$,每次找到两个位置$1\le x 0$的位置进行$-1$的操作,后面对应的$+1$可以放在$b_ic[i]$,那么$c[i]$减去$k$对答案的贡献就是$0$,因为$d[i] ......
Codeforces Mountain Round 887 Ina

CodeForces 960G Bandit Blues

[洛谷传送门](https://www.luogu.com.cn/problem/CF960G "洛谷传送门") [CF 传送门](https://codeforces.com/problemset/problem/960/G "CF 传送门") 发现设排列最大值位置为 $i$,那么 $[1, i] ......
CodeForces Bandit Blues 960G 960

Codeforces Round 247 (Div. 2) C(线性DP、树形结构)

[C. k-Tree](https://codeforces.com/contest/431/problem/C "C. k-Tree") > 题意:给定一颗 \$ k \$ 叉树, 每个节点和其子节点的连边的权值分别为 \$ 1, 2, \cdot\cdot\cdot, k \$, 问从根节点开始 ......
树形 线性 Codeforces 结构 Round

Codeforces Round #887 (Div. 2) A-D

[比赛链接](https://codeforces.com/contest/1853) # A ## 代码 ```c++ #include using namespace std; using ll = long long; int a[507]; bool solve() { int n; cin ......
Codeforces Round 887 A-D Div

Educational Codeforces Round 120

# C. Set or Decrease 可以得到两个规律 - 修改操作一定是把较大的数变成最小的数更优 - 减一对谁操作都不影响结果 根据以上两个规律有可以总结出最优操作策略 - 对最小值先做若干次减法 - 把最大的若干个数变成最小值 已知策略后,我们发现因为值域很大,所以不能枚举最小值减的次数, ......
Educational Codeforces Round 120

Educational Codeforces Round 138 (Rated for Div. 2) B. Death's Blessing

这是一个电脑游戏,$n$ 个怪物排成一行,第 $i$ 个怪物的血量为 $a_i$ 并且它的亡语强度为 $b_i$ 。规则是: * 玩家每秒可以削减一只怪物的一点血量。 * 第 $i$ 只怪物死亡后会释放亡语,它两侧的怪物血量会得到 $b_i$ 的增幅血量。边界上的怪物只能对它的邻居进行亡语增幅。 * ......
Educational Codeforces Blessing Death Round

Codeforces Round 406 (Div. 2) D. Legacy 线段树优化建图

[传送门](https://codeforces.com/problemset/problem/786/B) 题目大意: **给定n个点,m个操作,和起点s。其中n 和 q 大于等于1小于等于1e5, s大于等于1小于等于n** **其中m个操作有三种情况:** 1.输入1 u v val 表示从u ......
线段 Codeforces Legacy Round 406

Codeforces Round 836 (Div. 2) B. XOR = Average

给一个正整数 $n$ ,找到一个序列 $a_1, a_2, \cdots, a_n$ 满足 $$ \bigoplus_{i=1}^{n} a_i = \frac{\sum_{i=1}^{n} a_i}{n} $$ 。 一个原始的问题: $\bigoplus_{i=1}^{n}a_i=\sum_{i= ......
Codeforces Average Round 836 Div

Educational Codeforces Round 119

# B. Triangles on a Rectangle 因为保证了每一个边上都有点,所以相当于三角形的高已经确定了。最大化底即可。 ```cpp #include using namespace std; #define int long long const int inf = 1e15; u ......
Educational Codeforces Round 119

Codeforces Global Round 24 B. Doremy's Perfect Math Class

给一个元素个数为 $n$ 的正整数集合 $S$ ,可以做以下操作任意次: * 选择 $S$ 中的两个元素 $x$ $y$ 满足 $x > y$ 且 $x - y$ 不在集合内。 * 加入 $x - y$ 到集合。 经过若干次操作后,集合中最多能存在多少元素。 性质一:两个数 $x$ $y$ 辗转相减 ......
Codeforces Perfect Global Doremy Class

Codeforces Round 842 (Div. 2) B. Quick Sort

给一个长为 $n$ 的排列 $p$ 和一个正整数 $k, (k \leq n)$ 。在一步操作中,可以: * 选择 $k$ 个不同的元素 $p_{i_1}, p_{i_2}, \cdots, p_{i_k}$ 。 * 将他们移除然后排序,并拼接到剩余数组末尾 找到最小的操作数使得整个排列为增序。 典 ......
Codeforces Round Quick Sort 842

Codeforces Round 837 (Div. 2) A. Hossam and Combinatorics

给一个长为 $n$ 的数组 $a$ ,统计出所有二元组 $(a_i, a_j)$ 数量,满足以下条件: * $1 \leq j view ``` #include void solve() { int n; std::cin >> n; std::vector a(n); for (int i = ......
Combinatorics Codeforces Hossam Round 837

Codeforces Round 843 (Div. 2) A2. Gardener and the Capybaras (hard version)

有三个字符串 $s_1, s_2, s_3$ ,每个字符串只有 $a, b$ 组成。三个字符串顺序连接在了一起。满足以下条件之一: * $s1 \leq s_2, s_3\leq s_2$ * $s1 \geq s_2, s_3\geq s_2$ 以上为字典序比较。 给出连接的三个字符串,输出一组可 ......
Codeforces Capybaras Gardener version Round

Codeforces Round 869 (Div. 2) B. Indivisible

给一个正整数 $n$ ,问能否构造出任意一个一个长为 $n$ 的排列满足 $\forall l,r,\ 1 \leq l view ``` #include void solve() { int n;std::cin >> n; if (n == 1) std::cout > _; while (_ ......
Indivisible Codeforces Round 869 Div

Codeforces Round 873 (Div. 2) B. Permutation Swap

给一个无序排列 $p_1, p_2, \cdots, p_n$ 。为了排序这个排列,选一个常数 $k(k \geq 1)$ 并且在排列上做一些操作。 * 一次操作可以选择 $i, j, (1 \leq j view ``` #include typedef long long ll; ll gcd( ......
Permutation Codeforces Round Swap 873

Codeforces Round 861 (Div. 2) A. Lucky Numbers

定义一个数的幸运值是这个数的数位的最大值减去最小值,如 $luckiness_{769} = 9 - 6 = 3$ 。给出 $l$ $r$ ,求 $[l, r]$ 中最幸运的数,若最幸运的数有多个,任意一个为答案。 考虑拆分数位,然后枚举。以 $O(d)$ 的复杂度计算幸运值。则线性扫一遍的复杂度为 ......
Codeforces Numbers Round Lucky 861

Codeforces Round 859 (Div. 4) D. Odd Queries

给一个长为 $n$ 的数组 $a$ 。回到 $q$ 个询问。 * 让 $a_l, a_{l + 1}, \cdots, a_r$ 变为 $k$ ,$\sum_{i = 1}^r a_i$ 是否为奇数。 每个询问独立。 显然每个学问独立可以使用前缀和计算区间和,单个询问中 $pre_{1, l - 1 ......
Codeforces Queries Round 859 Div

Codeforces Round 858 (Div. 2) B. Mex Master

给一个长为 $n$ 的数组 $a$ ,定义 $a$ 的 $score$ 为 $a_1+ a_2, a_2 + a_3, \cdots, a_{n - 1} + a_n$ 的 $MEX$ 。 找到 $a$ 的 最小 $score$ 如果 $a$ 可以被重排。$(0 \leq a_i \leq 2 \t ......
Codeforces Master Round 858 Div

Codeforces Round 856 (Div. 2) B. Not Dividing

给一个长为 $n$ 的正整数数组 $a$ ,在一步操作中,你可以选择任一个数并且 $add\ 1$ 。要求最多执行 $2n$ 步操作使 $a$ 满足 $\forall i, i \in[1, n - 1], a_{i} \nmid a_{i + 1}$ 。输出任一个在操作数限制内可以得到的合法数组。 ......
Codeforces Dividing Round 856 Div

* Codeforces Round 889 (Div. 2) B. Longest Divisors Interval

给一个正整数 $n$ ,找一段最长的 $[l, r]$ ,满足 $\forall i, i \in [l, r],\ s.t.\ i | n$ 。输出这一段区间的长度,即 $r - l + 1$ 。 这题是一个准结论题,需要一些知识点和观察的基础。 放在 $900$ 的位置是因为结论存在的区间太容易 ......
Codeforces Divisors Interval Longest Round

Codeforces Round 874 (Div. 3) B. Restore the Weather

给一个长为 $n$ 的数组 $a$ ,给一个长为 $n$ 的乱序数组 $b$ ,给一个正整数 $k$ 。要求重排 $b$ 使得 $\forall i, |a_i - b_i| \leq k$ 。输出其中一种 $b$ 的排列方式。 一个性质题。(div2 前几题很喜欢有序数组的经典性质) 总结一下有序 ......
Codeforces Restore Weather Round 874

Codeforces Round 868 (Div. 2) B. Sort with Step

给一个长为 $n$ 的排列(无序)$p$,为 $p_1, p_2, \cdots, p_n$ 。一个正整数 $k$ 。 允许执行任意次以下操作: * 选择两个数 $p_i$ $p_j$ 满足 $|i - j| = k$ ,并且 $swap(p_i, p_j)$ 。 允许最多执行一次特殊操作: * 选 ......
Codeforces Round Sort with Step