cf-codeforces codeforces round 909

【做题记录】CodeForces343D Water Tree

题面翻译 - 给出一棵以 $1$ 为根节点的 $n$ 个节点的有根树。每个点有一个权值,初始为 $0$。 - $m$ 次操作。操作有 $3$ 种: 1. 将点 $u$ 和其子树上的所有节点的权值改为 $1$。 2. 将点 $u$ 到 $1$ 的路径上的所有节点的权值改为 $0$。 3. 询问点 $u ......
CodeForces Water 343D Tree 343

709 Round Day 5

$$ \Huge\text{709 Round Day 5} $$ $$ \large\text{Math Round} $$ $$ \large\text{Time: 2023.5.8 17:40 - 18:00} $$ $$ \large\text{出题: phx 验题: yhn 题面: phx ......
Round 709 Day

Codeforces 1827E - Bus Routes(思维)

一道比较诈骗的题,放在现场最大的挑战在于做完 B2 C D 这三道不算太签的题以后还有时间开这个题。 首先特判 $n=2$。以任意一个不是叶子的点为根。那么一棵树合法,当且仅当其中所有叶子都能在 $2$ 步内互相到达,因为如果一对不能在 $2$ 步内互相到达的点 $(u,v)$ 中存在至少一个不是叶 ......
Codeforces 思维 Routes 1827E 1827

Codeforces Round 873 (Div. 2)

Codeforces Round 873 (Div. 2) 链接 Codeforces Round 873 (Div. 2) A题 打印2-n并且计算总和,然后找到严格大于sum的n的倍数记为x,然后用这个x减去sum得到a. 然后先打印a然后再打印2-n #include <iostream> # ......
Codeforces Round 873 Div

Codeforces Round 767 (Div. 1) E. Groceries in Meteor Town (Kruskal重构树 + 线段树)

传送门 ** 出现最大路径权值就应该联想到克鲁斯卡尔重构树,我们对于克鲁斯卡尔重构树求一遍dfs序,维护所有白色点的最大最小dfn(包括出发点),求出最大最小dfn的最近公共祖先既是答案。注意需要特判一下除了本身以外没有白色点情况。** #include <bits/stdc++.h> int n, ......
线段 Codeforces Groceries Kruskal Meteor

Codeforces Round 873 A~E

Codeforces Round 873 (Div.1) A. Counting Orders 对于每个 $a_i$,可以计算出 $c_i$ 表示有多少个 $b_j\lt a_i$。 那么第 $i$ 个人就有 $c_i$ 种可能的位置。 注意到如果将 $a$ 升序排序,则能放的位置集合从前往后是包含 ......
Codeforces Round 873

Educational Codeforces Round 148 (Rated for Div. 2) A-D2

Educational Codeforces Round 148 (Rated for Div. 2) A. New Palindrome map<int,int>mp; void solve(){ string s; mp.clear(); cin>>s; for(int i=0;i<s.size ......
Educational Codeforces Round Rated 148

CodeForces 1827 D Two Centroids

洛谷传送门 CF 传送门 考虑固定一个重心,设 $k$ 为重心最大子树大小,答案为 $n - 2k$。构造方法是往最大的子树塞叶子。 树的重心有一个很好的性质,就是加一个叶子,重心最多移动一条边的距离。简单证一下,设重心为 $x$,往儿子 $u$ 的子树中加叶子。 如果 $sz_u > \left\ ......
CodeForces Centroids 1827 Two

CodeForces 1827 B Range Sorting

洛谷传送门 CF 传送门 考虑拆贡献 $i - 1 \sim i$,发现当 $[1, i - 1]$ 的最大值大于 $[i, n]$ 的最小值时 $i - 1 \sim i$ 产生 $1$ 的贡献。 考虑枚举左端点 $j$,设 $x = \max\limits_{k=j}^{i-1} a_k$。设 ......
CodeForces Sorting Range 1827

c#中的Math.Round()

https://www.cnblogs.com/jxl123456/p/12606456.html 其实C#中的Math.Round提供了非常多的重载方法,其中有两个重载方法是, public static double Round (double value, int digits, Midpoi ......
Round Math

Codeforces Round 872 (Div. 2)

Preface 怎么感觉越来越菜了现在,拿个小号打Div2都被血虐 C题一个Corner Case没写好直接爆炸,本来10min秒切的愣是搞到最后用对拍才看出来 本来D2和E都很有思路的说,结果都来不及写了苦路西 不过换着想还好是小号,不然直接又俯冲蓝名了 A. LuoTianyi and the ......
Codeforces Round 872 Div

Codeforces Round 872 (Div. 2) A-D

比赛地址 A. LuoTianyi and the Palindrome String 题意:给一个回文串,求最长的非回文子串的长度 Solution 判一下回文串是不是由相同的字母组成的,如果是的那么无解,如果不是答案就是len-1 void solve() { string s;cin>>s; ......
Codeforces Round 872 A-D Div

Codeforces Round 871 (Div. 4) A-H

Codeforces Round 871 (Div. 4) A. Love Story string t="codeforces"; void solve(){ string s; cin>>s; int ans=0; for(int i=0;i<10;i++){ if(s[i]!=t[i])ans ......
Codeforces Round 871 A-H Div

Codeforces Round 872 (Div. 1 & Div. 2)

这场寄大了。 My predictor say -101pts。 https://codeforces.com/contest/1824 https://codeforces.com/contest/1825 2A. LuoTianyi and the Palindrome String 因为给出的 ......
Codeforces Div Round 872 amp

Codeforces Round 871 (Div. 4)

A. Love Story #include<bits/stdc++.h> using namespace std; #define int long long int read() { int x = 0, f = 1, ch = getchar(); while ((ch < '0' || ch ......
Codeforces Round 871 Div

Codeforces Round 871 (Div. 4)

A.Love Story 题意: 给定n个长度为10的字符串,问其与codeforces字符串的对应下标字母不同的个数。 分析: 对于每个字符串从前往后依次和“codeforces”对应字符比较然后统计不同字母数即可 code: #include <bits/stdc++.h> using name ......
Codeforces Round 871 Div

Codeforces Round 871 (Div. 4)

Codeforces Round 871 (Div. 4) A - Love Story #include<bits/stdc++.h> using namespace std; typedef pair<int,int>PII; typedef pair<string,int>PSI; const ......
Codeforces Round 871 Div

Codeforces 871 div4(重拳出击)

Codeforces 871 div4 ABC 简单题 D 题意 每次操作可以将当前的数分成两份,一份是$\frac{1}{3}$,一份是$\frac{2}{3}$,问当前数n可否进行若干次操作,最终出现一份大小为m的片。递归一下就好了,数据最大才$10^7$ 代码 void dfs(int x) ......
重拳 Codeforces div4 871 div

Codeforces Round 871 (Div. 4) 题解

好久没打比赛了啊 qwq A~C skip D 把能被 $3$ 整除的数丢到一个队列里去 $\text{BFS}$,每次取队头把它分成两个,如果能被 $3$ 整除继续入队。最后看给定的数有没有入过队。 E 直接 $\text{BFS}$,把每个块总和算出来求最大。 F 可以发现,图的点数 $n=1+ ......
题解 Codeforces Round 871 Div

Codeforces 1817E - Half-sum

好题啊!最喜欢这种思路层层递进的题了。 首先从最终形态的角度入手分析。建立一棵合并树,每次合并两个数的时候就新建一个节点,令这个节点为合并的两个节点的父亲。那么显然一个点对答案的贡献系数就是 $2^{-\text{其在合并树中的深度}}$。更具体地不妨设 $B>A$,最终被划分在 $A$ 对应的数中 ......
Codeforces Half-sum 1817E 1817 Half

Codeforces Round 870 (Div. 2)

Codeforces Round 870 (Div. 2) A - Trust Nobody 思路:枚举每一种说谎人数x,若a[i]大于x则说谎人数加一,判断最后说谎总人数是否为x,若是则输出x,结束枚举;若没有满足的x则-1 #include<bits/stdc++.h> using namesp ......
Codeforces Round 870 Div

Codeforces 1817F - Entangled Substrings(SA)

为什么赛时不开串串题?为什么赛时不开串串题?为什么赛时不开串串题?为什么赛时不开串串题?为什么赛时不开串串题? 一种 SA 做法,本质上和 SAM 做法等价,但是说来也丢人,一般要用到 SAM 的题我都是拿 SA 过的/wul 考虑将 $ac$ 看作一个整体。记 $\text{occ}(S)$ 为 ......
Codeforces Substrings Entangled 1817F 1817

Codeforces Round 848 (Div. 2)C

B. The Forbidden Permutation 一定要注意题目中说的是对于all i满足才算不好的,我们做的时候只要破坏一个i这个a就不算好的了,被这一点坑了,没注意到all。 #include <bits/stdc++.h> using namespace std; typedef lo ......
Codeforces Round 848 Div

Codeforces Round 856 (Div. 2)C

C. Scoring Subsequences 思路:我们想要找到满足的最大值的长度最长的的区间,因为单调不减,所以更大的数一定在最大值的里面包含,所以我们用两个指针维护这样一个满足当前i的最大值区间,当新来一个数,这时我们答案里面一定要包含这个数,我们看能否保持这个长度,能不能保持需要看j指针所指 ......
Codeforces Round 856 Div

Codeforces——870

A. Trust Nobody 题目大意 给你一个长度为$n$的数组$a$,$a$中每个元素$a_i$表示当前人认为$n$个人中至少有$a_i$个人说谎,让你找出说谎的人的个数。 思路: 枚举说谎人数$x$,遍历$a$数组,对于当前$a_i$,如果有$a_i \geq x$,那么显然第$i$个人在说 ......
Codeforces 870

[CodeForces-1104A]题解(C++)

Part I Preface 原题目(Luogu) 原题目(CodeForces) Part II Sketch 给定一个整数 $n$。 将 $n$ 拆分成一个数列 $a_1,a_2,a_3,\dots,a_m$。 使得 $\sum\limits_{k = 1}^{m}a_k = n$,每个 $a_ ......
题解 CodeForces 1104

[CodeForces-143A]题解(C++)

Part I Preface 原题目(Luogu) 原题目(CodeForces) Part II Sketch 设有一个 $2 \times 2$ 的棋盘,上面可以填入 $1-9$ 的数字。 给出 $6$ 个数字,为每行每列以及每个对角线上的数字之和,求相应的摆放方式,无解输出 $-1$。 Par ......
题解 CodeForces 143

练习记录-cf-div2-Codeforces Round 870 (A-D)

这次写的也是比较快!rank305 虽然D简单,但是写出来了就算胜利! A. Trust Nobody 题意:给出n个人,他们会说多少人是说谎的,你要找出这个人数 思路: n最多只有100个,我枚举说谎的人有i个,对说话小于等于i的做前缀和,这个几个人都是说真话,记录前缀和sum,n-sum就是说谎 ......
Codeforces cf-div Round 870 A-D

Codeforces Round 870 (A-D)

A $n^2$暴力推,遍历可能撒谎的人数(0-n),然后$O(n)$check就行了。 仔细看逻辑其实$O(1)$就能check,草率了,后面再修正 点击查看代码 #include <bits/stdc++.h> #define rep(i, l, r) for(int i = l; i <= r; ......
Codeforces Round 870 A-D

CodeTON Round 4 (Div. 1 + Div. 2)C

C. Make It Permutation 我们希望尽可能少地进行操作可以使代价最小,我们如果要排列的话,那些重复的元素我们无论如何都要进行删除的,所以我们可以先把去重的代价计算出来,然后依次枚举排列的位数是多少,也就是枚举去重后的数组,其中的代价我们可以一次计算出来,当我们枚举第i个a时,前面1 ......
Div CodeTON Round