[codeforces1234F]Yet Another Substring Reverse 题目链接 大致题意为将某个子串进行翻转后,使得不包含相同字符的字符子串长度最长。只能翻转一次或零次。 设一个子串的状态为包含字符的二进制。如子串为abacdabacd,则状态为0000000000000000111100000000000000001111。 根据分析可以得到,一个子串和另一个子串如果没有交集,则...
Codeforces - Pair of Numbers 题目链接:Codeforces - Pair of Numbers 不难发现,如果我们枚举区间的每个值作为区间的gcd,那么左右端点是具有二分性的, 然后二分即可。 然后ST表维护区间gcd AC代码:...B - Pair of Topics CodeForces – 1324D The next lecture in a high school requires two topics to ...
string https://codeforces.com/contest/1316/problem/B 题意:给出一个序列,给出操作规则:让我们确定一个k值,然后翻转i,i+k-1,遍历完整个数组; 找出操作结束后字典序最小的序列的k值; 思路:在几遍演算之后可以发现,某一k值下的翻转,都是分成两部分序列,后面的序列移到前面,前面的序列移到后面; 但是后面的...
#include<iostream> #include<cstring> #include<algorithm> #include<cmath> using namespace std; typedef long long ll; int m[111][111]; const int maxn =1e5 + 10; int id[maxn]; int main() { int t; cin>>t; while(t--) { int n; cin>>n; string s; cin>>s; int cnt=0; int...
http://codeforces.com/contest/1360/problem/A 题意: 用最小正方形,容下两个相同矩形。 #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; typedef long long ll; int main() { int t; ...
Codeforces1110B. Tape http://codeforces.com/problemset/problem/1110/B题意:一个长为m的木棍,有n个缺口,你最多可以用k个长条补缺口,问用来补缺口的长条最短是多少。 方法:想象先用最长的m长度补好1~m位置,然后将最大的k-1个非缺口段挖去,就是答案。一开始想二分:一次最长使用长度为x的用来补的长条,...
You are given a string ss consisting of nn lowercase Latin letters. Let's define a substring as a contiguous subsegment of a string. For example, "acab" is a substring of "abacaba" (it starts in position 33and ends in position 66), but "aa" or "d" aren't substrings of this str...
string ans = s;intnow =0;for(inti =1; i <= k; i++) {for(intj = a[i]; j <= b[i]; j++){ now += cnt[j];//前缀和if(now &1) {//是奇数就翻转ans[j-1] = s[a[i]+b[i] - j-1]; } } } cout << ans; ...
#include<string> #include<cstdio> #include<algorithm> #include<vector> #include<cmath> #define ll long long #define maxn 2000000 using namespace std; ll a[maxn]; int n; ll sum[25][2]; void build(int dep,int L, int R) { if (dep == 0){ sum[dep][0] = sum[dep][1] =...
codeforces 首先我们发现,因为可以在任意地方翻转,所以最后的答案就是一个合法子串和他的补集的子集中个数和最大的那个 因此我们先枚举每一个合法状态,记录他的合法个数有几个。 然后我们从头枚举每一个状态,计算状态的子集中的最大个数。 这样我们最后只要枚举状态和补集,就能计算出真正的答案了 ...