Codeforces 895.D String Mark】的更多相关文章

D. String Mark time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output At the Byteland State University marks are strings of the same length. Mark x is considered better than y if string y is lexi…
一看好像会做的样子,就去做了一下,结果 猝不及防地T掉了 赶紧查了一下,没有死循环,复杂度也是对的,无果,于是翻了题解 题解没看懂,但是找到了标程,然后发现我被卡常了... 而且好像当时还过了前10个点啊..这要真的是比赛稳稳的FST啊 小技巧: 逆元只需要求inv[i]和inv[i!],可以预处理出来 令md=1e9+7 则inv[1]=1 除此外inv[i]=(md-md/i)*inv[md%i]%md 令inv2[i]=inv[i!] 则inv2[n]=pow(n!,md-2) 除此外in…
题目链接:http://codeforces.com/problemset/problem/797/C 题意: 给你一个非空字符串s,空字符串t和u.有两种操作:(1)把s的首字符取出并添加到t的末尾.(2)把t的尾字符取出并添加到u的末尾. 问你当经过一系列操作后,s和t均为空时,字典序最小的u. 题解: 操作的本质: s为队列,t为栈. 贪心思路: (1)找到s中的最小字符c,不断出队并加入t,直至有一次出队的字符等于c,停止出队. (2)当t的尾字符小于等于s中的最小字符时,优先弹出t的尾…
Grigory loves strings. Recently he found a metal strip on a loft. The strip had length n and consisted of letters "V" and "K". Unfortunately, rust has eaten some of the letters so that it's now impossible to understand which letter was…
C. Minimal string 题目链接:http://codeforces.com/problemset/problem/797/C time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Petya recieved a gift of a string s with length up to 105 characters fo…
/** 题目:F. String Compression 链接:http://codeforces.com/problemset/problem/825/F 题意:压缩字符串后求最小长度. 思路: dp[i]表示前i个字符需要的最小次数. dp[i] = min(dp[j]+w(j+1,i)); (0<=j<i); [j+1,i]如果存在循环节(自身不算),那么取最小的循环节x.w = digit((i-j)/x)+x; 否则w = i-j+1; 求一个区间最小循环节: 证明:http://w…
https://codeforces.com/problemset/problem/1117/E 就用abc表示数字来给每个数编码,编完直接问出移动的结果,反构造就行了,比C和D还简单. #include<bits/stdc++.h> using namespace std; #define ll long long int n; string s1,s2,s3; string t; string q1,q2,q3; ]; ]; void construct(){ ;i<n;i++){…
题目链接:http://codeforces.com/contest/828/problem/C 题解:有点意思的题目,可用优先队列解决一下具体看代码理解.或者用并查集或者用线段树都行. #include <iostream> #include <cstring> #include <queue> #include <vector> #include <cstdio> #include <map> #include <strin…
题目链接:http://codeforces.com/contest/779/problem/D 题意:给你一段操作序列,按顺序依次删掉字符串1中相应位置的字符,问你最多能按顺序删掉多少个字符,使得s2是剩下的字符构成的字符串的子列. 字符串长度为2e5每次查询的时间复杂度为n如果直接暴力那么复杂度就是n*n 如果二分一下答案的话复杂度就是n*logn再加上修改的复杂度总的复杂度是 (n+n)* logn #include <iostream> #include <cstring>…
http://www.codeforces.com/problemset/problem/494/B 题意:给出两个串S,T,求有几种将S分成若干个子串,满足T都是这若干个子串的子串. 思路:f[n]代表前n个字符来划分,有多少种划分方式,sum[i]代表1到i的f的和,转移就是:对于i这个位置,可以不选,因此首先 f[i]=f[i-1],然后若是选了i,那一定至少是在有匹配位置的左边开始匹配,假设L为小于i的最右边的匹配位置,则 F[i]+=ΣF[j] (1<=j<=L-1),然后也有可能自…
Codeforces 710 F 思路:KMP学的还是不过关啊... 按照字符串的长度分类,如果长度大于\(\sqrt{n}\)的就扔到什么地方等待查询,否则就扔进trie里面. 对于查询,我们先在trie树中暴力找有多少出现过的子串,因为trie中长度不超过\(\sqrt{n}\),那么这个操作总共不会超过\(n\sqrt{n}\)次. 然后对于每一个长度大于\(\sqrt{n}\)的,把kmp的fail数组构造出来,暴力在待查询串中查询出现次数.因为长度大于\(\sqrt{n}\)的不会超过…
ou should process m queries over a set D of strings. Each query is one of three kinds: Add a string s to the set D. It is guaranteed that the string s was not added before. Delete a string s from the set D. It is guaranteed that the string s is in th…
Ivan had string s consisting of small English letters. However, his friend Julia decided to make fun of him and hid the string s. Ivan preferred making a new string to finding the old one. Ivan knows some information about the string s. Namely, he re…
C. String Transformation   time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output You are given a string s consisting of |s| small english letters. In one move you can replace any character of thi…
Two people are playing a game with a string ss, consisting of lowercase latin letters. On a player's turn, he should choose two consecutive equal letters in the string and delete them. For example, if the string is equal to "xaax" than there is…
[题目链接]:http://codeforces.com/contest/779/problem/D [题意] 给你一段操作序列; 按顺序依次删掉字符串1中相应位置的字符; 问你最多能按顺序删掉多少个字符; 使得s2是剩下的字符构成的字符串的子列; [题解] 二分枚举能够按顺序删掉多少个字符m; 然后把1..m相应的字符标记成已经删掉了; 然后O(N)判断s2是不是剩下的字符的子串; 心态炸了. [完整代码] #include <bits/stdc++.h> using namespace s…
http://codeforces.com/problemset/problem/778/A 题意:给出字符串s和字符串p,还有n个位置,每一个位置代表删除s串中的第i个字符,问最多可以删除多少个字符使得s串依旧包含p串. 思路:想到二分,以为二分做法依旧很暴力.但是别人的做法确实就是二分暴力搞啊. 枚举删除字符数,然后判断的时候如果s串包含p串,那么可以往右区间找,否则左区间找. #include <bits/stdc++.h> using namespace std; #define N…
题目链接: https://codeforces.com/contest/1120/problem/C 题意: 从前往后压缩一段字符串 有两种操作: 1.对于单个字符,压缩它花费$a$ 2.对于末尾一段字符串,如果这段字符串是已经压缩过字符串的子串,那么可以选择压缩它,花费为$b$ 数据范围: $1\leq |S| \leq 5000$ $1\leq a \leq 5000$ $1\leq b \leq 5000$ 分析: 这道题目我们需要解决一个问题,计算某个子串出现的最早位置 转移,如果这个…
这题的题意就很晦涩.题意是:问有多少种方法,把字符串s划分成不重叠的子串(可以不使用完s的所有字符,但是这些子串必须不重叠),使得t串是所有这些新串的子串.譬如第一个样例,"ababa"和"aba",共有5种方法:{aba}(前3个),{aba}(后3个),{abab},{baba},{ababa}. 先设s的长度为lena,t的长度为lenb. 做法是:用dp[i]表示到i为止,有几种方案数,所以最终答案是dp[lena].然后考虑转移.首先dp[i]至少等于dp…
Description 题库链接 定义 \(F(x)\) 为 \(F(x-1)\) 与 \(F(x-2)\) 的连接(其中 \(F(0) = "0",F(1) = "1"\) ).给出一个长度为 \(n\) 的 \(01\) 字符串 \(s\) ,询问 \(s\) 在 \(F(x)\) 的所有子序列中出现了多少次. \(1\leq n\leq 100,0\leq x\leq 100\) Solution 首先 \(F(x)\) 是递归来定义的,显然我们可以递推来计算…
E. Eyes Closed time limit per test 2.5 seconds memory limit per test 256 megabytes input standard input output standard output Vasya and Petya were tired of studying so they decided to play a game. Before the game begins Vasya looks at array a consis…
C. Square Subsets time limit per test 4 seconds memory limit per test 256 megabytes input standard input output standard output Petya was late for the lesson too. The teacher gave him an additional task. For some array a Petya should find the number…
B. XK Segments time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output While Vasya finished eating his piece of pizza, the lesson has already started. For being late for the lesson, the teacher sug…
题意:给你一个字符串,有2种消除方式:1:消除一个单独的字母,代价为a.2:s[j]到s[k]是s[1]到s[j - 1]的子串,那么s[j]到s[k]可以消除,代价为b,问最小的代价. 思路:官方题解说的很明白了. 代码: #include <bits/stdc++.h> #define LL long long #define INF 0x3f3f3f3f using namespace std; const int maxn = 5010; int dp[maxn]; int v[max…
A. Pizza Separation time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output Students Vasya and Petya are studying at the BSU (Byteland State University). At one of the breaks they decided to order…
cf题面 中文题意 求一个由最多26个.最少k个小写字母构成的,长度为n的字符串,这个字符串要满足的要求是--当其中字母按照p和q两个\(1\)~\(n\)的全排列重新排序时,新的字符串是按照升序排好序的(没要求老字符串排好序). 解题思路 虚拟赛时其实已经走到了想出正解的路上我在路上了.正解是这样--对于排列p,将所有p[i]到p[i+1]连边,对于q也将所有q[i]和q[i+1]连边,那么每条边就代表前面位置的字母要小于等于后面位置的字母,那对于这个图中的的所有强连通分量,上边的字母应该都是…
codeforces Nikita and string time limit per test   2 seconds memory limit per test   256 megabytes One day Nikita found the string containing letters "a" and "b" only. Nikita thinks that string is beautiful if it can be cut into 3 stri…
codeforces 423 A. Restaurant Tables [水题] //注意,一个人选座位的顺序,先去单人桌,没有则去空的双人桌,再没有则去有一个人坐着的双人桌.读清题意. #include <cstdio> #include <algorithm> #include <cstring> using namespace std; int n, a, b, bb, x; int main() { ; scanf("%d%d%d", &am…
Pizza Serparation #include<stdio.h> #include<string.h> #include<stdlib.h> #include<vector> #include<algorithm> #include<iostream> #include<map> #include<queue> using std::vector; using std::queue; using std:…
c++ hex string array 转换 效果如下 tset string is follow 0x50 55 0x35 00 10 203040506073031323334ff format string is follow 5055350010203040506073031323334F0F now is to convert to a array and then convert to string to show 5055350010203040506073031323334F0…