POJ3320
来源:互联网 发布:lol代升级软件 编辑:程序博客网 时间:2024/06/03 17:20
尺取法做,在某个区间[s,t]已经覆盖了所有的知识点的情况。
有了如下的等价关系,所有的知识点被覆盖等价于每个知识点出现的次数不少于1.
附上代码。
#include<iostream>#include<cstdio>#include<queue>#include<set>#include<algorithm>#include<map>using namespace std;const int MAXN=1E6;int p;int a[MAXN];set<int> all;//计算全部知识点总数map<int,int> count;//知识点->出现次数的映射int main(){ scanf("%d",&p); for(int i=0;i<p;i++) scanf("%d",&a[i]); for(int i=0;i<p;i++) all.insert(a[i]); int n=all.size(); //尺取法 int s=0,t=0,num=0; int res=MAXN; while(true) { while(t<p&&num<n) if(count[a[t++]]++==0){ num++; } if(num<n)break; res=min(res,t-s); if(--count[a[s++]]==0){ num--; } } printf("%d\n",res);}
0 0
- poj3320
- poj3320
- poj3320
- POJ3320
- poj3320(取尺法)
- poj3320 hash
- 尺取法--poj3320
- POJ3320 尺取
- poj3320(区间追逐)
- poj3320 尺取法
- 尺取法 poj3061 poj3320
- poj3320 尺取法~~
- POJ3320尺取法
- poj3320尺取法
- POJ3320尺取法
- 尺取法+POJ3320
- POJ3320 尺取法
- poj3320 尺取法
- leetcode_292_Nim Game
- OpenGL学习脚印: 坐标和变换的数学基础(math-coordinates and transformations)
- centos 启动后,自动执行自己的脚本。
- 微信登陆,用到的。
- 路在远方,努力不止!!!
- POJ3320
- 使用Dom4j解析XML
- 2014年第五届蓝桥杯C/C++程序设计本科B组决赛 出栈次序(结果填空)
- C#委托和事件
- ssh 相关设置
- 动态规划——problem j】
- 理解Java中传递引用类型的实质
- calendar中set方法和静态属性带来的坑
- js中时间格式化