题目链接: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. 【BZOJ】【1986】【USACO 2004 Dec】/【POJ】【2373】划区灌溉

    DP/单调队列优化 首先不考虑奶牛的喜欢区间,dp方程当然是比较显然的:$ f[i]=min(f[k])+1,i-2*b \leq k \leq i-2*a $  当然这里的$i$和$k$都是偶数啦~ ...

  2. nodeJs 初探 ~

    今天晚上,开始时间了一下nodejs,跟着 Node入门 一步步的往下走.对node开发也有了初步的了解. 期间没有碰到什么问题,只有在最后的时候,碰到了几个问题.在这里记录一下: 1 . cross ...

  3. asp.net MVC3 + JQuery 的ajax简单使用

    一直都没有使用过JQuery,更没使用过JQuery的ajax支持带来的方便,今天试了一下,真是减少了很多工作量,使用方法也比较简单 这里先记下来,以后使用时可以再拿着用. 本应用中,本来是准备使用长 ...

  4. Sqli-labs less 57

    Less-57 从代码中看到对id进行了 " " 的处理,所以此处我们构造的payload要进行 "" 的处理,示例payload: http://127.0. ...

  5. MEAN实践——LAMP的新时代替代方案(下)

    在本系列文章的第一部分旨在介绍一些应用程序的基础技术细节和如何进行数据建模,而这个部分文章将着手建立验证应用程序行为的测试,并会指出如何启动和运行应用程序. 首先,编写测试 首先定义一些小型配置库.文 ...

  6. ASP.NET Web.Config配置数据库连接的一种方法

    所谓的webConfig配置数据库连接就是在里面某个特定名称的节点中写下ADP.NET中的ConnectString,就这么简单 1.首先在Web.Config文件里写下数据库连接字符串. <c ...

  7. (转)Eclipse平台技术概述

    转载:周金根 http://zhoujg.blog.51cto.com/1281471/516833    Eclipse:Eclipse平台技术概述 2010-10-19 13:35:00 标签:E ...

  8. hdu 4725

    The Shortest Path in Nya Graph Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  9. SqlBulkCopy大批量数据插入到sql表中

    alter TYPE TableType AS TABLE ( Name VARCHAR() , code VARCHAR() ) GO alter PROCEDURE usp_InsertProdu ...

  10. a cold welcome

    What does 'a cold welcome' refer to? On wednesday evening,we went to the town hall. It was the last ...