简单的尺取法…… 先找到右边界 然后在已经有了所有字母后减小左边界…… 不断优化最短区间就好了~ #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);…
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 left…
题目链接: C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output   You are given a permutation p of length n. Also you are given m foe pairs (ai, bi) (1 ≤ ai, bi ≤ n, ai ≠ bi). Your task…
题目大概说手机有n张照片.通过左滑或者右滑循环切换照片,滑动需要花费a时间:看一张照片要1时间,而看过的可以马上跳过不用花时间,没看过的不能跳过:有些照片要横着看,要花b时间旋转方向.那么问T时间下最多可以看多少张相片. 先确定左滑最多能看到哪张,然后用另一个指针从第一张照片往右移动,这代表先右滑然后左滑的方式看照片,而每次向右的指针移动计算其时间,不合法的话就通过向左的指针向右移修正时间: 而先左滑然后右滑的方式同理. 模拟题,好难写..不过写好后提交居然就1A了.. #include<cst…
题目大概说给一个由01组成的序列,要求最多把k个0改成1使得连续的1的个数最多,输出一种方案. 和CF 676C相似. #include<cstdio> #include<algorithm> using namespace std; ]; int main(){ int n,k; scanf("%d%d",&n,&k); ; i<n; ++i){ scanf("%d",a+i); } ){ ,cnt=;; ; i<…
题目链接: 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…
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组成的最长连续字串的长度. 解法一:尺取法…