2015福建省赛 fzoj The Longest Straight 2216 (二分&转换)好题
来源:互联网 发布:同花顺指标公式源码 编辑:程序博客网 时间:2024/05/16 05:41
Accept: 5 Submit: 12
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
#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int a[100010];int b[100010];int main(){int t,n,m,x;int i,j,k;scanf("%d",&t);while(t--){memset(a,0,sizeof(a));int zero=0;scanf("%d%d",&n,&m);for(i=0;i<n;i++){scanf("%d",&x);if(x)a[x]=1;elsezero++;}b[0]=0;for(i=1;i<=m;i++){if(a[i])b[i]=b[i-1];elseb[i]=b[i-1]+1;}int mm=0;for(i=0;i<=m;i++){int l=i,r=m;int mid;while(l<=r){mid=(l+r)/2;if(b[mid]-b[i]>zero)r=mid-1;elsel=mid+1;}mm=max(mm,r-i);}printf("%d\n",mm);}return 0;}
- 2015福建省赛 fzoj The Longest Straight 2216 (二分&转换)好题
- 2015福建省赛 fzoj The Longest Straight
- 福建省赛--Problem E The Longest Straight(标记+二分)
- FZOJ 2216 The Longest Straight (尺取法)
- FZU Problem 2216 The Longest Straight(二分答案+树状数组)——第六届福建省大学生程序设计竞赛-重现赛
- FZU 2216 The Longest Straight (二分)
- FZUoj 题目2216 The Longest Straight*(二分)
- FZU 2216 The Longest Straight (二分+01优化)
- Fzuoj 2216 The Longest Straight 【二分 || 模拟】
- FZU 2216 The Longest Straight 枚举+二分
- FZU 2216 The Longest Straight (二分)
- fzu 2216 The Longest Straight 二分
- 2015福建省赛 fzoj Super Mobile Charger 2212 (转换)
- FZU_2216 The Longest Straight (二分)
- 2015福建省赛 fzoj Knapsack problem 2214 (01背包&转换)
- FOJ 2216 The Longest Straight 第六届福建省大学生程序设计竞赛 E 尺取法乱搞
- 2015福建省赛 fzoj RunningMan 2221 (数学博弈)
- fzu 2216 The Longest Straight
- uva757
- Fedor and New Game
- HttpWatchPro-ha-crack抓包器怎么没有中文版本
- 每日一vim(0)
- win8 系统中安装了oracle11g及PL/SQL Developer如何连接64位oracle
- 2015福建省赛 fzoj The Longest Straight 2216 (二分&转换)好题
- 蓝桥杯练习--分解质因数
- 04.cocos2d-x多分辨率适配
- 多线程分段下载DownLoader代码
- 《c#之全局观》
- PAT (Basic Level)1002. 写出这个数 (20)
- IOS项目集成ShareSDK实现第三方登录、分享、关注等功能
- Objective-C 的内省
- JavaScript之基础篇