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 ...
随机推荐
- HDU------checksum
Quicksum Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Subm ...
- 引用AForge.video.ffmpeg,打开时会报错:找不到指定的模块,需要把发行包第三方文件externals\ffmpeg\bin里的dll文件拷到windows的system32文件夹下。
引用AForge.video.ffmpeg,打开时会报错:找不到指定的模块,需要把发行包第三方文件externals\ffmpeg\bin里的dll文件拷到windows的system32文件夹下. ...
- 浙大pat1050题解
1050. String Subtraction (20) 时间限制 10 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard Given two string ...
- Filewatcher
using System; using System.Collections.Generic; using System.IO; using System.Linq; using System.Tex ...
- CentOs + Nginx + php-fpm + MySql 依赖库安装
依赖库和开发工具 yum -y install gcc gcc-c++ autoconf libjpeg libjpeg-devel libpng libpng-devel freetype free ...
- iOS 隐藏导航栏 隐藏状态栏
1导航栏 self.navigationController.navigationBarHidden = YES; 2 状态栏 [[UIApplication sharedApplication] s ...
- 批处理改hosts
@echo off color 0F @attrib -r "%windir%\system32\drivers\etc\hosts" @echo ######测试配置 beg & ...
- sql server 查询表基本信息sql
SELECT c.name,t.name TYPE,c.max_length,c.precision,c.scale,p.value FROM sys.systypes t INNER JOIN sy ...
- Cookie小解2
Cookie最早用来标识和认证一个用户,其处理分为以下几步: 1.服务端向客户端发送Cookie 2.浏览器将Cookie保存 3.之后每次浏览器服务服务器时都会将Cookie发向服务器端 ----- ...
- shell中$0,$?,$!
变量说明: $$ Shell本身的PID(ProcessID) $! Shell最后运行的后台Process的PID $? 最后运行的命令的结束代码(返回值) $- 使用Set命令设定的Flag一览 ...