POJ 3320 Jessica's Reading Problem (原来标题在这里改……)
2016-10-30 00:00
260 查看
点击就送屠龙宝刀
题目大意:
有个人想参加一个考试(考试……?)然后他就想看书复习,然后他懒……并且书不咋地,知识点重复且散乱,然后他就想通过看最少的连续的页数覆盖到全部的知识点(偷懒还能考好……Orz)
求最少的连续的阅读页数……
样例输入:
5
1 8 8 8 1
样例输出:
2(看第一页和第二页)
朴素的尺取法
题目大意:
有个人想参加一个考试(考试……?)然后他就想看书复习,然后他懒……并且书不咋地,知识点重复且散乱,然后他就想通过看最少的连续的页数覆盖到全部的知识点(偷懒还能考好……Orz)
求最少的连续的阅读页数……
样例输入:
5
1 8 8 8 1
样例输出:
2(看第一页和第二页)
朴素的尺取法
#include <iostream> #include <cstdio> #include <algorithm> #include <cstring> using namespace std; const int MAXN = 1E6 + 5; int a[MAXN]; int dis[MAXN],tot; int where(int x) { int l = 0,r = tot; while(l <= r) { int mid = (l + r) >> 1; if(x < dis[mid]) r = mid; if(x == dis[mid]) return mid; if(x > dis[mid]) l = mid + 1; } return false; /*x = lower_bound(dis+1,dis+1+tot,x)-dis; return x;*/ } int tong[MAXN],ans; int n; int cqf() { int l = 1,r = 0,minn = 1E8; while(true) { while(ans < tot && r < n) if(!tong[where(a[++r])]++) ans++; if(ans < tot) return minn; minn = min(minn,r - l + 1); if(!--tong[where(a[l++])]) ans--; } } int main() { while(~scanf("%d",&n)) { memset(dis,0,sizeof(dis)); tot = 0; ans = 0; memset(a,0,sizeof(a)); memset(tong,0,sizeof(tong)); for(int i = 1;i <= n;i ++) { scanf("%d",&a[i]); dis[++tot] = a[i]; } sort(dis + 1,dis + n + 1); tot = unique(dis + 1,dis + n + 1) - (dis + 1); printf("%d\n",cqf()); } return 0; }
相关文章推荐
- POJ 3320 Jessica's Reading Problem (原来标题在这里改……)
- POJ 3320: Jessicas 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
- Jessica's Reading Problem POJ - 3320
- POJ 3320 Jessica's Reading Problem (HASH, 尺取法)
- POJ 3320 Jessica's Reading Problem (尺取法_滑动窗口,阅读最少页数)
- POJ 3320 Jessica's Reading Problem (STL)
- 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【尺取fa,Two Pointers 量身定做】
- 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