【题目链接】:http://codeforces.com/contest/701/problem/C

【题意】



让你选择一段最短的区间;

使得这段区间里面包含所有种类的字符;

【题解】



之前都是用二分写;

现在会用类似队列的思路写了;

就是先确定左端点;

然后右端点右移;

直到出现所有种类;(这时候右端点就没必要再右移了)

然后右端点不动,右移左端点;

然后如果这时候又没有全部种类,就再右移右端点;

O(N)的复杂度吧



【Number Of WA】



0



【完整代码】

#include <bits/stdc++.h>
using namespace std;
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define LL long long
#define rep1(i,a,b) for (int i = a;i <= b;i++)
#define rep2(i,a,b) for (int i = a;i >= b;i--)
#define mp make_pair
#define ps push_back
#define fi first
#define se second
#define rei(x) cin >> x
#define pri(x) cout << x
#define ms(x,y) memset(x,y,sizeof x) typedef pair<int,int> pii;
typedef pair<LL,LL> pll; const int dx[9] = {0,1,-1,0,0,-1,-1,1,1};
const int dy[9] = {0,0,0,-1,1,-1,1,-1,1};
const double pi = acos(-1.0);
const int N = 1e5+100; map <char,int> dic;
int n,tot,ans=N;
char s[N]; int main()
{
//freopen("F:\\rush.txt","r",stdin);
ios::sync_with_stdio(false);
rei(n);
rei((s+1));
rep1(i,1,n)
if (!dic[s[i]])
{
dic[s[i]] = 1;
tot++;
}
dic.clear();
int l = 1,r = 1,now = 0;
dic[s[1]] = 1;
now = 1;
while (r<=n)
{
if (l<=r && now==tot)
{
ans = min(ans,r-l+1);
dic[s[l]]--;
if (dic[s[l]]==0) now--;
l++;
}
else
{
r++;
if (r<=n)
{
dic[s[r]]++;
if (dic[s[r]]==1) now++;
}
}
}
pri(ans<<endl);
//printf("\n%.2lf sec \n", (double)clock() / CLOCKS_PER_SEC);
return 0;
}

【codeforces 701C】They Are Everywhere的更多相关文章

  1. 【codeforces 415D】Mashmokh and ACM(普通dp)

    [codeforces 415D]Mashmokh and ACM 题意:美丽数列定义:对于数列中的每一个i都满足:arr[i+1]%arr[i]==0 输入n,k(1<=n,k<=200 ...

  2. 【codeforces 707E】Garlands

    [题目链接]:http://codeforces.com/contest/707/problem/E [题意] 给你一个n*m的方阵; 里面有k个联通块; 这k个联通块,每个连通块里面都是灯; 给你q ...

  3. 【codeforces 707C】Pythagorean Triples

    [题目链接]:http://codeforces.com/contest/707/problem/C [题意] 给你一个数字n; 问你这个数字是不是某个三角形的一条边; 如果是让你输出另外两条边的大小 ...

  4. 【codeforces 709D】Recover the String

    [题目链接]:http://codeforces.com/problemset/problem/709/D [题意] 给你一个序列; 给出01子列和10子列和00子列以及11子列的个数; 然后让你输出 ...

  5. 【codeforces 709B】Checkpoints

    [题目链接]:http://codeforces.com/contest/709/problem/B [题意] 让你从起点开始走过n-1个点(至少n-1个) 问你最少走多远; [题解] 肯定不多走啊; ...

  6. 【codeforces 709C】Letters Cyclic Shift

    [题目链接]:http://codeforces.com/contest/709/problem/C [题意] 让你改变一个字符串的子集(连续的一段); ->这一段的每个字符的字母都变成之前的一 ...

  7. 【Codeforces 429D】 Tricky Function

    [题目链接] http://codeforces.com/problemset/problem/429/D [算法] 令Si = A1 + A2 + ... + Ai(A的前缀和) 则g(i,j) = ...

  8. 【Codeforces 670C】 Cinema

    [题目链接] http://codeforces.com/contest/670/problem/C [算法] 离散化 [代码] #include<bits/stdc++.h> using ...

  9. 【codeforces 515D】Drazil and Tiles

    [题目链接]:http://codeforces.com/contest/515/problem/D [题意] 给你一个n*m的格子; 然后让你用1*2的长方形去填格子的空缺; 如果有填满的方案且方案 ...

随机推荐

  1. [Swift通天遁地]四、网络和线程-(4)使用Alamofire实现网络请求

    ★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★★➤微信公众号:山青咏芝(shanqingyongzhi)➤博客园地址:山青咏芝(https://www.cnblogs. ...

  2. Elasticsearch索引的操作,利用kibana(如何创建/删除一个es的索引?)

    我们已经通过索引一篇文档创建了一个新的索引 .这个索引采用的是默认的配置,新的字段通过动态映射的方式被添加到类型映射.现在我们需要对这个建立索引的过程做更多的控制:我们想要确保这个索引有数量适中的主分 ...

  3. Kafka详解与总结(五)

    Kafka持久化 1. 概述 Kafka大量依赖文件系统去存储和缓存消息.对于硬盘有个传统的观念是硬盘总是很慢,这使很多人怀疑基于文件系统的架构能否提供优异的性能.实际上硬盘的快慢完全取决于使用它的方 ...

  4. 洛谷2019 3月月赛 T3

    题干 唯一AC T3 的大巨佬%%% 这题就是个大模拟吧. 题解

  5. $P5018 对称二叉树$

    problem 一直忘记给这个题写题解了. 这题挺水的吧. 挺后悔当时没写出来. #ifdef Dubug #endif #include <bits/stdc++.h> using na ...

  6. java,安卓之信息的输出

    Android中实现信息的输出 java一般的打印办法为System.out.println("");J2ME也是,在ide的控制台就可以看到效果. 但是android平台,Sys ...

  7. BZOJ 3473

    思路: CF原题 ZYF有题解 O(nlog^2n) //By SiriusRen #include <bits/stdc++.h> using namespace std; ; ]; i ...

  8. myeclipse配置tomcat后,无法正常使用的问题

    如图所示:一定要设置为Enable.否则部署tomcat时,没有tomcat8.0

  9. js基础---数据类型转换

    js中数据类型: 简单数据类型: number:233,-34,0x23,023 string:"hello"或者'hello' boolean:true.false undefi ...

  10. MonoBehaviour简述

    Unity中的脚本都是继承自MonoBehaviour. 一.基础函数: 创建脚本就默认的update.start方法:(这些官方的文档都是有的) Start:Update函数第一次运行前调用,一般用 ...