Problem E The Longest Straight

Accept: 71    Submit: 293
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

2
7 11
0 6 5 3 0 10 11
8 1000
100 100 100 101 100 99 97 103


Sample Output

5
3

#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int num[100100],flog[100100];
int main()
{
int t;
scanf("%d",&t);
while(t--)
{
int n,m,s,zero=0;
memset(flog,0,sizeof(flog));
memset(num,0,sizeof(num));
scanf("%d%d",&n,&m);
for(int i=0;i<n;i++)
{
scanf("%d",&s);
if(s)
num[s]=1;
else
zero++;
}
flog[0]=0;
for(int i=1;i<=m;i++)
{
if(num[i])
flog[i]=flog[i-1];
else
flog[i]=flog[i-1]+1;
}
int L=-1000000;
for(int i=0;i<=m;i++)
{
int l=i,r=m;
int mid;
while(l<=r)
{
mid=(l+r)/2;
if(flog[mid]-flog[i]>zero)
r=mid-1;
else
l=mid+1;
}
L=max(L,r-i);
}
printf("%d\n",L);
}
return 0;
}

福建省赛--Problem E The Longest Straight(标记+二分)的更多相关文章

  1. FZU 2216——The Longest Straight——————【二分、枚举】

    Problem 2216 The Longest Straight Accept: 17    Submit: 39Time Limit: 1000 mSec    Memory Limit : 32 ...

  2. The Longest Straight(二分,离散化)

     Problem 2216 The Longest Straight Accept: 7    Submit: 14 Time Limit: 1000 mSec    Memory Limit : 3 ...

  3. FZU-2216 The Longest Straight (二分枚举)

    题目大意:给n个0~m之间的数,如果是0,那么0可以变为任意的一个1~m之间的一个数.从中选出若干个数,使构成一个连续的序列.问能构成的最长序列的长度为多少? 题目分析:枚举连续序列的起点,二分枚举二 ...

  4. The Longest Straight(FZUoj2216)

     Problem 2216 The Longest Straight Accept: 82    Submit: 203Time Limit: 1000 mSec    Memory Limit : ...

  5. FZU-2216 The Longest Straight(尺取法)

     Problem 2216 The Longest Straight Accept: 523    Submit: 1663Time Limit: 1000 mSec    Memory Limit ...

  6. FZU 2216 The Longest Straight(最长直道)

    Description 题目描述 ZB is playing a card game where the goal is to make straights. Each card in the dec ...

  7. FZU 2216 The Longest Straight 模拟

    题目链接:The Longest Straight 就是一个模拟就是这样,T_T然而当时恶心的敲了好久,敲完就WA了,竟然有这么简单的方法,真是感动哭了.......xintengziji...zhi ...

  8. 【Floyd最短路】第七届福建省赛 FZU Problem 2271 X

    http://acm.fzu.edu.cn/problem.php?pid=2271 [题意] 给定一个n个点和m条边的无向连通图,问最多可以删去多少条边,使得每两个点之间的距离(最短路长度)不变. ...

  9. (Problem 14)Longest Collatz sequence

    The following iterative sequence is defined for the set of positive integers: n n/2 (n is even) n 3n ...

随机推荐

  1. oauth2.0里回调地址返回code中如何让code不显示在URL里?

    背景: 最近在调用对方提供的oauth2.0接口的时候,返回code在URL显示,但是会影响到本系统调用其他的菜单项的操作,所以想把返回的code值去掉. 解决办法:     想了各种解决办法,目前把 ...

  2. java发送邮件带附件

    package com.smtp; import java.util.Vector; public class MailBean { private String to; // 收件人 private ...

  3. 从头认识Spring-3.4 简单的AOP日志实现-扩展添加检查订单功能,以便记录并检測输入的參数

    这一章节我们再上一个章节的基础上加上一个检查订单功能 1.domain 蛋糕类: package com.raylee.my_new_spring.my_new_spring.ch03.topic_1 ...

  4. 认识一下Kotlin语言,Android平台的Swift

    今天在CSDN首页偶然看到一个贴子JetBrains正式公布Kotlin 1.0:JVM和Android上更好用的语言 看完后,感觉Kotlin语法非常简洁,有一系列动态语言的特点,Lambda表达式 ...

  5. scikit-learn:3.5. Validation curves: plotting scores to evaluate models

    參考:http://scikit-learn.org/stable/modules/learning_curve.html estimator's generalization error can b ...

  6. SPOJ 694/705 后缀数组

    思路: 论文题*n Σn-i-ht[i]+1 就是结果 O(n)搞定~ //By SiriusRen #include <cstdio> #include <cstring> ...

  7. 【原创】Unable to read TLD "META-INF/c.tld" from JAR file 解决方法

    type Exception report message description The server encountered an internal error () that prevented ...

  8. hiho 1564 - 简单dfs + 宏的危害!!!

    题目链接 H公司有 N 台服务器,编号1~N,组成了一个树形结构.其中中央服务器处于根节点,终端服务器处于叶子节点. 中央服务器会向终端服务器发送消息.一条消息会通过中间节点,到达所有的终端服务器.消 ...

  9. 在网页html中嵌入特殊字体

    1.字体格式 .EOT,适用于Internet Explorer 4.0+ .TTF或.OTF,适用于Firefox 3.5.Safari.Opera .SVG,适用于Chrome.IPhone 最常 ...

  10. ActiveMQ学习笔记(8)----ActiveMQ的消息存储持久化

    1. 概述 ActiveMQ不仅支持persistent和non-persistent两种方式,还支持消息的恢复(recovery)方式. 2. PTP Queue的存储是很简单的,其实就是FIFO的 ...