题目链接: C. They Are Everywhere time limit per test 2 seconds   memory limit per test 256 megabytes input standard input output standard output Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row fr…
题目链接: 传送门 They Are Everywhere time limit per test:2 second     memory limit per test:256 megabytes Description Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from left to right. It is possib…
题目大概说给一个由a和b组成的字符串,最多能改变其中的k个字符,问通过改变能得到的最长连续且相同的字符串是多长. 用尺取法,改变成a和改变成b分别做一次:双指针i和j,j不停++,然后如果遇到需要改变且改变次数用完就让i++更正改变次数,最后更新答案.时间复杂度O(n). 另外,注意到k=0的情况. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ]; int mai…
题目链接:http://codeforces.com/problemset/problem/660/C 尺取法,每次遇到0的时候补一个1,直到补完或者越界为止.之后每次从左向右回收一个0点.记录路径用两个指针卡住,每次更新即可. #include <algorithm> #include <iostream> #include <iomanip> #include <cstring> #include <climits> #include <…
简单的尺取法…… 先找到右边界 然后在已经有了所有字母后减小左边界…… 不断优化最短区间就好了~ #include<stdio.h> #include<string.h> #define M(a,b) memset(a,b,sizeof(a)) ]; ]; ]; ]; int sum; int main(){ int n; while(~scanf("%d",&n)){ getchar(); M(zimu,); M(in,false); gets(a);…
D. Longest k-Good Segment 题目连接: http://www.codeforces.com/contest/616/problem/D Description The array a with n integers is given. Let's call the sequence of one or more consecutive elements in a segment. Also let's call the segment k-good if it conta…
题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法,不懂得可以看今天开始学算法系列-尺取法 2.二分法,具体见代码 PS:因为讲得太少所以附上A和B的题解: A:结构体存储,将所有数sort一下,一头一尾输出即可 B:开辆个数组记录当前行或列是否有车,row[],col[],设两个变量a,b记录行列,放入一个车时,如果已标记则不用减去,否则减去(a-…
题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cstdio> #include<cstring> #include<cmath> #include<string> #include<set> #include<map> #include<vector> #include<qu…
//yy:因为这题多组数据,DP预处理存储状态比每次尺取快多了,但是我更喜欢这个尺取的思想. 题目链接:codeforces 814 C. An impassioned circulation of affection 题意:给出字符串长度n (1 ≤ n ≤ 1 500),字符串s由小写字母组成,q个询问q (1 ≤ q ≤ 200 000),每个询问为:mi (1 ≤ mi ≤ n)   ci ,表示可以把任意mi个字母改成ci,求每次改变后只由ci组成的最长连续字串的长度. 解法一:尺取法…
题目链接: C. They Are Everywhere time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output Sergei B., the young coach of Pokemons, has found the big house which consists of n flats ordered in a row from…