The Longest Straight(FZUoj2216)

Accept: 82 Submit: 203
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
7 11
0 6 5 3 0 10 11
8 1000
100 100 100 101 100 99 97 103
Sample Output
3
Source
第六届福建省大学生程序设计竞赛-重现赛(感谢承办方华侨大学)
思路:尺取法,先将哪些点是否出现过标记,并记录0的个数,然后再前缀数组统计1到M中的未出现的数字,
在用尺取法跑一遍区间取最长就可以了。
#include<stdio.h>#include<algorithm>#include<iostream>#include<stdlib.h>#include<string.h>using namespace std;int aa[100005];int bb[100005];int main(void){ int n,i,j,k,p,q; scanf("%d",&k); while(k--) { memset(aa,0,sizeof(aa)); memset(bb,0,sizeof(bb)); scanf("%d %d",&p,&q);int ma=0; for(i=0; i<p; i++) { scanf("%d",&n); aa[n]++; if(ma<n) { ma=n; } } int cnt=aa[0]; bb[0]=0;ma=min(ma+cnt,q); for(i=1; i<=q; i++) { if(!aa[i]) { bb[i]=bb[i-1]+1; } else { bb[i]=bb[i-1]; } } int ll=1; int rr=1; int maxx=0; while(rr<=ma&&ll<=rr+1) { while(bb[rr]-bb[ll-1]<=cnt&&rr<=ma) { rr++; } maxx=max(maxx,(rr-ll)); ll++; } printf("%d\n",maxx); } return 0;}
}
The Longest Straight(FZUoj2216)的更多相关文章
- FZU 2216 The Longest Straight(最长直道)
Description 题目描述 ZB is playing a card game where the goal is to make straights. Each card in the dec ...
- The Longest Straight(二分,离散化)
Problem 2216 The Longest Straight Accept: 7 Submit: 14 Time Limit: 1000 mSec Memory Limit : 3 ...
- FZU-2216 The Longest Straight (二分枚举)
题目大意:给n个0~m之间的数,如果是0,那么0可以变为任意的一个1~m之间的一个数.从中选出若干个数,使构成一个连续的序列.问能构成的最长序列的长度为多少? 题目分析:枚举连续序列的起点,二分枚举二 ...
- FZU 2216——The Longest Straight——————【二分、枚举】
Problem 2216 The Longest Straight Accept: 17 Submit: 39Time Limit: 1000 mSec Memory Limit : 32 ...
- FZU-2216 The Longest Straight(尺取法)
Problem 2216 The Longest Straight Accept: 523 Submit: 1663Time Limit: 1000 mSec Memory Limit ...
- FZU 2216 The Longest Straight 模拟
题目链接:The Longest Straight 就是一个模拟就是这样,T_T然而当时恶心的敲了好久,敲完就WA了,竟然有这么简单的方法,真是感动哭了.......xintengziji...zhi ...
- 福建省赛--Problem E The Longest Straight(标记+二分)
Problem E The Longest Straight Accept: 71 Submit: 293 Time Limit: 1000 mSec Memory Limit : 327 ...
- LeetCode算法题-Longest Palindrome(五种解法)
这是悦乐书的第220次更新,第232篇原创 01 看题和准备 今天介绍的是LeetCode算法题中Easy级别的第87题(顺位题号是409).给定一个由小写或大写字母组成的字符串,找到可以用这些字母构 ...
- UVA10100:Longest Match(最长公共子序列)&&HDU1458Common Subsequence ( LCS)
题目链接:http://blog.csdn.net/u014361775/article/details/42873875 题目解析: 给定两行字符串序列,输出它们之间最大公共子单词的个数 对于给的两 ...
随机推荐
- addict, address, adequate
addict Addiction is a biopsychosocial disorder characterized by repeated use of drugs, or repetitive ...
- STM32一些特殊引脚做IO使用的注意事项
1 PC13.PC14.PC15的使用 这三个引脚与RTC复用,<STM32参考手册>中这样描述: PC13 PC14 PC15需要将VBAT与VDD连接,实测采用以下程序驱动4个74HC ...
- ping (网络诊断工具)
Ping是Windows.Unix和Lnix系统下的一个命令,ping也属于一个通信协议,是TCP/IP协议的一部分,利用Ping命令可以检查网络是否连通,可以很好地帮助我们分析和判定网络故障.应用格 ...
- 监测linux系统负载与CPU、内存、硬盘、用户数的shell脚本
本节主要内容: 利用Shell脚本来监控Linux系统的负载.CPU.内存.硬盘.用户登录数. 一.linux系统告警邮件脚本 # vim /scripts/sys-warning.sh #!/bin ...
- Dubbo管控平台
2019年初,官方发布了Dubbo管理控制台0.1版本.结构上采取了前后端分离的方式,前端使用Vue和Vuetify分别作为Javascript框架和UI框架,后端采用Spring Boot框架 一. ...
- 【Java 8】函数式接口(二)—— 四大函数接口介绍
前言 Java8中函数接口有很多,大概有几十个吧,具体究竟是多少我也数不清,所以一开始看的时候感觉一脸懵逼,不过其实根本没那么复杂,毕竟不应该也没必要把一个东西设计的很复杂. 几个单词 在学习了解之前 ...
- Web容器(tomcat服务器)处理JSP文件请求的三个阶段
Web容器(tomcat服务器)处理JSP文件请求的三个阶段 翻译:编写好的jsp文件被web容器中的jsp引擎转换成java源码. 编译:翻译成java源码的jsp文件会被编译成可被计算机执行的字节 ...
- 【划重点】Python matplotlib绘图设置坐标轴的刻度
一.语法简介 plt.xticks(ticks,labels,rotation=30,fontsize=10,color='red',fontweight='bold',backgroundcolor ...
- Linux网络编程入门
(一)Linux网络编程--网络知识介绍 Linux网络编程--网络知识介绍客户端和服务端 网络程序和普通的程序有一个最大的区别是网络程序是由两个部分组成的--客户端和服务器端. 客户 ...
- [BUUCTF]REVERSE——[GWCTF 2019]pyre
[GWCTF 2019]pyre 附件 步骤: 1.附件是pyc文件,用python打不开,百度后得知用python反编译工具打开,分享一个python反编译在线网站 反编译后是这段代码 #!/usr ...