Codeforces Round #364 C. They Are Everywhere分析及题解 尺取法
来源:互联网 发布:华硕笔记本推荐 知乎 编辑:程序博客网 时间:2024/05/17 21:48
这道题要求求出包含所有类型字母的最短连续序列,我采用了尺取法,它一般是反复推进区间的开头和结尾,来求取满足条件的最小区间的方法,比较实用。
AC代码: (耗时62ms)
#include<bits/stdc++.h>
using namespace std;
int main()
{
int n,sum=0;
cin>>n;
char a[100009];
map<char, int> Map1,m;
for(int i=1;i<=n;i++)
{
cin>>a[i];
if(!Map1.count(a[i]))
{
sum++;
}
Map1[a[i]]++;
}
int j=1,len=0,now=0,ans=100009;
for(int i=1;i<=n;i++)
{
if(m[a[i]]==0)now++;
m[a[i]]++;
len++;
if(now==sum)
{
if(len<ans)ans=len;
while(now==sum)
{
m[a[j]]--;
if(m[a[j]]==0)now--;
len--;
j++;
if(now==sum)if(len<ans)ans=len;
}
}
}
cout<<ans<<endl;
}
- Codeforces Round #364 C. They Are Everywhere分析及题解 尺取法
- Codeforces Round #364 (Div. 2) C. They Are Everywhere (尺取法)
- Codeforces Round #364 (Div. 2) C. They Are Everywhere (尺取法)
- Codeforces Round #364 (Div. 2) C. They Are Everywhere (尺取法)
- codeforces 701C They Are Everywhere(尺取法)
- codeforces--701C They Are Everywhere(尺取法)
- codeforces problem 701 C They Are Everywhere尺取法
- 【CodeForces】701C - They Are Everywhere(尺取法)
- 【Codeforces】-701C-They Are Everywhere(尺取法)
- CodeForces 701C They Are Everywhere (尺取法)
- codeforces 701C They Are Everywhere(尺取法)
- codeforces 701 C. They Are Everywhere (尺取法)
- CodeForces - 701C They Are Everywhere (尺取法)
- CF #364 (Div. 2)(C. They Are Everywhere 尺取法)
- Codeforces Round #364 div.2 C. They Are Everywhere 【尺追法】
- Codeforces Round #364 (Div. 2) C. They Are Everywhere(二分)
- Codeforces Round #364 (Div. 2)C. They Are Everywhere
- Codeforces Round #364 (Div. 2) C. They Are Everywhere
- PHP判断指定时间段的2个方法
- yield and Generators
- timeline播放
- 线段树专题#4_蒟蒻训练历程记录_HDU1698_ 延迟标记、区间更新
- hdu 2509 Be the Winner(博弈Nim)
- Codeforces Round #364 C. They Are Everywhere分析及题解 尺取法
- RxJava之一——一次性学会使用RxJava
- Android使用ViewPager实现左右循环滑动及轮播效果
- Linux CFS调度器之pick_next_task_fair选择下一个被调度的进程--Linux进程的管理与调度(二十八)
- 杭电 hdu 1070 Milk
- 算法竞赛入门经典第6章图论和树:竞赛选讲部分与习题
- Manacher算法--求最长回文子串
- redmine如何更改更换主题 (redmine之三)
- Codeforces 242E XOR on Segment(线段树)