[CodeForces-1225B] TV Subscriptions [贪心][尺取法] 标签: 题解 codeforces题解 尺取法 题目描述 Time limit 2000 ms Memory limit 262144 kB Source Technocup 2020 - Elimination Round 2 Tags implementation  two pointers  *1300 Site https://codeforces.com/problemset/problem/1…
题目大概说给一个由a和b组成的字符串,最多能改变其中的k个字符,问通过改变能得到的最长连续且相同的字符串是多长. 用尺取法,改变成a和改变成b分别做一次:双指针i和j,j不停++,然后如果遇到需要改变且改变次数用完就让i++更正改变次数,最后更新答案.时间复杂度O(n). 另外,注意到k=0的情况. #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ]; int mai…
题目链接: C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and '…
Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' only.…
题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cstdio> #include<cstring> #include<cmath> #include<string> #include<set> #include<map> #include<vector> #include<qu…
题意: 给出一个长度为n的字符串,只有字符'a'和'b'.最多能改变k个字符,即把'a'变成'b'或把'b'变成'a'. 问改变后的最长连续相同字符的字串长度为多少. 首先是二分查找,好想也好写 ..]of longint; ch:ansistring; n,k,i,l,r,mid,last,ans:longint; function max(x,y:longint):longint; begin if x>y then exit(x); exit(y); end; begin //assign…
C. Vasya and String time limit per test 1 second memory limit per test 256 megabytes input standard input output standard output High school student Vasya got a string of length n as a birthday present. This string consists of letters 'a' and 'b' onl…
题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法,不懂得可以看今天开始学算法系列-尺取法 2.二分法,具体见代码 PS:因为讲得太少所以附上A和B的题解: A:结构体存储,将所有数sort一下,一头一尾输出即可 B:开辆个数组记录当前行或列是否有车,row[],col[],设两个变量a,b记录行列,放入一个车时,如果已标记则不用减去,否则减去(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…
简单的尺取法…… 先找到右边界 然后在已经有了所有字母后减小左边界…… 不断优化最短区间就好了~ #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);…