FZUoj 题目2216 The Longest Straight*(二分)
来源:互联网 发布:淘宝客发单机器人 编辑:程序博客网 时间:2024/06/05 06:42
Accept: 22 Submit: 44
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<stdio.h>#include<string.h>#include<stdlib.h>#include<iostream>#include<math.h>#include<algorithm>#define LL long long#define INF 0x3f3f3f3fusing namespace std;int vis[100010],num[100010];void init(int m){ int i; for(i=0;i<=m;i++) vis[i]=0;}int bseach_l(int l,int r,int val){ int ans=r; int tl=l; while(l<=r) { int mid=(l+r)>>1; if(num[mid]-num[tl]>val) { // ans=mid; //l=mid+1; r=mid-1; } else l=mid+1; } return r;}int main(){ int t; scanf("%d",&t); while(t--) { int n,m; scanf("%d%d",&n,&m); int i; int cnt=0; memset(vis,0,sizeof(vis)); for(i=0;i<n;i++) { int x; scanf("%d",&x); if(x==0) { cnt++; continue; } vis[x]=1; } int ans=0,tc=cnt,pt; memset(num,0,sizeof(num)); for(i=1;i<=m;i++) { if(vis[i]) num[i]=num[i-1]; else num[i]=num[i-1]+1; } for(i=0;i<=m;i++) { int temp=bseach_l(i,m,cnt); ans=max(temp-i,ans); } printf("%d\n",ans); }}
- FZUoj 题目2216 The Longest Straight*(二分)
- Fzuoj 2216 The Longest Straight 【二分 || 模拟】
- FZU 2216 The Longest Straight (二分)
- FZU 2216 The Longest Straight (二分+01优化)
- FZU 2216 The Longest Straight 枚举+二分
- FZU 2216 The Longest Straight (二分)
- fzu 2216 The Longest Straight 二分
- FZU_2216 The Longest Straight (二分)
- 2015福建省赛 fzoj The Longest Straight 2216 (二分&转换)好题
- fzu 2216 The Longest Straight
- fzu 2216 The Longest Straight
- The Longest Straight(FZU2216)
- FZOJ 2216 The Longest Straight (尺取法)
- FOJ Problem 2216 The Longest Straight
- 福建省赛--Problem E The Longest Straight(标记+二分)
- The Longest Straight
- FZU2216 The Longest Straight
- The Longest Straight FZU
- 145Binary Tree Postorder Traversal
- T-SQL
- API & SPI
- UVA331 Mapping the Swaps
- 部署发布wb程序的时候,最好清一下tomcat目录下的work文件夹
- FZUoj 题目2216 The Longest Straight*(二分)
- 让OpenCV枚举所有摄像头-附如何建立Windows下的OpenCV工程
- 在构造器中调用构造器
- 简单 sql 语句 实用大全
- 《神经网络与深度学习》讲义1—数学基础
- DoTween - 动画重复播放
- 《Monkey Android》第3课之Android Studio简介与模拟器
- 运算放大器选型及其要求
- java 集合(6) 选择集合类标准 / Map 接口用法