CodeForces 701C They Are Everywhere 尺取法
简单的尺取法……
先找到右边界 然后在已经有了所有字母后减小左边界……
不断优化最短区间就好了~
#include<stdio.h>
#include<string.h>
#define M(a,b) memset(a,b,sizeof(a))
char a[];
int zimu[];
int zimu1[];
bool in[];
int sum;
int main(){
int n;
while(~scanf("%d",&n)){
getchar();
M(zimu,);
M(in,false);
gets(a);
sum=;
int minx=;
for(int i=;i<n;i++){
if(!in[a[i]-'A']){
in[a[i]-'A']=true;
sum++;
}
}
M(in,false);
int l=,r=,num=;
while(r<n){
zimu[a[r]-'A']++;
if(!in[a[r]-'A']){
in[a[r]-'A']=true;
num++;
}
if(sum==num){
while(true){
if(zimu[a[l]-'A']==) break;
else zimu[a[l]-'A']--;
l++; //在这里T了一发
}
if(r-l+<minx) minx=r-l+;
}
r++;
}
printf("%d\n",minx);
}
return ;
}
/* 3
AaA
7
bcAAcbc
6
aaBCCe */
CodeForces 701C They Are Everywhere 尺取法的更多相关文章
- codeforces #364c They Are Everywhere 尺取法
C. They Are Everywhere time limit per test 2 seconds memory limit per test 256 megabytes input stand ...
- codeforces 652C C. Foe Pairs(尺取法+线段树查询一个区间覆盖线段)
题目链接: C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard i ...
- Codeforces 650B Image Preview(尺取法)
题目大概说手机有n张照片.通过左滑或者右滑循环切换照片,滑动需要花费a时间:看一张照片要1时间,而看过的可以马上跳过不用花时间,没看过的不能跳过:有些照片要横着看,要花b时间旋转方向.那么问T时间下最 ...
- Codeforces 660C Hard Process(尺取法)
题目大概说给一个由01组成的序列,要求最多把k个0改成1使得连续的1的个数最多,输出一种方案. 和CF 676C相似. #include<cstdio> #include<algor ...
- codeforces 701C C. They Are Everywhere(尺取法)
题目链接: C. They Are Everywhere time limit per test 2 seconds memory limit per test 256 megabytes inp ...
- Codeforces Educational Codeforces Round 5 D. Longest k-Good Segment 尺取法
D. Longest k-Good Segment 题目连接: http://www.codeforces.com/contest/616/problem/D Description The arra ...
- Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)
题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...
- Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)
题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cs ...
- codeforces 814 C. An impassioned circulation of affection 【尺取法 or DP】
//yy:因为这题多组数据,DP预处理存储状态比每次尺取快多了,但是我更喜欢这个尺取的思想. 题目链接:codeforces 814 C. An impassioned circulation of ...
随机推荐
- Android设置窗体Activity背景透明
背景透明 style.xml <item name="android:windowBackground">@color/transparent</item> ...
- IntelliJ Idea设置默认换行符
IntelliJ换行CRLF, LF, CR的解释和默认设置 在window下开发有一个大坑,就是换行默认是CRLF,也就是回车换行,但是Linux下只有换行LF,这样代码提交后,会出现编译问题,所以 ...
- Python学习笔记——基础篇【第一周】——变量与赋值、用户交互、条件判断、循环控制、数据类型、文本操作
目录 Python第一周笔记 1.学习Python目的 2.Python简史介绍 3.Python3特性 4.Hello World程序 5.变量与赋值 6.用户交互 7.条件判断与缩进 8.循环控制 ...
- Filewatcher
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...
- @classmethod及@staticmethod方法浅析【python】
目前对于python中@classmethod 类方法和@staticmethod静态方法的有了一定的认识,之后有进一步的认识后继续记录. @classmethod :是和一个class类相关的方法, ...
- .net MVC 中“MvcPager” 插件的简单使用。
.net MVC 中提供了一个分页组件"MvcPager",用起来还算方便,实用性较强. 简单写一下使用方法,如有不足的地方,请各位大大给小弟指正出来. 一.准备工作 使用这个组件 ...
- 坑爹的 Hardware Reserved Memory (查看内存等)
来源: http://blog.sina.com.cn/s/blog_772645ff0100s4t7.html 我的电脑是GatewayNV49C83c,酷睿i3的CPU和NV的独立显卡 Inter ...
- response.setContentType与 request.setCharacterEncoding 区别
1.request.setCharacterEncoding()是设置从request中取得的值或从数据库中取出的值的编码 2.response.setContentType指定 HTTP 响应的编码 ...
- vue router 只需要这么几步
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- 在Table的Tbody中实现滚动条滚动
功能描述: 在一个Table中实现表头固定不动,内容部分实现通过滚动条滚动. 实现效果: 当页面宽度变宽时,只有最后一列的宽度会改变. 逻辑实现: 1.将表头和内容分别使用两个table标签包裹,每一 ...