codeforces 701 c 尺取法
来源:互联网 发布:网络流行词语2017 编辑:程序博客网 时间:2024/04/30 04:45
题目:
代码:
#include<set>#include<map>#include<cstdio>#include<cstring>#include<iostream>using namespace std;int n,ans;set<int> s;map<int,int> m;string a;/*主要是得心细 仔细模拟尺取法先移动右端点到一个符合条件的情况 然后尝试向前移动左端点如此反复直到右端点移动到头*/int main(){ ios_base::sync_with_stdio(false); cin>>n>>a; for(int i=0;a[i]!='\0';i++) s.insert(a[i]-'A'); int num=s.size(); ans=n; int L=0,R=0,cnt=0; while(R<n){ while(R<n&&cnt<num){///只要区间尚未覆盖所有元素 右端点右移 if(!m[a[R]]) cnt++;///覆盖新元素 m[a[R++]]++;///覆盖新元素 右端点右移 } while(m[a[L]]>1) m[a[L++]]--;///尝试向前移动左端点 同时改变区间覆盖情况 if(cnt==num){///第一个循环有可能出现R=n但还没覆盖满就退出了的情况 ans=min(ans,R-L); //cout<<L<<" "<<R<<endl; m[a[L++]]--; cnt--; } } printf("%d\n",ans); return 0;}
阅读全文
0 0
- codeforces 701 c 尺取法
- codeforces 701C(尺取法)
- codeforces 676C (尺取法)
- [CodeForces-676C] 尺取法
- 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 (尺取法)
- codeforces 660C (尺取法 水~)
- codeforces 676C C. Vasya and String 尺取法
- #尺取法 --由codeforces 701C They are EveryWhere为例
- Educational Codeforces Round 6(C)尺取法+贪心
- Codeforces 660C-Hard Process【尺取法经典练习】
- 国务院正式发布《新一代人工智能发展规划》
- fastDFS+nginx
- java实现插入排序
- C#高级编程(第7版)pdf
- javaweb部署服务器 详细版
- codeforces 701 c 尺取法
- 从诗人到程序员
- 科研经验3:公众号建立实验室共享知识体系和宣传窗口
- 智能医疗影像诊断系统遭遇的骨感现实
- 3279 &[kuangbin带你飞]专题一 简单搜索 D
- HDU1678 Shopaholic
- CSS权威指南(第三版)pdf
- N皇后问题的Java实现
- hdu 1222 Wolf and Rabbit