题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1127

思路:尺取法,一开始我考虑更新右指针,直到遇到一个和l指针指向的字符相同的时候为止,发现这样做ac不了。于是换了一个思路。

一直更新r指针,直到所有字符都出现了一遍后,更新答案和左指针,导致有一个缺口,这时候再更新r指针。

     /*
━━━━━┒ギリギリ♂ eye!
┓┏┓┏┓┃キリキリ♂ mind!
┛┗┛┗┛┃\○/
┓┏┓┏┓┃ /
┛┗┛┗┛┃ノ)
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┛┗┛┗┛┃
┓┏┓┏┓┃
┃┃┃┃┃┃
┻┻┻┻┻┻
*/
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <climits>
#include <complex>
#include <fstream>
#include <cassert>
#include <cstdio>
#include <bitset>
#include <vector>
#include <deque>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define fr first
#define sc second
#define cl clear
#define BUG puts("here!!!")
#define W(a) while(a--)
#define pb(a) push_back(a)
#define Rint(a) scanf("%d", &a)
#define Rll(a) scanf("%lld", &a)
#define Rs(a) scanf("%s", a)
#define Cin(a) cin >> a
#define FRead() freopen("in", "r", stdin)
#define FWrite() freopen("out", "w", stdout)
#define Rep(i, len) for(int i = 0; i < (len); i++)
#define For(i, a, len) for(int i = (a); i < (len); i++)
#define Cls(a) memset((a), 0, sizeof(a))
#define Clr(a, x) memset((a), (x), sizeof(a))
#define Full(a) memset((a), 0x7f7f7f, sizeof(a))
#define lrt rt << 1
#define rrt rt << 1 | 1
#define pi 3.14159265359
#define RT return
#define lowbit(x) x & (-x)
#define onenum(x) __builtin_popcount(x)
typedef long long LL;
typedef long double LD;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<string, int> psi;
typedef pair<LL, LL> pll;
typedef map<string, int> msi;
typedef vector<int> vi;
typedef vector<LL> vl;
typedef vector<vl> vvl;
typedef vector<bool> vb; const int maxn = ;
int ascii[];
char s[maxn];
int n; int main() {
// FRead();
while(~Rs(s)) {
Cls(ascii);
n = strlen(s);
if(n < ) {
printf("No Solution\n");
continue;
}
int ret = 0x7f7f7f;
int cnt = ;
int l = , r = ;
ascii[s[l]]++; cnt = ;
while(r < n) {
if(ascii[s[r]] == ) cnt++;
ascii[s[r]]++;
while(cnt == ) {
ret = min(ret, r-l+);
ascii[s[l]]--;
if(ascii[s[l]] == ) cnt--;
l++;
}
r++;
}
if(ret == 0x7f7f7f) printf("No Solution\n");
else printf("%d\n", ret);
}
RT ;
}

[51NOD1127]最短的包含字符串(尺取法)的更多相关文章

  1. 51nod1127 最短的包含字符串 尺取法

    Bryce1010模板 #include <bits/stdc++.h> using namespace std; typedef long long LL; map<char,LL ...

  2. 51Nod 1127 最短的包含字符串 (尺取法)

    #include <iostream> #include <algorithm> #include <string> #include <cstring> ...

  3. 51 nod 1127最短的包含字符串(尺取法)

    1127 最短的包含字符串   收藏  关注 给出一个字符串,求该字符串的一个子串S,S包含A-Z中的全部字母,并且S是所有符合条件的子串中最短的,输出S的长度.如果给出的字符串中并不包括A-Z中的全 ...

  4. 字符串----hiho字符串(尺取法)

    注意:这道题的解法和最短摘要一样,都是采用尺取法解决问题,注意这儿题目要求恰好包含,也就是说这个hiho字符串必须包含2个'h'.1个'i'和1个'o'.一个不能多,一个也不能少. import ja ...

  5. 51Nod - 1127 最短的包含字符串

    给出一个字符串,求该字符串的一个子串s,s包含A-Z中的全部字母,并且s是所有符合条件的子串中最短的,输出s的长度.如果给出的字符串中并不包括A-Z中的全部字母,则输出No Solution. Inp ...

  6. 校内模拟赛T5:连续的“包含”子串长度( nekameleoni?) —— 线段树单点修改,区间查询 + 尺取法合并

    nekameleoni 区间查询和修改 给定N,K,M(N个整数序列,范围1~K,M次查询或修改) 如果是修改,则输入三个数,第一个数为1代表修改,第二个数为将N个数中第i个数做修改,第三个数为修改成 ...

  7. 51nod1127(尺取法)

    题目链接:https://www.51nod.com/onlineJudge/questionCode.html#!problemId=1127 题意:中文题诶- 思路:尺取法 维护一个队列,若当前队 ...

  8. CF 701C They Are Everywhere(尺取法)

    题目链接: 传送门 They Are Everywhere time limit per test:2 second     memory limit per test:256 megabytes D ...

  9. nyoj133_子序列_离散化_尺取法

    子序列 时间限制:3000 ms  |  内存限制:65535 KB 难度:5   描述 给定一个序列,请你求出该序列的一个连续的子序列,使原串中出现的所有元素皆在该子序列中出现过至少1次. 如2 8 ...

随机推荐

  1. Segment Tree 分类: ACM TYPE 2014-08-29 13:04 97人阅读 评论(0) 收藏

    #include<iostream> #include<cstdio> using namespace std; struct node { int l, r, m; int ...

  2. c++11 pod类型(了解)

    啥是POD类型? POD全称Plain Old Data.通俗的讲,一个类或结构体通过二进制拷贝后还能保持其数据不变,那么它就是一个POD类型. 平凡的定义 .有平凡的构造函数 .有平凡的拷贝构造函数 ...

  3. thinkPHP生成静态分页列表

    改造分页类Pagehtml.class.php <?php // 静态分页列表类 class Pagehtml extends Think { //分页url public $pageUrl; ...

  4. unset之讲解

    unset (PHP 4, PHP 5) unset — 释放给定的变量 说明¶ void unset ( mixed $var [, mixed $... ] ) unset() 销毁指定的变量. ...

  5. .NET设计模式(13):享元模式(Flyweight Pattern)(转)

    摘要:面向对象的思想很好地解决了抽象性的问题,一般也不会出现性能上的问题.但是在某些情况下,对象的数量可能会太多,从而导致了运行时的代价.那么我们如何去避免大量细粒度的对象,同时又不影响客户程序使用面 ...

  6. UNITY_MATRIX_IT_MV[Matrix] (转载)

    转载 http://blog.csdn.net/cubesky/article/details/38682975 前面发了一篇关于unity Matrix的文章. http://blog.csdn.n ...

  7. Chapter 3

    1.序列类型可以使用成员操作符in,大小计算函数(len()),分片([]),都可以迭代.Python内置的序列类型:str,list,tuple,bytearray,bytes.标准库中的序列类型: ...

  8. javascript和“主流大型语言”(c# JAVA C++等)的差异

    1.javascript不支持overload,因为它的函数参数是以数组方式来实现的,没有固定的参数签名,所以无法重载. 2.javascript的基本类型只有5个:number string boo ...

  9. 同一网站不同和二级域名和不同子目录的cookie

    1.cookie二级域名的实现: 用户其中一个站点登录,而且可以各个子频道间切换,保持登录状态设置Cookie时,使用如下代码即可:setcookie(name,value,expire,path,& ...

  10. iOS生成本地随机验证码

    原文链接:http://www.cnblogs.com/jerehedu/p/4527707.html 效果图: