7.6 KPOJ 3320Jessica's Reading Problem
来源:互联网 发布:傲剑金蛇升级数据大全 编辑:程序博客网 时间:2024/05/22 07:02
题意:
给一串长为n的数字串,求恰好包含所有数字种类的最小串长度。
思路:
用双指针即可。
代码:
#include <iostream>using namespace std;const int h_max=1000007;int hkey[h_max],hmap[h_max];int page[h_max],cnt[h_max];int n,amt=0;void add(const int& x){ int u=x%h_max; while(hmap[u]!=0&&hkey[u]!=x){ u=(u+1)%h_max; } hkey[u]=x; hmap[u]++;}int f(const int& x){ int u=x%h_max; while(hmap[u]!=0&&hkey[u]!=x){ u=(u+1)%h_max; } return u;}int main(){ ios::sync_with_stdio(0); cin>>n; if(n==1){cout<<1<<endl;return 0;} for (int i = 0; i <= n; i++) cnt[i] = 100000000; for(int i=0;i<n;i++) cin>>page[i]; int l=0,r=1; add(page[0]); while(r<n){ if(hmap[f(page[r])]==0) amt++; add(page[r]); while(hmap[f(page[l])]>1){ hmap[f(page[l])]--; l++; } cnt[amt]=min(cnt[amt],r-l+1); r++; } cout<<cnt[amt]<<endl; return 0;}
0 0
- 7.6 KPOJ 3320Jessica's Reading Problem
- Jessica's reading problem
- Jessica's Reading Problem
- PKU 3320 Jessica's Reading Problem
- POJ:3320 Jessica's Reading Problem
- poj 3320 Jessica's Reading Problem
- poj 3320 Jessica's Reading Problem
- POJ-3320-Jessica's Reading Problem
- POJ 3320 Jessica's Reading Problem
- poj 3320 Jessica's Reading Problem
- Jessica's Reading Problem POJ 3320
- POJ 3320 Jessica's Reading Problem
- POJ 3320 Jessica's Reading Problem
- POJ 3320 Jessica's Reading Problem
- POJ-3320 Jessica's Reading Problem
- poj 3320 Jessica's Reading Problem
- POJ 3320 Jessica's Reading Problem
- poj 3320 Jessica's Reading Problem
- 学习Hadoop第九课(RPC)
- 统计单词个数
- 全概率公式和贝叶斯公式
- 0910
- 1010. Radix (25)
- 7.6 KPOJ 3320Jessica's Reading Problem
- Java获取客户端IP
- Java设计模式—组合模式
- 列车调度(PAT)
- ASIS CTF - 三个魔法Web关WriteUp
- HDU5869 Different GCD Subarray Query(线段树&&离线处理)
- Java异常处理细节
- Java--Connection
- HDU 5876 Sparse Graph2016 ACM/ICPC Asia Regional Dalian Online 1009