Codeforces Round #418 (Div. 2) (补题C 尺取法)
来源:互联网 发布:洞主的淘宝店 编辑:程序博客网 时间:2024/05/16 07:51
今天看了下别人的博客,get了一个很厉害的暴力。
名字叫尺取法,是用来做类似找连续区间的最长值/最短值,而且这个区间必须要满足一定的条件,对于这一题就是最多不能换超过m个字母。
我对尺取法的理解就是对每个l,看最多能跑多远,然后开始移动l,在移动l前先把对l做的操作收回。
#include <cstdio>#include <cstring>#include <iostream>using namespace std;const int maxn = 1600;char s[maxn];int d[maxn];int main(){ int n,q; scanf("%d",&n); scanf("%s",s); for(int i = 0; i < n ; i++) d[i] = s[i]-'a'; scanf("%d",&q); while(q--) { char t[3]; int a; scanf("%d%s",&a,t); int tag = t[0] - 'a'; int use = 0,l = 0,ans = 0,th = 0,id = 0; if(a >= n) {printf("%d\n",n);continue;} while(1) { while(id < n) { if(d[id] != tag) { if(use < a) use ++; else break; } th++;id++; } ans = max(ans, th); if(d[l++] != tag) use--; th--; if(id == n || l == n) break; } printf("%d\n",ans); } return 0;}
POJ - 3061 http://poj.org/problem?id=3061
那就再来一题吧。
#include <cstdio>#include <iostream>#include <cstring>using namespace std;const int maxn = 1e5+10;int d[maxn];int main(){ int t; int n,m; scanf("%d",&t); while(t--) { scanf("%d%d",&n,&m); for(int i = 0; i < n ; i++) scanf("%d",&d[i]); int id = 0,l = 0,sum = 0,ans = n+1, imin = n+2; while(1) { while(sum < m && id < n) sum += d[id++]; if(sum < m) break; ans = min(ans, id-l); sum -= d[l++]; } ans == n+1 ? printf("0\n"):printf("%d\n",ans); } return 0;}
阅读全文
0 0
- Codeforces Round #418 (Div. 2) (补题C 尺取法)
- Codeforces Round #418 (Div. 2)-C(尺取法)
- Codeforces Round #364 (Div. 2) C 尺取法
- Codeforces Round #354 (Div. 2) C Vasya and String(尺取法二分)
- Codeforces Round #364 (Div. 2) C. They Are Everywhere (尺取法)
- Codeforces Round #364 (Div. 2) C. They Are Everywhere (尺取法)
- Codeforces Round #364 (Div. 2) C. They Are Everywhere (尺取法)
- Codeforces Round #354 (Div. 2) C. Vasya and String (尺取法)
- Codeforces Round #337 (Div. 2)-------补题
- Codeforces Round #340 (Div. 2)--补题
- Codeforces Round #341 (Div. 2) ---补题
- Codeforces Round #430 (Div. 2) C. Ilya And The Tree(补题)
- Codeforces Round #431 (Div. 2) C. From Y to Y(补题)
- Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)
- Codeforces Round #430 (Div. 2) C+D补题记录
- Codeforces Round #418 (Div. 2) C (尺取+预处理)
- Educational Codeforces Round 6(C)尺取法+贪心
- Codeforces Round #313 (Div. 2) C. Gerald's Hexagon(补大三角形)
- Runtime相关方法封装
- c++虚拟克隆
- jsoup总结
- 《Web接口开发与自动化测试基于Python语言》–第5章
- fwrite和fread函数的用法小结
- Codeforces Round #418 (Div. 2) (补题C 尺取法)
- 苹果与宜家:以用户为中心不会产生突破性创新
- python下载文件demo
- BZOJ3451 Normal 点分治+FFT
- 汇编复习题 test2
- vue内如何引入阿里图标
- CentOS 7.3.1611 安装 MySQL
- 【Unity闲谈】如何判断用户是否在打字?
- 6月告知--