codeforces
文章平均质量分 61
追风者_
要我自我介绍,挺秃然的
展开
-
E2. Array and Segments (Hard version) 思维 线段树区间最值维护
题意:给你若干区间,选出若干区间,对其区间内元素值-1,使得最后序列最大-最小的值最大思路:首先一点,枚举每个aia_iai当最大值,那么所有不包括i这个位置的区间都选上,让它们去减。然后询问一次区间最小值mi,a[i]-mi就是当前枚举得到的一个解,每次比较更新答案即可。上面的操作可以用线段树维护,我们可以先对所有区间-1,同时预处理出以i位置为区间L,R端点的区间,然后遍历1->n的点,每一次,把以i这个位置为左端点的区间+1回来,然后询问区间最值,完了后,对以i这个点为右端点的区间再-1原创 2021-07-30 16:34:14 · 118 阅读 · 0 评论 -
Codeforces Round #710 (Div. 3) ABCDE 题解
我的博客园传送门,看的方便些A. Strange Table签到题,算出对应行列即可。view code#include<iostream>#include<string>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<map>#include <queue>#include<s原创 2021-03-26 00:54:21 · 492 阅读 · 0 评论 -
Codeforces Round #708 (Div. 2) ABC1C2题解
A. Meximization我的博客园传送门,看到方便些第i位优先放等于i-1的,没有的话就后面随便填了。view code#include<iostream>#include<string>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<map>#include <queue>#i原创 2021-03-18 00:36:59 · 150 阅读 · 0 评论 -
Codeforces Round #706 (Div. 2) D. Let‘s Go Hiking 博弈 思维
思路:A要赢的大前提就是当前x是一个波峰。因为如果是一个直线单调的话如1 2 3 4 5(或者5 4 3 2 1),不管A选哪个位置,B直接在他下一个位置封死,A就直接GG。现在考虑波峰的时候,那A就有两条路可以走,走左边或者走右边都可以(这个时候B就不能直接封死A了)。但是如果B能在别的地方挑一条比这两条路还长的路,那A还是输。当B选不到更长的路的时候,就会尽量的恶心A,走两条路中较长的那一条,这个时候A走较短的话必输,所以AB这时候必须相向而行。这个时候这条路的长度是奇数的话A就能赢了,且是唯一的一原创 2021-03-10 23:01:54 · 471 阅读 · 3 评论 -
Codeforces Global Round 13 ABC题解
我的博客园传送门,看的方便些A. K-th Largest Value思路:操作就是0变1,1变0。那么只用统计1有多少个就知道第x大是谁了。view code#include<iostream>#include<string>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<map>#include原创 2021-03-01 00:40:24 · 2268 阅读 · 3 评论 -
Codeforces Round #699 (Div. 2) ABC题解
我的博客园传送门,看的方便点A. Space Navigation思路:分别统计往px和py方向的步数,看看能不能分别大于等于px和py。view code#include<iostream>#include<string>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<map>#include &原创 2021-02-06 00:42:24 · 510 阅读 · 1 评论 -
Codeforces Round #697 (Div. 3) ABCDE 题解
=>我的博客园传送门,阅读更方便<=久违的cf服务器爆炸场A. Odd Divisor思路:任何一个数都可以写成n=k2m,其中k是一个奇数n = k2^m,其中k是一个奇数n=k2m,其中k是一个奇数,若k=1,那么n就一定是一个2的幂。view code#include<iostream>#include<string>#include<algorithm>#include<cstdio>#include<cstrin原创 2021-01-26 11:29:57 · 283 阅读 · 0 评论 -
Codeforces Round #695 (Div. 2) B. Hills And Valleys 思维
思路:这个题一开始为了考虑出所有可能的情况写的很麻烦。。。比如考虑改变当前点后对两端波峰波谷的影响之类的。后来发现其实就一个思路:最优策略肯定是,当前这个点要么变成左端点一样的值,要么和右端点相等(a[i]=a[i−1]或者a[i]=a[i+1]a[i]=a[i-1]或者a[i]=a[i+1]a[i]=a[i−1]或者a[i]=a[i+1]),因为改变这个点最多只会影响相邻的两个点的状态,所以先记录没改之前[i-1,i+1]的波峰波谷个数,再看两次改变之后的波峰波谷个数,两次取个最小的(就是能消除掉最多的原创 2021-01-09 11:35:16 · 1293 阅读 · 0 评论 -
Codeforces Round #693 (Div. 3) ABCDE题解
A. Cards for Friends思路:折纸游戏,看长宽能各折多少次,就是2的几次方,相乘即可。view code#include<iostream>#include<string>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<map>#include <queue>#inclu原创 2021-01-05 00:52:08 · 588 阅读 · 2 评论 -
Codeforces Round #690 (Div. 3) ABCDE题解
我的博客园传送门A. Favorite Sequence思路:照着模拟即可。view code#include<iostream>#include<string>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<map>#include <queue>#include<sstr原创 2020-12-16 10:04:22 · 297 阅读 · 1 评论 -
Codeforces Round #688 (Div. 2) ABC题解
A. Cancel the Trains签到题,看两边有无相同相对位置出发的,加入计数即可。view code#include<iostream>#include<string>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<map>#include <queue>#include<原创 2020-12-04 23:43:12 · 349 阅读 · 0 评论 -
Codeforces Round #682 (Div. 2) ABC 题解
A. Specific Tastes of Andre题意:构造一个长度为n且任意子串和整除其长度的序列。思路:n个1就行。view code#include<iostream>#include<string>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<map>#include <queu原创 2020-11-14 09:53:39 · 261 阅读 · 0 评论 -
Gym 101466 E - Text Editor KMP + 二分答案
题意:给你一个主串和模式串,找出模式串最大的前缀,使得其在主串中的出现次数大于等于n。思路:首先会想到KMP。但是如果直接拿模式串一位一位匹配是O(n2)的时间复杂度,肯定过不了。我们发现模式串长度越长,越不容易满足要求。所以这里有个单调性,可以来二分。我们二分答案可能的长度,然后用这么长的前缀丢进KMP里面,看看能否满足,如果发现可以,就把长度调大一点,反之调小一点。时间复杂度O(nlogn)。最后注意KMP用来计数时,每次匹配完不能直接j=0, i -= p.size(),因为这样会使得指针回溯原创 2020-10-13 13:34:55 · 214 阅读 · 0 评论 -
Educational Codeforces Round 96 ABCDE 题解(详解)
我的博客园传送门,看起来更方便些A. Number of Apartments题意:用3、5、7凑数,若能凑出给出方案,不能则输出-1。思路:观察发现除了1 2 4凑不到以外其他都凑得到。那么关于方案的话,既然其他数都凑得到,我们就可以用dp的思想每次试探着来,若减去当前数还是个可以凑得到的就继续减直到等于0。view code#include<iostream>#include<string>#include<algorithm>#include<原创 2020-10-12 22:08:22 · 298 阅读 · 0 评论 -
Codeforces Round #674 (Div. 3) ABCD 题解
A. Floor Number题意:一开始的数为2,问加多少次x才能加到超过n。思路:水题,循环一遍就行。view code#include<iostream>#include<string>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<map>#include <queue>#in原创 2020-09-28 19:40:40 · 403 阅读 · 4 评论 -
Codeforces Round #673 (Div. 2) ABC 题解
博客园传送门A. Copy-paste题意:问在保持每个数都小于等于k的情况下,最多能执行多少步a[j] += a[i] ,其中(i,j)为任意不同下标。思路:水题,排个序,用a[1]去加到别的值上,看每个数能加多少个a[1],累加贡献即可。view code#include<iostream>#include<string>#include<algorithm>#include<cstdio>#include<cstring>原创 2020-09-28 13:29:40 · 308 阅读 · 0 评论 -
Educational Codeforces Round 95 ABC 题解
我的博客园传送门,看起来更方便A. Buying Torches题意:合成一个物品需要一个a和一个b,一开始有一个a。现在有下面两种操作:1.用1个a换x个a。2.用y个a换1个b。问你合成k个物品最少需要多少次操作。思路:水题,先算出一共需要多少个a,然后用这个数除(x-1)上取整得到合成出这么多a需要的次数,再加上k次转化成b的次数即可。view code#include<iostream>#include<string>#include<algori原创 2020-09-15 11:20:03 · 134 阅读 · 0 评论 -
Codeforces Round #669 ABC 题解
A. Ahahahahahahahaha题意:给个一个偶数长度的01序列,要求删除不超过2/n个元素使得奇数位和等于偶数位和。思路:注意到题目给的提示,只有0和1,且为偶数长度。那么对和有贡献的也就只有1,而且0或1总有一个出现次数小于等于n/2。所以我们就有这样的策略,把最后搞的只剩0或者1即可,0的个数小就删0,反之删1。最后注意只保留1的时候还要考虑一下答案数组长度的奇偶性。view code#include<iostream>#include<string>原创 2020-09-09 00:57:34 · 786 阅读 · 0 评论 -
【Codeforces Round #661 (Div. 3)】 ABCD 题解
E题没思路就没搞了。A. Remove Smallest题意:找出最多的绝对值相差不大于1的对,使得剩下只有一个思路:排个序,相邻着取最优,这样还不能就真的不能了AC代码:#include<iostream>#include<string>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#include<map>#i原创 2020-08-06 00:36:12 · 262 阅读 · 1 评论 -
【CodeForces 1156C】 Match Points 二分答案
You are given a set of points x1, x2, …, xn on the number line.Two points i and j can be matched with each other if the following conditions hold:neither i nor j is matched with any other point;|xi−xj|≥z.What is the maximum number of pairs of points yo原创 2020-07-31 12:44:46 · 266 阅读 · 0 评论 -
【Maratona de Programa¸c˜ao da SBC 2019 A】Artwork 并查集 模拟
The Mona Dura is one of the most valuable artworks in Nlogonia Museum. The famous painting isdisplayed in a rectangular room of M by N meters. The room entrance is in a corner of it, while theMona is in the corner diagonally opposite to the entrance.To原创 2020-07-22 18:51:44 · 525 阅读 · 0 评论 -
【Maratona de Programa¸c˜ao da SBC 2019 M】 Maratona Brasileira de Popcorn 二分答案
The “Maratona Brasileira de Popcorn” is a competition that takes place annually to find out whichteam is the most organized, prepared and well-trained in the art of eating popcorn. It is organized byBrazilian Society of Popcorn Eaters (SBCp, its acronym原创 2020-07-22 16:36:12 · 338 阅读 · 0 评论 -
Codeforces Round #658 (Div. 2) A - C 超详解
A. Common Subsequence题意:找出一个最短序列,里面的元素在AB数组里都出现过,若没有则输出NO思路:Map一下A数组里的东西,B遇到一个就输出就行。B搞完都没有的话就说明没有了AC代码:#include<iostream>#include<string>#include<algorithm>#include<cstdio>#include<cstring>#include<cmath>#inclu原创 2020-07-22 00:43:24 · 536 阅读 · 0 评论 -
【Codeforces Round #647 (Div. 2)】 A - C 题解
A. Johnny and Ancient Computer题意:问a能否通过乘除2 4 8达到b思路:因为要是能除的尽才除,所以乘除两个过程是对称的。我们只需要看看大的能不能按顺序除完8 4 2后只剩下1即可(代表大的能到小的,且步数最少)。AC代码:#include<iostream>#include<string>#include<algorithm>#include<cstdio>#include<cstring>#inc原创 2020-07-11 20:37:32 · 142 阅读 · 0 评论 -
【Codeforces Round #651 (Div. 2)】 D. Odd-Even Subsequence 二分答案
Ashish has an array a of size n.A subsequence of a is defined as a sequence that can be obtained from a by deleting some elements (possibly none), without changing the order of the remaining elements.Consider a subsequence s of a. He defines the cost of原创 2020-07-10 22:58:31 · 234 阅读 · 1 评论 -
【暑训排位 #D】Gym - 100952H 动态规划DP
A sequence of positive and non-zero integers called palindromic if it can be read the same forward and backward, for example:15 2 6 4 6 2 1520 3 1 1 3 20We have a special kind of palindromic sequences, let’s call it a special palindrome.A palindromic s原创 2020-07-10 18:55:34 · 185 阅读 · 0 评论 -
【暑训排位赛 #C】Gym - 100952D 简单组合
You have been out of Syria for a long time, and you recently decided to come back. You remember that you have M friends there and since you are a generous man/woman you want to buy a gift for each of them, so you went to a gift store that have N gifts, eac原创 2020-07-10 18:22:38 · 124 阅读 · 0 评论 -
【暑训排位赛 #A】Gym - 100971D 单调栈
One-dimensional country has n cities, the i-th of which is located at the point x i and has population p i, and all x i, as well as all p i, are distinct. When one-dimensional country got the Internet, it was decided to place the main server in the largest原创 2020-07-10 18:08:28 · 165 阅读 · 0 评论 -
【暑训排位 #9 F】 思维
You are given a permutation p of length n. Also you are given m foe pairs (a i, b i) (1 ≤ a i, b i ≤ n, a i ≠ b i).Your task is to count the number of different intervals (x, y) (1 ≤ x ≤ y ≤ n) that do not contain any foe pairs. So you shouldn’t count int原创 2020-07-08 17:45:35 · 172 阅读 · 0 评论 -
【 CodeForces - 96 B 】 Lucky Numbers (easy) 暴力打表
Petya loves lucky numbers. Everybody knows that positive integers are lucky if their decimal representation doesn’t contain digits other than 4 and 7. For example, numbers 47, 744, 4 are lucky and 5, 17, 467 are not.Lucky number is super lucky if it’s dec原创 2020-07-06 21:45:19 · 331 阅读 · 0 评论 -
【Codeforces Round #653 (Div. 3)】 A-D 详解
手速还是慢了点,小细节bug没注意到浪费了一点时间A.Required Remainder题意:找出n以内最大的k使得k%x==y思路:贪心地找靠近n的解,先看看n % x余数是否大于等于y,是的话就用(n/x)*x,不是的话就往前一位(n/x-1)*x。AC代码:#include<iostream>#include<string>#include<algorithm>#include<cstdio>#include<cstring&g原创 2020-06-29 01:04:17 · 196 阅读 · 0 评论 -
【Codeforces】GCD Compression 唯一分解定理 思维
Ashishgup and FastestFinger play a game.They start with a number n and play in turns. In each turn, a player can make any one of the following moves:Divide n by any of its odd divisors greater than 1.Subtract 1 from n if n is greater than 1.Divisors of原创 2020-06-23 12:02:54 · 341 阅读 · 0 评论 -
【CodeForces 782B】 The Meeting Place Cannot Be Changed 二分
The main road in Bytecity is a straight line from south to north. Conveniently, there are coordinates measured in meters from the southernmost building in north direction.At some points on the road there are n friends, and i-th of them is standing at the原创 2020-06-22 12:35:31 · 130 阅读 · 0 评论 -
【CodeForces 577C】 唯一分解定理
Vasya and Petya are playing a simple game. Vasya thought of number x between 1 and n, and Petya tries to guess the number.Petya can ask questions like: “Is the unknown number divisible by number y?”.The game is played by the following rules: first Petya原创 2020-06-22 11:13:16 · 263 阅读 · 0 评论 -
【CodeForces 577B】 Modulo Sum 鸽巢(抽屉)原理 DP
You are given a sequence of numbers a1, a2, …, an, and a number m.Check if it is possible to choose a non-empty subsequence aij such that the sum of numbers in this subsequence is divisible by m.InputThe first line contains two numbers, n and m (1 ≤ n ≤原创 2020-06-21 23:52:22 · 349 阅读 · 0 评论 -
【CodeForces 682A 】Alyona and Numbers 思维
After finishing eating her bun, Alyona came up with two integers n and m. She decided to write down two columns of integers — the first column containing integers from 1 to n and the second containing integers from 1 to m. Now the girl wants to count how m原创 2020-06-20 22:15:31 · 266 阅读 · 0 评论 -
【CodeForces 676C 】 Vasya and String 二分法
High school student Vasya got a string of length n as a birthday present. This string consists of letters ‘a’ and ‘b’ only. Vasya denotes beauty of the string as the maximum length of a substring (consecutive subsequence) consisting of equal letters.Vasya原创 2020-06-20 14:21:25 · 164 阅读 · 0 评论 -
【CodeForces 676B 】 Pyramid of Glasses DFS模拟
Mary has just graduated from one well-known University and is now attending celebration party. Students like to dream of a beautiful life, so they used champagne glasses to construct a small pyramid. The height of the pyramid is n. The top level consists o原创 2020-06-20 13:26:08 · 203 阅读 · 0 评论 -
【CodeForces 304A 】Pythagorean Theorem II 高斯素数 高效算法
In mathematics, the Pythagorean theorem — is a relation in Euclidean geometry among the three sides of a right-angled triangle. In terms of areas, it states:In any right-angled triangle, the area of the square whose side is the hypotenuse (the side oppos原创 2020-06-19 15:49:49 · 280 阅读 · 0 评论 -
【CodeForces 550C 】Divisibility by Eight DFS 数学
You are given a non-negative integer n, its decimal representation consists of at most 100 digits and doesn’t contain leading zeroes.Your task is to determine if it is possible in this case to remove some of the digits (possibly not remove any digit at al原创 2020-06-19 11:01:40 · 176 阅读 · 0 评论