【题目链接】: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. Android 触摸提示音【转】

    本文转载自:http://blog.csdn.net/Jin_HeZai/article/details/46791567 近期任务,涉及Android触摸提示音. 首先,定位源码目标.很显然的,在原 ...

  2. Android之利用EventBus进行数据传递

    在项目中,不可避免的要在两个页面之间进行数据的传递,就算不传递,也需要进行刷新之类的,我们根据Google提供的库类方法,也是可以做的,主要有广播broadcastreceiver,startacti ...

  3. 41. extjs--combobox下拉列表的triggerAction

    转自:https://icrwen.iteye.com/blog/939247 一般combobox的store先load加载数据,然后combobox的mode设置为local,则不会每次下拉列表都 ...

  4. U3D版本控制设置 Force Text优劣

    git的忽略列表 .gitignore Library/ Temp/ .vs/ *.csproj *.sln Edit > Project Settings > Editor 下把meta ...

  5. 蛤玮学计网 -- 简单的判断ip

    心累 , 狗日的想了好多数据 , ......啥也不说了 我去哭一会 .  #include<stdio.h> #include<string.h> #include<m ...

  6. JavaScript--Date 日期对象

    日期对象可以储存任意一个日期,并且可以精确到毫秒数(1/1000 秒). 定义一个时间对象 : var Udate=new Date(); 注意:使用关键字new,Date()的首字母必须大写. 使 ...

  7. Android中有四大组件的简单总结

    Android四大基本组件分别是Activity,Service服务,Content Provider内容提供者,BroadcastReceiver广播接收器. 一:了解四大基本组件 Activity ...

  8. [转]Linux下chkconfig命令详解

    转自:http://www.cnblogs.com/panjun-Donet/archive/2010/08/10/1796873.html chkconfig命令主要用来更新(启动或停止)和查询系统 ...

  9. 函数 out 传值 分割

    public void Jia(int a ,int b) { a = a + b; Console.WriteLine(a); } public void Jia1(int a,out int b) ...

  10. Spring Boot (23) Lettuce Redis

    Spring Boot除了支持常见的ORM框架外,更是对常用的中间件提供了非常好的封装,随着SpringBoot2.x的到来,支持的组件也越来越丰富,也越来越成熟,其中对Redis的支持不仅仅是它丰富 ...