标签:\n print ons 题意 longest fzu include blank 连续序列
题目链接:http://acm.fzu.edu.cn/problem.php?pid=2216
题意:给你n张纸牌,代表的数字在1至m区间,给出k张joker可以充当任何牌,现在求出最大的连续区间的长度。
题目分析:枚举连续序列的起点,二分枚举二分序列的终点
# include<iostream> # include<cstdio> # include<cstring> # include<algorithm> using namespace std; const int N=1000; int n,m; int sum[N*100+5]; int main() { int T; scanf("%d",&T); while(T--) { scanf("%d%d",&n,&m); memset(sum,0,sizeof(sum)); int a,k=0; for(int i=0;i<n;++i){ scanf("%d",&a); if(a) sum[a]=1; else ++k; } for(int i=1;i<=m;++i) sum[i]+=sum[i-1]; int ans=0; for(int i=1;i<=m;++i){ int l=i,r=m; while(l<=r){ int x=(l+r)>>1; if(sum[x]-sum[i-1]+k>=x-i+1){ ans=max(ans,x-i+1); l=x+1; }else{ r=x-1; } } } printf("%d\n",ans); } return 0; }
福建省赛--Problem E The Longest Straight(二分枚举)
标签:\n print ons 题意 longest fzu include blank 连续序列
原文地址:https://www.cnblogs.com/Fy1999/p/9021902.html