FZU2216【二分】
题意:
百度。
思路:
一个连续数组111222233344444555666的每一个起伏转折即需要一张万能牌。
然后二分一下得最长区间。
#include<cstdio>
#include<cstring>
#include<cmath>
#include<iostream>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
typedef long long LL;
const LL mod=1e9+7;
const int N=1e5+10;
int b[N];
bool vis[N];
int num;
int Search(int left,int right)
{
int L=left;
while(left<right)
{
int mid=left+(right-left+1)/2;
if(b[mid]-b[L]<=num)
left=mid;
else
right=mid-1;
}
return left;
} int main()
{
int T;
scanf("%d",&T);
while(T--)
{
int n,m,x;
scanf("%d%d",&n,&m);
memset(vis,0,sizeof(vis));
num=0;
for(int i=0;i<n;i++)
{
scanf("%d",&x);
if(x==0)
num++;
else
vis[x]=1;
}
b[0]=0;
for(int i=1;i<=m;i++)
{
if(vis[i])
b[i]=b[i-1];
else
b[i]=b[i-1]+1;
}
int res=0;
for(int i=0;i<=m;i++)
res=max(Search(i,m)-i,res);
printf("%d\n",res);
}
return 0;
}
FZU2216【二分】的更多相关文章
- FZU-2216 The Longest Straight (二分枚举)
题目大意:给n个0~m之间的数,如果是0,那么0可以变为任意的一个1~m之间的一个数.从中选出若干个数,使构成一个连续的序列.问能构成的最长序列的长度为多少? 题目分析:枚举连续序列的起点,二分枚举二 ...
- BZOJ1012: [JSOI2008]最大数maxnumber [线段树 | 单调栈+二分]
1012: [JSOI2008]最大数maxnumber Time Limit: 3 Sec Memory Limit: 162 MBSubmit: 8748 Solved: 3835[Submi ...
- BZOJ 2756: [SCOI2012]奇怪的游戏 [最大流 二分]
2756: [SCOI2012]奇怪的游戏 Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 3352 Solved: 919[Submit][Stat ...
- 整体二分QAQ
POJ 2104 K-th Number 时空隧道 题意: 给出一个序列,每次查询区间第k小 分析: 整体二分入门题? 代码: #include<algorithm> #include&l ...
- [bzoj2653][middle] (二分 + 主席树)
Description 一个长度为n的序列a,设其排过序之后为b,其中位数定义为b[n/2],其中a,b从0开始标号,除法取下整. 给你一个长度为n的序列s. 回答Q个这样的询问:s的左端点在[a,b ...
- [LeetCode] Closest Binary Search Tree Value II 最近的二分搜索树的值之二
Given a non-empty binary search tree and a target value, find k values in the BST that are closest t ...
- [LeetCode] Closest Binary Search Tree Value 最近的二分搜索树的值
Given a non-empty binary search tree and a target value, find the value in the BST that is closest t ...
- jvascript 顺序查找和二分查找法
第一种:顺序查找法 中心思想:和数组中的值逐个比对! /* * 参数说明: * array:传入数组 * findVal:传入需要查找的数 */ function Orderseach(array,f ...
- BZOJ 1305: [CQOI2009]dance跳舞 二分+最大流
1305: [CQOI2009]dance跳舞 Description 一次舞会有n个男孩和n个女孩.每首曲子开始时,所有男孩和女孩恰好配成n对跳交谊舞.每个男孩都不会和同一个女孩跳两首(或更多)舞曲 ...
随机推荐
- Django创建模型_模型层
1.在项目Mysite下创建应用bms 2.在bms下的models.py文件中创建模型 from django.db import models # Create your models here. ...
- php标准库DirectoryIterator类的操作说明
<?php $dir = new DirectoryIterator(dirname(__FILE__)); foreach ($dir as $fileInfo) { if ($fileInf ...
- Table control 相关
转:晚上回去有时间看看 http://help.sap.com/saphelp_nw04/helpdata/en/9f/dbac1d35c111d1829f0000e829fbfe/frameset. ...
- matlab vs使用
~ matlab无论什么程序只输出 ans 1 注意matlab命名规则:1不能与matlab内部函数名字重合.2.文件名首字母不能是数字或下划线.3.文件名中不能有空格.4.文件名不能太长.5注意大 ...
- 【shell】常用的正则表达式
一.校验数字的表达式 1 数字:^[0-9]*$ 2 n位的数字:^\d{n}$ 3 至少n位的数字:^\d{n,}$ 4 m-n位的数字:^\d{m,n}$ 5 零和非零开头的数字:^(0|[1-9 ...
- Why use async requests instead of using a larger threadpool?(转载)
问: During the Techdays here in the Netherlands Steve Sanderson gave a presentation about C#5, ASP.NE ...
- 2018年东北农业大学春季校赛 E wyh的集合 【数学】
题目链接 https://www.nowcoder.com/acm/contest/93/F 思路 其实容易知道在两个不同集合里 假设元素个数 分别为 a b 然后对于第一个集合里的每一个元素 都可以 ...
- nginx+keepalived简单双机主从热备
双机主从热备概述 可以两台机子互为热备,平时各自负责各自的服务.在做上线更新的时候,关闭一台服务器的tomcat后,nginx自动把流量切换到另外一台服务的后备机子上,从而实现无痛更新,保持服务的持续 ...
- TP框架控制器和对应方法创建
控制器和对应方法创建 控制器是MVC模式中的核心,TP默认有一个控制器: Index控制器里面有一个操作方法:Index 我们在访问http://localhost:8080/Thinkphp ...
- CSS样式命名整理
CSS样式命名整理 页面结构 容器: container/wrap 整体宽度:wrapper 页头:header 内容:content 页面主体:main 页尾:footer 导航:nav 侧栏:si ...