Codeforces Round #364 (Div. 2) C. They Are Everywhere (尺取法)
2016-07-23 14:19
369 查看
要维护区间内字符数为定值,求最小的满足条件的区间典型的双指针。
#include <cstdio> #include <iostream> #include <cstring> #include <set> #include <map> using namespace std; #define pr(x) cout << #x << ": " << x << " " #define pl(x) cout << #x << ": " << x << endl; struct jibancanyang { int n, t; string str; void two() { int l = 0, r = 0; map<char, int> st; int ret = int(1e9); while (l < n) { while (r < n && (int)st.size() < t) { st[str[r++]]++; } if (t <= (int)st.size()) ret = min(ret, r - l); else break; st[str[l]]--; if (st[str[l]] == 0) st.erase(str[l]); l++; } cout << ret << endl; } void run() { cin >> n >> str; set<char> st; for (int i = 0; i < (int)str.size(); i++) { st.insert(str[i]); } t = st.size(); two(); } }ac; int main() { #ifdef LOCAL freopen("in.txt", "r", stdin); //freopen("out.txt", "w", stdout); #endif ac.run(); return 0; }
相关文章推荐
- C - C
- mysql修改root密码
- C99 新增了复数类型(_Complex)和虚数类型(_Imaginary)。简单来说,C99 提供了三种复数类型:float _Complex,double _Complex,和 long do
- VS2010 MPI并行环境设置
- [树形dp] poj 2486 Apple Tree
- poj 3641 Pseudoprime numbers
- Rx学习笔记和总结
- HLS_ug871笔记
- 2016夏季练习——最小生成树
- 第一周学习笔记3
- 南阳理工学院--语言入门--6174问题
- 一个整型数组里除了两个数之外,其他数都出现了两次。找出这两个出现一次的数。
- Python Web框架Tornado运行和部署
- css3技巧之背景渐变
- 基于纯Java代码的Spring容器和Web容器零配置的思考和实现(1) - 数据源与事务管理
- 基于MVC+EasyUI的Web开发框架经验总结(15)--在MVC项目中使用RDLC报表
- 本地服务端 使用 sqlplus / as sysdba 报ORA-12547: TNS:lost contact
- JDBC之事务处理
- 定时锁屏软件
- 复习(数据结构):字符串:c语言