codeforces decreasing 1839e game

CodeForces 1882E1 Two Permutations (Easy Version)

洛谷传送门 CF 传送门 考虑若是对一个排列进行操作,怎么做。 我们维护一个排列上的值域连续段 \([l, r]\),满足 \(a_{l + 1} = a_l + 1, a_{l + 2} = a_{l + 1} + 1\),以此类推。初始 \(l = r = 1\)。 那么我们每次可以选择往外扩充 ......
Permutations CodeForces Version 1882E1 1882E

CodeForces 1882E2 Two Permutations (Hard Version)

洛谷传送门 CF 传送门 如何评价,模拟赛搬了一道,前一天晚上代码写了一半的题。 考虑如何让操作次数最小。发现直接做太困难了。根本原因是,一次操作对序列的影响太大了。考虑做一些转化,减少一次操作对序列的影响。 仍然先考虑一个排列怎么做。 不知道为什么可以想到在排列前面添加特殊字符 \(0\) 变成 ......
Permutations CodeForces Version 1882E2 1882E

Codeforces Round 834 (Div. 3)

Codeforces Round 834 (Div. 3) A - Yes-Yes? 思路:判断每种情况即可 #include<bits/stdc++.h> using namespace std; //#define int long long //#define int __int128 #de ......
Codeforces Round 834 Div

Educational Codeforces Round 156 (Rated for Div. 2) - A B C D

目录A. Sum of Three A. Sum of Three 如果说给定的数为 n 如果 \(n \le 6\) 或 \(n = 9\) 时,无法分解 如果 $n %% 3 != 0 $ 时,可以 ......
Educational Codeforces Round Rated 156

CF1886C Decreasing String

单调栈的应用。 显然可以 \(O(n)\) 地找到 \(pos\) 所属的 \(s_i\) 段,所以我们只需要得到 \(s_i\) 即可。不难发现,删除元素的规则应该是从 \(1\) 到 \(n\) 枚举每个元素,删除它前面“紧邻的”比他大的元素(例如对于 eadcb 中的 b 删除掉 dc)。 赛 ......
Decreasing String 1886C 1886 CF

Educational Codeforces Round 156 A-D

A. Sum of Three 思路1: 1.把数拆成1,2,n-3 2.如果(n-3)%3==0,那么拆成1,4,n-5,可证明n-3如果可被3整除,那么再左移两位一定除不尽 思路2: 1.如果n是奇数,那么可取一个数为2,其他两数为相邻数,如果两数其中一位被整除,那么两者往外走 2.如果n为偶, ......
Educational Codeforces Round 156 A-D

Educational Codeforces Round 156 (Rated for Div. 2)

