题意:有一排座位,要求每人之间隔\(k\)个座位坐,\(1\)代表已做,\(0\)代表空座,问最多能坐几人. 题解:我们分别从前和从后跑个前缀和,将已经有人坐的周围的位置标记,然后遍历求每一段连续的\(0\),对于每一段最多能坐\(\lceil len/(k+1) \rceil\),求个和就可. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #inc…
题目链接:https://codeforces.com/contest/1367/problem/C 题意 给出一个长为 $n$ 的 $01$字符串,两个相邻 $1$ 间距应大于 $k$,初始序列合法,问最多能再使多少 $0$ 变为 $1$ . 题解 如果当前字符为 $0$,查找 $k$ 个距离内是否有 $1$: 若有则不合法,跳至最近的 $1$ 否则因为 $k$ 个距离内没有 $1$,当前字符置为 $1$,跳至第 $i + k$ 个字符 如果当前字符为 $1$,因为初始序列合法,下一个可以置为…
B. Hamming Distance Sum 题目连接: http://www.codeforces.com/contest/608/problem/A Description Genos needs your help. He was asked to solve the following programming problem by Saitama: The length of some string s is denoted |s|. The Hamming distance betw…
链接: https://codeforces.com/contest/1234/problem/B2 题意: The only difference between easy and hard versions are constraints on n and k. You are messaging in one of the popular social networks via your smartphone. Your smartphone can show at most k most…
B. Hamming Distance Sum   Genos needs your help. He was asked to solve the following programming problem by Saitama: The length of some string s is denoted |s|. The Hamming distance between two strings s and t of equal length is defined as , where si…
题目链接:https://codeforces.com/contest/1367/problem/B 题意 有一大小为 $n$ 的数组 $a$,问能否经过交换使所有元素与下标奇偶性相同(0 - indexed). 题解 奇偶性不同的奇数和偶数个数应相等. 代码 #include <bits/stdc++.h> using namespace std; void solve() { int n; cin >> n; int odd = 0, even = 0; for (int i…
题目链接:https://codeforces.com/contest/1367/problem/A 题意 给出一个字符串 $t$,找出原字符串 $s$,$t$ 由 $s$ 从左至右的所有长为 $2$ 的子串构成. 题解 只有 $s$ 的首尾字符会只在 $t$ 中出现一次,其余字符都会重复出现两次. 代码 #include <bits/stdc++.h> using namespace std; void solve() { string s; cin >> s; int n =…
题意:给你\(n\)个数,每次可以使某个数++,--,或使某个数--另一个++,分别消耗\(a,r,m\).求使所有数相同最少的消耗. 题解:因为答案不是单调的,所以不能二分,但不难发现,答案只有一个峰,所以我们可以三分高度,然后写个check函数贪心一下即可. 代码: #include <iostream> #include <cstdio> #include <cstring> #include <cmath> #include <algorith…
题意:有一组数,每次操作可以将某个数移到头部或者尾部,问最少操作多少次使得这组数非递减. 题解:先离散化将每个数映射为排序后所对应的位置,然后贪心,求最长连续子序列的长度,那么最少的操作次数一定为\(n-len\). 感觉不好解释,直接上图,其实就是排序后它们一定是连续的,所以我们就求一个最长的连续的,然后s剩下的数移到头部尾部,贪心的想,这样一定是最优解. 代码: #include <iostream> #include <cstdio> #include <cstring…
题意:有一个字符串,要求使用其中字符构造一个环(不必全部都用),定义一个环是k美的,如果它转\(k\)次仍是原样,现在给你\(k\),要求最长的k美环的长度. 题解:我们首先看\(k\),如果一个环转\(k\)的因子次是美的,那么\(k\)次也一定是美的,然后再看环,假如一个环最少转\(d\)次是美的,那么这个环的长度\(n\)一定能被\(d\)整除.也就是这个环有\(d\)种不同的数,每种数有\(n/d\)个.其实也就可以把看作是一个循环节构成的,画一画也就知道了. 代码: #include…