![](https://img-blog.csdnimg.cn/20201014180756925.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
思维
Dejavu1z
做题,总结,不断的学习
展开
-
codeforces 1417C(思维)
题意描述思路使用一个vector数组来存储每个数字对应的下标,然后对111到nnn进行遍历,统计该数字相邻位置的最大距离,该距离即为子段长度为kkk时共用的数字。发现,长度为nnn的子段一定包含长度为n−1n-1n−1的子段,所以最后再遍历一遍,使res[i]=min(res[i],res[i−1])res[i]=min(res[i],res[i-1])res[i]=min(res[i],res[i−1])。AC代码#include<bits/stdc++.h>#define x f原创 2020-09-28 11:45:28 · 257 阅读 · 0 评论 -
codeforces 1335E1+E2(思维)
题意描述思路+代码easy版本:我们只需要枚举[1,i],[i+1,j],[j+1,n][1,i],[i+1,j],[j+1,n][1,i],[i+1,j],[j+1,n]三个区间即可,设lenlrlenlrlenlr为第一个和第三个区间中出现最多的数字的次数,lenmidlenmidlenmid为第二个区间中出现最多数字的次数,则ans=max(ans,lenlr∗2+lenmid)ans=max(ans,lenlr*2+lenmid)ans=max(ans,lenlr∗2+lenmid)。我们可原创 2020-09-25 22:11:04 · 201 阅读 · 0 评论 -
codeforces 1213D2(贪心+思维)
题意可以对每个数进行除2的操作,求最少需要操作多少次,使得数组中有k个相同的数思路题目中说答案始终存在,因为每个数都可以变成0,但很明显,让数字变成0的情况是不存在的,每个数字不停的除2肯定可以变成1,如果变成0,肯定不是最优解。我们可以使用一个cntcntcnt数组来记录每个数字出现的次数,使用tottottot数组来记录变成该数需要的次数,因为数据范围最大是2∗1052*10^52∗105,每个数字除2不超过20次就可以变成1,我们遍历一遍数组即可得到答案。AC代码#include<bi原创 2020-09-19 08:17:33 · 192 阅读 · 0 评论 -
codeforces 1328D(思维)
题意描述The round carousel consists of n figures of animals. Figures are numbered from 1 to n in order of the carousel moving. Thus, after the n-th figure the figure with the number 1 follows. Each figure has its own type — the type of the animal correspondin原创 2020-09-16 08:09:19 · 170 阅读 · 0 评论 -
codeforces 1311D(暴力)
题意描述You are given three integers a≤b≤c.In one move, you can add +1 or −1 to any of these integers (i.e. increase or decrease any number by one). You can perform such operation any (possibly, zero) number of times, you can even perform this operation seve原创 2020-09-15 21:47:28 · 138 阅读 · 0 评论 -
codeforces 1367D(思维)
题意描述Polycarp wrote on the board a string s containing only lowercase Latin letters (‘a’-‘z’). This string is known for you and given in the input.After that, he erased some letters from the string s, and he rewrote the remaining letters in any order. As原创 2020-09-15 20:47:57 · 131 阅读 · 0 评论 -
codeforces1294D(思维+暴力)
题意描述Recall that MEX of an array is a minimum non-negative integer that does not belong to the array. Examples:for the array [0,0,1,0,2] MEX equals to 3 because numbers 0,1 and 2 are presented in the array and 3 is the minimum non-negative integer not pre原创 2020-09-15 16:04:19 · 170 阅读 · 0 评论 -
codeforces 1203D1(暴力)
题意描述给定两个字符串s和t,s中包含t的子串,求最大删除的区间的长度,使得t仍是s的子串思路由于数据范围很小,所以我们暴力枚举删除字符的左右边界,统计长度即可AC代码#include<bits/stdc++.h>#define x first#define y second#define PB push_back#define mst(x,a) memset(x,a,sizeof(x))#define all(a) begin(a),end(a)#define rep(x原创 2020-09-08 15:29:09 · 106 阅读 · 0 评论 -
codeforces 1405B(思维)
题意描述You’re given an array a of n integers, such that a1+a2+⋯+an=0.In one operation, you can choose two different indices i and j (1≤i,j≤n), decrement ai by one and increment aj by one. If i<j this operation is free, otherwise it costs one coin.How ma原创 2020-09-07 14:52:10 · 266 阅读 · 0 评论 -
codeforces 1234C(思维)
题意描述一个管道有6种类型,两种直管四种弯管,可以将管道任意旋转,给定t个询问,回答每次是否可以从(0,0)到哪(1,n)。思路通过观察可以发现,如果是直管的话,只能向右移动。如果是弯管的话,需要保证同一位置的另一排也是弯管,否则移动失败。AC代码#include<bits/stdc++.h>#define x first#define y second#define PB push_back#define mst(x,a) memset(x,a,sizeof(x))#def原创 2020-09-06 15:19:00 · 268 阅读 · 0 评论 -
codeforces 1399D
题意描述You are given a binary string s consisting of n zeros and ones.Your task is to divide the given string into the minimum number of subsequences in such a way that each character of the string belongs to exactly one subsequence and each subsequence loo原创 2020-08-07 08:37:45 · 248 阅读 · 0 评论 -
codeforces1322A(括号匹配)
题意描述A bracketed sequence is called correct (regular) if by inserting “+” and “1” you can get a well-formed mathematical expression from it. For example, sequences “(())()”, “()” and “(()(()))” are correct, while “)(”, “(()” and “(()))(” are not.The teach原创 2020-08-03 20:51:39 · 178 阅读 · 0 评论 -
codeforces 1040B(思维)
题意描述有n个煎饼,每次可以反转会反转左右k个,求最小反转次数思路如果k为0的话,每个煎饼一定需要反转。如果nnn能够整除2∗k+12*k+12∗k+1的话,那么每次都加2∗k+12*k+12∗k+1一定不会重叠,否则的话,我们可以先对余数的情况进行输出,然后就转换成了整除的状态。AC代码#include<bits/stdc++.h>#define x first#define y second#define PB push_back#define mst(x,a) memse原创 2020-08-02 21:14:11 · 160 阅读 · 0 评论 -
codeforces 1144D(思维)
题意描述You are given an array a consisting of n integers. You can perform the following operations arbitrary number of times (possibly, zero):Choose a pair of indices (i,j) such that |i−j|=1 (indices i and j are adjacent) and set ai:=ai+|ai−aj|;Choose a pa原创 2020-07-28 16:17:14 · 376 阅读 · 0 评论 -
codeforces 1384A(构造)
题意描述The length of the longest common prefix of two strings s=s1s2…sn and t=t1t2…tm is defined as the maximum integer k (0≤k≤min(n,m)) such that s1s2…sk equals t1t2…tk.Koa the Koala initially has n+1 strings s1,s2,…,sn+1.For each i (1≤i≤n) she calculated原创 2020-07-25 08:21:38 · 258 阅读 · 0 评论 -
codeforces 509B(构造,思维)
题意描述There are n piles of pebbles on the table, the i-th pile contains a i pebbles. Your task is to paint each pebble using one of the k given colors so that for each color c and any two piles i and j the difference between the number of pebbles of color c原创 2020-07-23 16:14:48 · 148 阅读 · 0 评论 -
codeforces 1382C1(思维)
题目描述This is the easy version of the problem. The difference between the versions is the constraint on n and the required number of operations. You can make hacks only if all versions of the problem are solved.There are two binary strings a and b of lengt原创 2020-07-22 09:59:30 · 401 阅读 · 0 评论 -
codeforces 224B(思维+双指针)
题意描述给定n个数字,求一段区间l,r,要求r-l+1最小,且区间内有k个不同的数思路由于区间内有k个不同的数,所以r-l+1至少为k。所以可以找到第一个r,然后再从r开始向左找l,找到的区间l和r即为答案AC代码#include<iostream>#include<string>#include<cstring>#include<cstdio>#define x first#define y second#define PB push_原创 2020-07-20 17:57:26 · 205 阅读 · 0 评论 -
codeforces 1066B(树)
题意描述Ramesses knows a lot about problems involving trees (undirected connected graphs without cycles)!He created a new useful tree decomposition, but he does not know how to construct it, so he asked you for help!The decomposition is the splitting the ed原创 2020-07-14 15:25:43 · 174 阅读 · 0 评论 -
蚂蚁(思维)
题意描述有许多蚂蚁在一根无限长的木棍上,每一只蚂蚁都有一个初始位置和初始朝向(任意两只蚂蚁的初始位置不同)。蚂蚁们以每秒一个单位的速度向前移动,当两只蚂蚁相遇时,它们会掉头(掉头时间忽略不计)。现给出每只蚂蚁的初始位置和初始朝向,请你计算出它们在 t 秒后的位置和朝向。思路通过观察我们可以发现两个性质:1.如果两只蚂蚁碰头以后,我们可以不让他们掉头,而是交换两只蚂蚁的灵魂,让他们继续往前走2.在限定秒速走完以后,每个蚂蚁仍是按照初始时的顺序排列明白这两个性质后就容易想了,我们可以先按初始位置排序原创 2020-07-08 18:08:13 · 609 阅读 · 0 评论