Preface 沉迷Galgame不打CF懒狗闪总出列! 这场在大物课上口胡了前四个题,回去写了也都很顺,然后E题本来做不来的,看了眼昨天校队群里的消息就会做了 F题什么东西直接弃 A. Sum of Three 当\(n\bmod 3\ne 0\)时,用\((1,2,z)\)来凑;否则当\(n\b ......
Educational Codeforces Round Rated 156

Codeforces Round 706 (Div. 2) A. Split it!

给一个长度为 \(n\) 的字符串 \(s\) 。给定一个正整数 \(k\) 。询问 \(s\) 能否等于 \(a_1 + a_2 + \cdots + a_k + a_{k + 1} + R(a_k) + R(a_{k - 1}) + \cdots + R(a_{1})\) 。 其中 \(a_i\ ......
Codeforces Round Split 706 Div

Codeforces Round 707 (Div. 2, based on Moscow Open Olympiad in Informatics) B. Napoleon Cake

按以下 \(n\) 次操作制作蛋糕。 叠上第 \(i\) 块面包,然后浇上 \(a_i\) 单位的奶油。可以使当前往下 \(a_i\) 块面包沾上奶油。 输出空格隔开的 \(n\) 个数,第 \(i\) 个的 \(0/1\) 代表第 \(i\) 块面包是否沾有奶油。 比较显然的思路可以进行差分修改。 ......

C. Card Game

C. Card Game There are $n$ cards stacked in a deck. Initially, $a_{i}$ is written on the $i$-th card from the top. The value written on a card does no ......
Card Game

Codeforces Round 834 (Div. 3)

A. Yes-Yes? #include <bits/stdc++.h> using namespace std; #define int long long using pii = pair<int, int>; using vi = vector<int>; const string T = " ......
Codeforces Round 834 Div

Educational Codeforces Round 109 (Rated for Div. 2) B. Permutation Sort

给一个长为 \(n\) 的排列 \(a\),你可以执行以下操作:选择一个子数组并且按任意顺序重排,但这个子数组不能是数组本身。 询问最少经过多少次操作可以使得排列 \(a\) 变为升序。 定义操作次数为 \(ans\) 。 若数组已经有序,\(ans = 0\) 。 若 \(a_1 = 1\) 或者 ......

Educational Codeforces Round 110 (Rated for Div. 2) Array Reodering

给一个长为 \(n\) 的数组 \(a\) 。 定义一对 \(pair(i, j)\) 是 \(good\) 的当且仅当 \(1 \leq i < j \leq n\) 且 \(gcd(a_i, 2 \cdot a_j) > 1\) 。 如果你可以以任意顺序重排数组 \(a\) ,找到最多的 \(g ......
Educational Codeforces Reodering Array Round

Codeforces Round 902 Div 1 (CF 1876)

A. Helmets in Night Light 按花费 sort 一下,\(b<p\) 就让他用 \(b\) 的花费告诉别人,剩下的人一开始用 \(p\) 的花费告诉即可。 B. Effects of Anti Pimples 发现一个数会被所有它的因数贡献,\(O(n\sqrt{n})\) 随 ......
Codeforces Round 1876 902 Div

Educational Codeforces Round 156 (Rated for Div. 2)

Educational Codeforces Round 156 (Rated for Div. 2) A. Sum of Three 解题思路: 如果\(n \leq 6 或 n =9\),无解。 若\(n \% 3 == 0,t = \lfloor\frac{3}{n}\rfloor\): 若\ ......
Educational Codeforces Round Rated 156

Codeforces Round 902 (Div. 2, based on COMPFEST 15 - Final Round)

目录写在前面ABCDE写在最后 写在前面 比赛地址:https://codeforces.com/contest/1877。 呜呜铃果唱歌太好听了、、、 我宣布是第二喜欢的声线,第三喜欢是东北切蒲英,第一喜欢绝赞招募中。 这下不得不成为数码推了、、、 A 答案为 \(-\sum a_i\)。 懒得写 ......
Round Codeforces COMPFEST Final based

Codeforces Round 891 (Div. 3) F. Sum and Product(数论+map)

Codeforces Round 891 (Div. 3) F. Sum and Product 思路:对于x,y:ai+aj=x —> aj=x-ai 因此 ai*(x-ai) = y ——> ai = (x 土 sqr( x^2 - 4y ) ) /2 对应的 ai 就是要的两个值 若两个值不同 ......
数论 Codeforces Product Round 891

Educational Codeforces Round 152 (Div. 2) D. Array Painting(双指针)

Educational Codeforces Round 152 (Div. 2) D. Array Painting //思路:双指针找连续正数段 //若段中出现2,则更新两头的0的情况,若为涂色则改为true //若无2,则优先更新左侧0,若左0已经为true,则更新右侧0 //数组开头结尾特判 ......
指针 Educational Codeforces Painting Array

练习记录-cf-Educational Codeforces Round 156 (Rated for Div. 2)(A-C)

好久没打了 还是就出了三道 不过还好没掉分 A. Sum of Three 就是问能不能把一个数拆成三个不同的 且都不能被三整除的数 我的思路就是拆成1+2+一个大于等于4的数 如果拆了后另一个数是%3==0 那么我拆成1+4它肯定就不被整除 然后判下相同 #include<bits/stdc++. ......

Codeforces Round 902 (Div. 2) C. Joyboard 规律

Codeforces Round 902 (Div. 2) C. Joyboard //思路:在k=1,k=2,k=3 时有解 //当 k=1 时为全0 //当 k=2 时,若 m>=n,则先是 0 然后为 1~n,最后一位可以为n的倍数也符合,即n+m/n-1 //若m<n则为 1~m 即 m / ......
Codeforces Joyboard 规律 Round 902

Codeforces Round 726 (Div. 2) B. Bad Boy

给一个 \(n \times m\) 的平面,一个初始位置 \((i, j)\) 。 需要放两个废弃物在平面上,位置为 \((x_1, y_1), (x_2, y_2)\) 。 使得从 \((i, j)\) 出发,捡起两个废弃物后,回到原位置,所经过的曼哈顿距离最长。 询问一组合法的 \((x_1, ......
Codeforces Round 726 Bad Boy

Codeforces Round 902 (Div. 2, based on COMPFEST 15 - Final

Codeforces Round 902 (Div. 2, based on COMPFEST 15 - Final A. Goals of Victory 解题思路: 答案为所有元素之和的负数。 代码: #include <bits/stdc++.h> using namespace std; u ......
Codeforces COMPFEST Round Final based

【题解】CodeForces-1876/1877

CodeForces-1877A Goals of Victory 答案是 \(-\sum_{i=1}^{n-1} a_i\)。 提交记录:Submission - CodeForces CodeForces-1876A Helmets in Night Light 按 \(b_i\) 排序,贪心取 ......
题解 CodeForces 1876 1877

Codeforces Round 902 (Div. 2, based on COMPFEST 15 - Final Round)

Preface 难得这么好时间的CF,我直接找来队友组队练题 当然比赛的过程没有三人三机,就跟平时训练一样搞了个新号三人一机的写 中间因为溜去先看F了导致E题留给徐神solo因此出的偏慢,不过后面一起讨论了一下还是出了 最后开F结果好家伙我和祁神双双看错题,对着假题意苦战1h最后无奈投降,今天去再看 ......
Round Codeforces COMPFEST Final based

Codeforces Round 902 (Div. 2, based on COMPFEST 15 - Final Round)

比赛连接 打着打着吃饭去了,又掉分了! A. Goals of Victory 题意: 一场比赛有n个球队,每一个队伍匹配一次,球队的效率等于球队的得分数减去对手的得分数,给出n-1个数据,让你求出未给出的那个数据。 思路: 所有球队的效率和为0 代码: #include<bits/stdc++.h ......
Round Codeforces COMPFEST Final based

CodeForces 1876D Lexichromatography

洛谷传送门 CF 传送门 这说明你的能力还不足以维持 IM。 显然 balanced 的充要条件是,对于每个值,染色一定是 RB 交替。然后一种值只会有先染红或先染蓝两种情况。 然后还剩下字典序严格小于的条件。我场上的想法是枚举 \(\text{LCP}\),然后推出来一个巨大麻烦做法,根本写不出来 ......
Lexichromatography CodeForces 1876D 1876

Codeforces Round 730 (Div. 2) A. Exciting Bets

给两个正整数 \(a, b\) ,可以执行以下操作之一任意次: \(a = a + 1, b = b + 1\) 。 \(a = a - 1, b = b - 1\) 。 需要保证 \(min(a, b) \geq 0\) 。 询问 \(gcd(a, b)\) 最大是多少,且到达最大 \(gcd(a ......
Codeforces Exciting Round Bets 730

Codeforces Round 902 (Div. 1, based on COMPFEST 15 - Final Round) A~D

A. Helmets in Night Light 首先注意到一个关键性质 \(b_i \geq 1\),这就意味着当我们花 \(p\) 的代价解锁了 \(b_i\) 最小的后,仅凭接下来的“连锁反应”就能解锁全部的点。注意到我们“连锁反应”的一定是按 \(b_i\) 从小到大排序后的一段前缀(因为 ......
Round Codeforces COMPFEST Final based

Codeforces Round 902 (Div. 2) (CF1877) B、C、D 题解

B 题目大意 你要传话给 \(n\) 个人,每传一下话需要花费 \(p\) ,当一个人被传话后,他可以最多传给 \(a_i\) 个人,每次花费 \(b_i\) 。问把话传给 \(n\) 个人的最小花费。 分析 首先传给第一个人只少要 \(p\) 下来贪心,每次让花费最小、且能够传话的人去传话。 考虑 ......
题解 Codeforces Round 1877 902

Codeforces Round 902 Div. 2 - A B C D

目录A. Goals of VictoryB. Helmets in Night Light 传送门 A. Goals of Victory 对给定 n - 1 组队伍的净得分求和取负即为最后一组队伍的净得分 B. Helmets in Night Light 赛时想法假了,赛后更正 对所有人按照传 ......
Codeforces Round 902 Div