uva 11536——Smallest Sub-Array
来源:互联网 发布:三星scx3400扫描软件 编辑:程序博客网 时间:2024/05/21 17:19
题意:给定n个数,这n个数在m的范围之内。v[i]=(v[i-1]+v[i-2]+v[i-3])%m+1; 然后求一个最短连续子序列使得序列内包括1-k个数。
思路:枚举。枚举以v[i]结尾的最短序列。用ct维护已经找到的k个数中的个数,queue跳转区间。
code:
#include <iostream>#include <cstdio>#include <cmath>#include <algorithm>#include <cstring>#include <sstream>#include <string>#include <vector>#include <list>#include <queue>#include <stack>#include <map>#include <set>#include <bitset>using namespace std;typedef long long ll;typedef unsigned long long ull;typedef long double ld;const int INF=0x3fffffff;const int inf=-INF;const int N=1000000;const int M=2005;const int mod=1000000007;const double pi=acos(-1.0);#define cls(x,c) memset(x,c,sizeof(x))#define cpy(x,a) memcpy(x,a,sizeof(a))#define fr(i,s,n) for (int i=s;i<=n;i++)#define lson l,m,rt<<1#define rson m+1,r,rt<<1|1#define lrt rt<<1#define rrt rt<<1|1#define middle int m=(r+l)>>1#define lowbit(x) (x&-x)#define pii pair<int,int>#define mk make_pair#define IN freopen("in.txt","r",stdin);#define OUT freopen("out.txt","w",stdout);int n,m,k;int v[N],vt[N];int main(){ int T,ca=1,ct,ans; scanf("%d",&T); while (T--) { scanf("%d %d %d",&n,&m,&k); cls(vt,0);ans=INF;ct=0; v[1]=1,v[2]=2,v[3]=3; fr(i,4,n) v[i]=(v[i-1]+v[i-2]+v[i-3])%m+1; queue<int>q; fr(i,1,n) { if (v[i]>=1&&v[i]<=k) { q.push(i); if (vt[v[i]]++==0) ct++; while (ct==k) { int p=q.front();q.pop(); ans=min(ans,i-p+1); if (--vt[v[p]]==0) ct--; } } } printf("Case %d: ",ca++); if (ans==INF) puts("sequence nai"); else printf("%d\n",ans); }}
0 0
- uva 11536——Smallest Sub-Array
- UVA 11536 - Smallest Sub-Array
- UVa 11536 - Smallest Sub-Array
- UVa 11536 Smallest Sub-Array
- Uva - 11536 - Smallest Sub-Array
- uva 11536Smallest Sub-Array
- UVA 11536 Smallest Sub-Array
- Smallest Sub-Array UVA
- uva 11536 - Smallest Sub-Array(Towpointer)
- UVA - 11536 Smallest Sub-Array 纪录
- UVA:11536 Smallest Sub-Array(尺取法)
- UVA 11536(p255)----Smallest Sub-Array
- UVA - 11536 Smallest Sub-Array (滑动窗口)
- ACM UVA 11536 Smallest Sub-Array
- 11536 - Smallest Sub-Array
- uva 11536 - Smallest Sub-Array(two pointers)
- 【uva】11536-Smallest Sub-Array(区间移动问题)
- UVa #11536 Smallest Sub-Array (习题8-17)
- [Android基础]Service
- hdu5534Partial Tree(长春现场赛H题)
- MyBatis之传入参数
- Linux下安装MySQL5.7
- java的三大框架
- uva 11536——Smallest Sub-Array
- 输入格式控制
- [NOIP 2014]解方程 秦九韶算法+质数取模
- 黑马程序员 Java 基础:IO 流
- hdoj 5536 Chip Factory 【字典树】
- 2015.11.1 [XJOI] NOIP模拟赛总结
- 古典问题:有一对兔子,从出生后第3个月起每个月都生一对兔子,小兔子长到第三个月后每个月又生一对兔子,假如兔子都不死,问每个月的兔子总数为多少? 兔子的规律为数列1,1,2,3,5,8,13,21...
- [NOIP 2009]潜伏者 模拟
- hihocoder王胖浩与三角形【海伦公式+分类讨论】