51Nod - 1127 最短的包含字符串
给出一个字符串,求该字符串的一个子串s,s包含A-Z中的全部字母,并且s是所有符合条件的子串中最短的,输出s的长度。如果给出的字符串中并不包括A-Z中的全部字母,则输出No Solution。
Input
第1行,1个字符串。字符串的长度 <= 100000。
Outpu
t输出包含A-Z的最短子串s的长度。如果没有符合条件的子串,则输出No Solution。
Sample Input
BVCABCDEFFGHIJKLMMNOPQRSTUVWXZYZZ
Sample Output
28 尺取法,判断标准是是否含有全部26个字母。
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<stack>
#include<deque>
#include<iostream>
using namespace std;
char con[];
int main()
{
int i,p,j,k;
int head,tail,ans,flag,big;
int check[]={};
gets(con);
k=strlen(con);
big=;
head=tail=;
flag=;
ans=;
check[con[]-]++;
while()
{
if(tail>head||head>=k||tail>=k||head<||tail<)
break;
if(flag<)
{
head++;
ans++;
if(check[con[head]-]==)
{
flag++;
}
check[con[head]-]++;
}
else
{
if(ans<big)
big=ans;
ans--;
check[con[tail]-]--;
if(check[con[tail]-]==)
flag--;
tail++;
}
}
if(big==)
printf("No Solution\n");
else
printf("%d\n",big);
return ;
}
51Nod - 1127 最短的包含字符串的更多相关文章
- 51Nod 1127 最短的包含字符串 (尺取法)
#include <iostream> #include <algorithm> #include <string> #include <cstring> ...
- 51 nod 1127最短的包含字符串(尺取法)
1127 最短的包含字符串 收藏 关注 给出一个字符串,求该字符串的一个子串S,S包含A-Z中的全部字母,并且S是所有符合条件的子串中最短的,输出S的长度.如果给出的字符串中并不包括A-Z中的全 ...
- [51NOD1127]最短的包含字符串(尺取法)
题目链接:http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1127 思路:尺取法,一开始我考虑更新右指针,直到遇到一个和l指 ...
- 51nod1127 最短的包含字符串 尺取法
Bryce1010模板 #include <bits/stdc++.h> using namespace std; typedef long long LL; map<char,LL ...
- sql server 查找包含字符串的对象
sql server 查找包含字符串的对象 SELECT sm.object_id, OBJECT_NAME(sm.object_id) AS object_name, o.type, o.type_ ...
- css3选择器的比较(二) -- 包含字符串
二. 包含“字符串” 两种用法的区别是: a. “~=”,需要用空格分割, b. "*=",不需要任何分隔符 1. 资料 a) b) 2. html代码 <div tit ...
- strstr() strpos() 获取db报错,判断报错中是否包含字符串,判断错误类型
model中直接获取添加公司的错误.(公司名称不能重复) $enterprise_id = $this->add($enterprisedata ); $err = $this->getD ...
- js判断字符串str是否包含字符串substr
js判断字符串str是否包含字符串substr: function addUser(id,realName){ var userids = $("#userids").val(); ...
- idea 快捷键以及包含字符串文件搜索
1.idea也有一个类似于eclipse的包含字符串文件搜索(特别实用) idea 里按快捷键:ctrl+H 2.下图是idea的快捷键汇总 3.debug调试 F5:跳入方法 F6:向下逐行调试 ...
随机推荐
- selenium webdriver XPath的定位方法练习 !
html 代码: <html> <body> <div id="div1"> <input name="divl1input& ...
- JavaScript判断密码强度
以下是代码: <html> <head> <title>JS判断密码强度</title> <script language=javascript& ...
- Linux 重定向输出到多个文件中
转自:http://codingstandards.iteye.com/blog/833695 用途说明 在执行Linux命令时,我们可以把输出重定向到文件中,比如 ls >a.txt,这时我们 ...
- python的N个小功能(高斯模糊原理及实践)
原理: 二维高斯函数 1) 为了计算权重矩阵,需要设定σ的值.假定σ=1.5,则模糊半径为1的权重矩阵如下: 2) 这9个点的权重总和等于0.4787147,如果只计算 ...
- BZOJ 1264 基因匹配(DP+线段树)
很有意思的一道题啊. 求两个序列的最大公共子序列.保证每个序列中含有1-n各5个. 如果直接LCS显然是TLE的.该题与普通的LCS不同的是每个序列中含有1-n各5个. 考虑LCS的经典DP方程.dp ...
- HDU1863畅通工程---并查集+最小生成树
#include<cstdio> #include<algorithm> #define MAX 105 struct edge { int from,to; long lon ...
- oracle 插入每年每天数据
create or replace procedure PROC_P_ABC is v_sumday ; i ; v_calendar_date number :=null; v_day number ...
- spring集成webSocket实现服务端向前端推送消息
原文:https://blog.csdn.net/ya_nuo/article/details/79612158 spring集成webSocket实现服务端向前端推送消息 1.前端连接webso ...
- maven 启动 tomcat 及 跳过 test 安装
1.先在pom文件中配置 tomcat插件 <!-- 文件上传组件 --> <dependency> <groupId>commons-fileupload< ...
- html中的事件属性
Window 事件属性 针对 window 对象触发的事件(应用到 <body> 标签): 属性 值 描述 onafterprint script 文档打印之后运行的脚本. onbefor ...