D. Binary String Minimizing You are given a binary string of length n (i. e. a string consisting of n characters '0' and '1'). In one move you can swap two adjacent characters of the string. What is the lexicographically minimum possible string you c…
You are given a binary string of length nn (i. e. a string consisting of nn characters '0' and '1'). In one move you can swap two adjacent characters of the string. What is the lexicographically minimum possible string you can obtain from the given o…
题目链接:https://codeforces.com/contest/1265/problem/A 题意 给出一个由 a, b, c, ? 组成的字符串,将 ? 替换为 a, b, c 中的一个字母,问能否字符串中所有相邻字母都不同. 题解 除非一开始字符串就不合法,否则一定可以构造出合法的字符串,因为共有三个字母可选,而替换时最多需要判断前后两个位置. 代码 #include <bits/stdc++.h> using namespace std; void solve() { strin…
B. Minimize the Permutation You are given a permutation of length n. Recall that the permutation is an array consisting of n distinct integers from 1 to n in arbitrary order. For example, [2,3,1,5,4] is a permutation, but [1,2,2] is not a permutation…
题目传送门 /* 题意:找到一个字符串p,使得它和s,t的不同的总个数相同 贪心:假设p与s相同,奇偶变换赋值,当是偶数,则有答案 */ #include <cstdio> #include <algorithm> #include <cstring> #include <cmath> #include <iostream> using namespace std; ; const int INF = 0x3f3f3f3f; int p[MAXN…
Codeforces Round #598 (Div. 3)- E. Yet Another Division Into Teams - 动态规划 [Problem Description] 给你\(n\)个数,将其划分为多组,对于每个组定义其\(d\)值为 组内的最大值减最小值,问如何划分使得最终所有组的\(d\)值之和最小.每个组至少要保证有\(3\)个数. [Solution] 将所有值从小到大排序,然后我们知道最多有\(5\)个人划分到同一组中,如果有\(6\)个人,那么划分为两组一定比…
https://codeforces.com/contest/1256 A:Payment Without Change[思维] 题意:给你a个价值n的物品和b个价值1的物品,问是否存在取物方案使得价值为s 题解:min(s/n,a)*n+b>=s?YES:NO #include<iostream> #include<cstdio> #include<cstdlib> #include<cmath> #include<algorithm>…
传送门 A. Payment Without Change 签到. Code /* * Author: heyuhhh * Created Time: 2019/11/4 21:19:19 */ #include <bits/stdc++.h> #define MP make_pair #define fi first #define se second #define sz(x) (int)(x).size() #define all(x) (x).begin(), (x).end() #d…
A. Payment Without Change   #include<bits/stdc++.h> using namespace std; #define int long long #define N 100500 int arr[N]; signed main(){ int _; cin>>_; while(_--){ int a,b,n,s; cin>>a>>b>>n>>s; int y=s/n; int x=min(a,…
Codeforces Round #297 (Div. 2)C. Ilya and Sticks Time Limit: 2 Sec  Memory Limit: 256 MBSubmit: xxx  Solved: 2xx 题目连接 http://codeforces.com/contest/525/problem/C Description In the evening, after the contest Ilya was bored, and he really felt like ma…
题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cstdio> #include<cstring> #include<cmath> #include<string> #include<set> #include<map> #include<vector> #include<qu…
B. Equidistant String Time Limit: 20 Sec  Memory Limit: 256 MB 题目连接 http://codeforces.com/contest/545/problem/B Description Little Susie loves strings. Today she calculates distances between them. As Susie is a small girl after all, her strings conta…
E. Binary Numbers AND Sum 题目链接:https://codeforces.com/contest/1066/problem/E 题意: 给出两个用二进制表示的数,然后将第二个二进制不断地往右边移一位,每次答案加上这两个的交集,求最后的答案. 题解: 考虑第二个二进制每一位对答案的贡献就行了,然后对第一个二进制算前缀和就ok了. 代码如下: #include <bits/stdc++.h> using namespace std; typedef long long l…
[Link]:http://codeforces.com/contest/828/problem/C [Description] 让你猜一个字符串原来是什么; 你知道这个字符串的n个子串; 且知道第i个字符t[i],在k[i]个位置出现过; 且告诉你这k[i]个位置在哪里; 数据不会产生矛盾; 让你输出最终的字符串,输出字典序最小的那个; [Solution] 对于输入的n个子串; 对于每个位置; 看看那个位置有没有子串之前出现过,没有的话,就放在那个位置; 否则,如果当前这个子串ti的长度比原…
链接: https://codeforces.com/contest/1265/problem/A 题意: A string is called beautiful if no two consecutive characters are equal. For example, "ababcb", "a" and "abab" are beautiful strings, while "aaaaaa", "abaa&…
题目链接:https://codeforces.com/contest/1385/problem/D 题意 一个小写字母串称为 $c-good\ string$,如果至少满足以下条件之一: 字符串长度为 $1$,包含字母 $c$ 字符串前一半都为字母 $c$,后一半为 $(c+1)-good\ string$ 字符串后一半都为字母 $c$,前一半为 $(c+1)-good\ string$ 计算将一个长为 $n = 2^k$ 的小写字母串变为 $a-good\ string$ 至少需要替换多少个…
题目链接:https://codeforces.com/contest/1370/problem/E 题意 给出两个长为 $n$ 的 $01$ 串 $s$ 和 $t$,每次可以选择 $s$ 的一些下标,使字符只在这些下标内循环右移一个单位,问两个字符串相等至少需要循环移动多少次. 题解 无解的情况 两个字符串中的 $01$ 个数不同. 有解的情况 将 $s$ 中同一位置与 $t$ 不同的字符拿出组成一个新字符串,每次操作一定是取这个新字符串 $01010 \dots$ 或 $10101 \dot…
Median String time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output You are given two strings ss and tt, both consisting of exactly kk lowercase Latin letters, ss is lexicographically less than …
把字符串看作是26进制的数,从后往前翻译,那么就可以把两个串变成对应的26进制的数字,那么只要把两个数加起来除以二就得到中间的串对应的数了,同理再转化回来就行了.但是这样会有一个问题就是串的长度有2e5,26的2e5次方显然不可求,所以需要对每一位进行手动的加和运算.对于两个串,我们假设a串从后往前的每一位对应的数值为a0, a1, a2...,b串从后往前的每一位对应的数值为b0, b1, b2...对于进制加法,有 扔一下垃圾代码: #include <iostream> #include…
B. Obsessive String   Hamed has recently found a string t and suddenly became quite fond of it. He spent several days trying to find all occurrences of t in other strings he had. Finally he became tired and started thinking about the following proble…
F. Equalizing Two Strings You are given two strings s and t both of length n and both consisting of lowercase Latin letters. In one move, you can choose any length len from 1 to n and perform the following operation: Choose any contiguous substring o…
You are given two strings ss and tt both of length nn and both consisting of lowercase Latin letters. In one move, you can choose any length lenlen from 11 to nn and perform the following operation: Choose any contiguous substring of the string ss of…
题:https://codeforces.com/contest/1256/problem/E 题意:给一些值,代表队员的能力值,每组要分3个或3个以上的人,然后有个评价值x=(队里最大值-最小值),问最小的∑x是多少,以及输出方案 学习粗:https://www.cnblogs.com/Lubixiaosi-Zhaocao/p/11797744.html dp路径转移 #include<bits/stdc++.h> using namespace std; ; struct node{ in…
传送门 题意: 你需要输出一个长度为n的字符序列(由小写字母组成),且这个字符串中至少包含k个不同的字符.另外题目还有要求:给你两个长度为p和q的序列,设字符序列存在s中 那么就会有s[Pi]<=s[P(i+1)]   (i<p) s[Qi]<=s[Q(i+1)]   (i<q)   如果你能找出来满足这些条件的字符串s,就输出YES和s,否则输出NO 这会得到一个非递减字符串 题解: 因为最后的结果是一个非递减字符串,那么肯定对整个字符串s,会有s[i]<=s[i+1] (…
题意:给你两个字符串\(s\)和\(t\),保证\(t\)的字典序大于\(s\),求他们字典序中间的字符串. 题解:我们假设题目给的不是字符串,而是两个10禁止的正整数,那么输出他们之间的数只要把他两加起来除\(2\)就行了,那么对于字符串又为何不可呢?我们可以将每个字母看成\(26\)进制的数,像高精度那样模拟加法运算的过程,然后再模拟除\(2\)的过程即可. 代码: int k; string s,t; int c[N]; int d[N]; int main() { ios::sync_w…
题意:有一个长度为\(n=2^k\)的字符串,对于某个字符\(c\),我们定义他是一个\(c-good\),如果: ​ 1.\(len=1\),并且\(s[1]=c\). ​ 2.\(len>1\),\(s[1]=s[2]=...=s[\frac{len}{2}]=c\),并且另外一半是一个\((c+1)-good\)字符串. ​ 3.\(len>1\),\(s[\frac{len}{2}+1]=s[\frac{len}{2}+2]=...=s[len]=c\),并且另外一半是一个\((c+1…
题意:有两个\(01\)字符串\(a\)和\(b\),每次让\(a\)和\(b\)进行与运算,将值贡献给答案,然后将\(b\)右移一位,直到\(b=0\). 题解:因为\(a\)不变,而\(b\)每次右移一位,所以我们看\(b\)中\(1\)的位置在\(a\)中所对应的位置,从该位置到最低位,所有为\(1\)的位置都要算一次十进制的数贡献给答案,那么为了降低复杂度,很明显,我们使用前缀和,用十进制记录\(a\)中从低位到高位的和,然后再从低位到高位遍历\(b\),累加所有\(1\)位置在\(a\…
题意: 给两个串S,T,问能找出多少的S的(a1,b1)(a2,b2)..(ak,bk),使Sa1---Sb1,...Sak---Sbk都包含子串T,其中k>=1,且(a1,b1)...(ak,bk)互不相交. 比如S = "abacaba",T="aba", 当k=1时,(0,6)满足,还有其他只包含一个aba串的也满足,k-2时,(0,2)(3,6)满足,(0,2)(4,6)也满足,(0,3)(4,6)也满足,所以总共有12种. 解法:dp.先用kmp找出…
E. Yet Another Division Into Teams There are n students at your university. The programming skill of the i-th student is ai. As a coach, you want to divide them into teams to prepare them for the upcoming ICPC finals. Just imagine how good this unive…
C. Platforms Jumping There is a river of width n. The left bank of the river is cell 0 and the right bank is cell n+1 (more formally, the river can be represented as a sequence of n+2 cells numbered from 0 to n+1). There are also m wooden platforms o…