简单的尺取法……

先找到右边界 然后在已经有了所有字母后减小左边界……

不断优化最短区间就好了~

 #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 尺取法的更多相关文章

  1. codeforces #364c They Are Everywhere 尺取法

    C. They Are Everywhere time limit per test 2 seconds memory limit per test 256 megabytes input stand ...

  2. codeforces 652C C. Foe Pairs(尺取法+线段树查询一个区间覆盖线段)

    题目链接: C. Foe Pairs time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  3. Codeforces 650B Image Preview(尺取法)

    题目大概说手机有n张照片.通过左滑或者右滑循环切换照片,滑动需要花费a时间:看一张照片要1时间,而看过的可以马上跳过不用花时间,没看过的不能跳过:有些照片要横着看,要花b时间旋转方向.那么问T时间下最 ...

  4. Codeforces 660C Hard Process(尺取法)

    题目大概说给一个由01组成的序列,要求最多把k个0改成1使得连续的1的个数最多,输出一种方案. 和CF 676C相似. #include<cstdio> #include<algor ...

  5. codeforces 701C C. They Are Everywhere(尺取法)

    题目链接: C. They Are Everywhere time limit per test 2 seconds   memory limit per test 256 megabytes inp ...

  6. 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 ...

  7. Codeforces Round #364 (Div.2) C:They Are Everywhere(双指针/尺取法)

    题目链接: http://codeforces.com/contest/701/problem/C 题意: 给出一个长度为n的字符串,要我们找出最小的子字符串包含所有的不同字符. 分析: 1.尺取法, ...

  8. Codeforces Round #354 (Div. 2)_Vasya and String(尺取法)

    题目连接:http://codeforces.com/contest/676/problem/C 题意:一串字符串,最多改变k次,求最大的相同子串 题解:很明显直接尺取法 #include<cs ...

  9. codeforces 814 C. An impassioned circulation of affection 【尺取法 or DP】

    //yy:因为这题多组数据,DP预处理存储状态比每次尺取快多了,但是我更喜欢这个尺取的思想. 题目链接:codeforces 814 C. An impassioned circulation of ...

随机推荐

  1. 转:Spark User Defined Aggregate Function (UDAF) using Java

    Sometimes the aggregate functions provided by Spark are not adequate, so Spark has a provision of ac ...

  2. WebForm 分页与组合查询

    1.封装实体类 2.写查询方法 //SubjectData类 public List<Subject> Select(string name) { List<Subject> ...

  3. CodeForces 706C Hard problem

    简单$dp$. $dp[i][0]$:第$i$个串放置完毕,并且第$i$个串不反转,前$i$个串字典序呈非递减的状态下的最小费用. $dp[i][1]$:第$i$个串放置完毕,并且第$i$个串反转,前 ...

  4. 【JS】倒计时

    描述: 先要链接jquery.js,这样写法可以直接放JS文件运行. //放在图片里定位的倒计时 //顶图里面定位才使用的代码 document.writeln("<style> ...

  5. 【转】Zookeeper-Watcher机制与异步调用原理

    声明:本文转载自http://shift-alt-ctrl.iteye.com/blog/1847320,转载请务必声明. Watcher机制:目的是为ZK客户端操作提供一种类似于异步获得数据的操作. ...

  6. .net后台代码临时表创建

    写法一: var dt = new DataTable(); dt.Columns.Add(new DataColumn("Id", System.Type.GetType(&qu ...

  7. 设置session存储在int sqlserver上---使用aspnet_regsql.exe工具

    以管理员身份打开命令窗 1)cd到相应的framework下,如:C:\Windows\Microsoft.NET\Framework\v4.0.30319 2)执行如下命令:aspnet_regsq ...

  8. python学习之批量更改文件格式

    文件操作 import os, glob from PIL import Image path = 'D:/SBSR/view_1' imgslist = glob.glob(path+'/*.jpg ...

  9. C# .NETWEB开发6大内置对象

    ASP.NET 内置对象包括 1.Response 2.Request  3.Server  4.Application   5.Session   6.Cookie 1  Request对象主要是让 ...

  10. mysql B+树 Cardinality MRR

    B+树索引并不能找到一个给定键值的具体行,而是被查找数据行所在的页.然后数据库通过把页读入到内存,再在内存中进行查找,最后得到想要查找的数据. Show index from table. Cardi ...