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 ...
随机推荐
- Saltstack Master 配置文件详解
#主配置 /etc/salt/master interface 默认值:0.0.0.0(所有的网络地址接口) 绑定到本地的某个网络地址接口 interface: 192.168.30.131 publ ...
- APP模板框架
HTML页面 <!DOCTYPE html><html lang="en"><head> <meta charset="UTF- ...
- js的特殊运算符
1)三元条件运算符: c是一个布尔值,当c为true的时候,取冒号左边a的值,否取冒号右边的b的值: 2)逗号运算符: 值从左到右依次计算,取最右边的,例如例子里的val,会取最右边的值3: 特殊运算 ...
- Openjudge-NOI题库-对齐输出
题目描述 Description 读入三个整数,按每个整数占8个字符的宽度,右对齐输出它们. 输入输出格式 Input/output 输入格式: 只有一行,包含三个整数,整数之间以一个空格分开. ...
- iOS 最新App提交上架流程及部分问题的解决方案2016.12.21,感谢原博主!!!
内容摘自http://www.cocoachina.com/bbs/3g/read.php?tid=330302,原博特别详细,下面我对部分地方进行了修改,主要是对在打包验证和上传的时候遇到的问题进行 ...
- Introduction to Programming Contests (stanford)
http://web.stanford.edu/class/cs9http://web.stanford.edu/class/cs97si/7si/
- winform开线程,避免页面假死
using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...
- python 学习 设计模式(goF设计模式)
一 单例模式 用来创建单个实例 #/usr/bin/env python3 # -*- coding:utf-8 -*- # Author: ZSHAOX class Foo: instance = ...
- 【Python之路】第二篇--初识Python
Python简介 Python可以应用于众多领域,如:数据分析.组件集成.网络服务.图像处理.数值计算和科学计算等众多领域.目前业内几乎所有大中型互联网企业都在使用Python,如:Youtube.D ...
- Arpa's weak amphitheater and Mehrdad's valuable Hoses
Arpa's weak amphitheater and Mehrdad's valuable Hoses time limit per test 1 second memory limit per ...