FZU_2216 The Longest Straight (二分)
来源:互联网 发布:巴丁算法集app 编辑:程序博客网 时间:2024/06/05 06:04
Accept: 441 Submit: 1380
Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
ZB is playing a card game where the goal is to make straights. Each card in the deck has a number between 1 and M(including 1 and M). A straight is a sequence of cards with consecutive values. Values do not wrap around, so 1 does not come after M. In addition to regular cards, the deck also contains jokers. Each joker can be used as any valid number (between 1 and M, including 1 and M).
You will be given N integers card[1] .. card[n] referring to the cards in your hand. Jokers are represented by zeros, and other cards are represented by their values. ZB wants to know the number of cards in the longest straight that can be formed using one or more cards from his hand.
Input
The first line contains an integer T, meaning the number of the cases.
For each test case:
The first line there are two integers N and M in the first line (1 <= N, M <= 100000), and the second line contains N integers card[i] (0 <= card[i] <= M).
Output
For each test case, output a single integer in a line -- the longest straight ZB can get.
Sample Input
Sample Output
Source
第六届福建省大学生程序设计竞赛-重现赛(感谢承办方华侨大学)#include<iostream>#include<algorithm>#include<cstring>#include<cmath>#include<queue>#include<set>#include<cstdio>#define ll long long#define mset(a,x) memset(a,x,sizeof(a))using namespace std;const double PI=acos(-1);const int inf=0x3f3f3f3f;const double esp=1e-6;const int maxn=1e6+5;const int mod=1e9+7;int dir[4][2]={0,1,1,0,0,-1,-1,0};ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}ll lcm(ll a,ll b){return a/gcd(a,b)*b;}ll inv(ll b){if(b==1)return 1; return (mod-mod/b)*inv(mod%b)%mod;}ll fpow(ll n,ll k){ll r=1;for(;k;k>>=1){if(k&1)r=r*n%mod;n=n*n%mod;}return r;}int map[100005],ans[100005];int main(){int n,m,i,j,k,t,x;scanf("%d",&t);while(t--){scanf("%d%d",&n,&m);mset(map,0);mset(ans,0);int sum=0;for(i=0;i<n;i++){scanf("%d",&x);if(x==0)sum++;elsemap[x]=1;} for(i=1;i<=m;i++){if(map[i])ans[i]=ans[i-1];elseans[i]=(ans[i-1]+1);}int maxx=0;for(i=0;i<=m;i++){int l=i,r=m,mid;while(l<=r){mid=(l+r)/2;if(ans[mid]-ans[i]>sum)r=mid-1;elsel=mid+1;}maxx=max(maxx,r-i);}cout<<maxx<<endl;}return 0;}
- FZU_2216 The Longest Straight (二分)
- Fzuoj 2216 The Longest Straight 【二分 || 模拟】
- FZU 2216 The Longest Straight (二分)
- FZU 2216 The Longest Straight 枚举+二分
- FZU 2216 The Longest Straight (二分)
- fzu 2216 The Longest Straight 二分
- 福建省赛--Problem E The Longest Straight(标记+二分)
- FZUoj 题目2216 The Longest Straight*(二分)
- FZU 2216 The Longest Straight (二分+01优化)
- The Longest Straight
- FZU2216 The Longest Straight
- The Longest Straight FZU
- The Longest Straight(FZU2216)
- fzu 2216 The Longest Straight
- fzu 2216 The Longest Straight
- 2015福建省赛 fzoj The Longest Straight 2216 (二分&转换)好题
- FOJ Problem 2216 The Longest Straight
- 2015福建省赛 fzoj The Longest Straight
- three.js轨道控制器OrbitControls.js
- 55. 时间服务器 : NTP 服务器
- 队列(Queue)
- (一)java基础篇笔记库(1)
- 常用布局效果09-表格布局
- FZU_2216 The Longest Straight (二分)
- clock_gettime()
- ZooKeeper 命令操作
- 《超越需求 敏捷思维模式下的分析》
- 基于SSH框架-CRM客户资源管理系统-简单小项目开发记录-CRM系统-02
- 判断从键盘输入的大括号是否匹配
- 【面试】--三个线程轮流打印ABC
- BootStrap(1)——排版、代码、表格和按钮
- 分页结果做缓存报java.lang.Integer cannot be cast to java.lang.String错误