百题计划-5 codeforces 651 div2 D. Odd-Even Subsequence 二分检查
https://codeforces.com/contest/1370/problem/D
二分检查

#include<bits/stdc++.h> using namespace std; typedef long long ll;
const int maxn=200100;
const int INF=(1LL<<30);
const ll MOD=1e9+7; int n,k;
int a[maxn];
/**
奇数位 from 1
k%2==0,不能取n 偶数位 from 2
k%2==1,不能取n
*/ bool check_odd(int m){
int cnt=(k+1)/2;
int last=0;
for(int i=1;i<=n;i++){
if(a[i]<=m) cnt--,last=i,i++;
if(cnt==0) break;
}
if(cnt==0){
if(k%2==0) return last!=n;
return 1;
}
return 0;
} bool check_even(int m){
int cnt=k/2;
int last=0;
for(int i=2;i<=n;i++){
if(a[i]<=m) cnt--,last=i,i++;
if(cnt==0) break;
}
if(cnt==0){
if(k%2) return last!=n;
return 1;
}
return 0;
} bool check(int m){
return check_odd(m) || check_even(m);
} int bin(int l,int r){
if(k==1) return l;
int res=r;
while(l<=r){
int m=(l+r)>>1;
if(check(m)) res=min(res,m),r=m-1;
else l=m+1;
}
return res;
} int main(){
while(cin>>n>>k){
int max_a=0,min_a=MOD;
for(int i=1;i<=n;i++) cin>>a[i],max_a=max(max_a,a[i]),min_a=min(min_a,a[i]);
cout<<bin(min_a,max_a)<<endl;
}
return 0;
}
百题计划-5 codeforces 651 div2 D. Odd-Even Subsequence 二分检查的更多相关文章
- 【第一期百题计划进行中,快来打卡学习】吃透java、细化到知识点的练习题及笔试题,助你轻松搞定java
[快来免费打卡学习]参与方式 本期百题计划开始时间:2022-02-09,今日打卡题已在文中标红. 0.本文文末评论区打卡,需要登录才可以打卡以及查看其他人的打卡记录 1.以下练习题,请用对应的知识点 ...
- CF&&CC百套计划1 Codeforces Round #449 B. Ithea Plays With Chtholly
http://codeforces.com/contest/896/problem/B 题意: 交互题 n张卡片填m个1到c之间的数,1<=n*ceil(c/2)<=m 最后填出一个单调非 ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits
http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...
- CF&&CC百套计划4 Codeforces Round #276 (Div. 1) E. Sign on Fence
http://codeforces.com/contest/484/problem/E 题意: 给出n个数,查询最大的在区间[l,r]内,长为w的子区间的最小值 第i棵线段树表示>=i的数 维护 ...
- CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)
http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation
http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik
http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding
http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...
- CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods
http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...
- CF&&CC百套计划1 Codeforces Round #449 A. Nephren gives a riddle
http://codeforces.com/contest/896/problem/A 第i个字符串嵌套第i-1个字符串 求第n个字符串的第k个字母 dfs #include<map> # ...
随机推荐
- Vue3 ref 模板引用获取不到节点
ref模板引用必须要在组件实例挂载完成之后才可以访问.如果你是在组合式 API 里面写的组件,那么 setup 函数比任何周期函数都早,所以不可能在该函数中执行时获取得到ref--组件实例. 官网关于 ...
- VueRouter 报错:inject() can only be used inside setup() or functional components
单独创建的一个文件,封装了登录函数的业务逻辑,出现了一个警告,紧接着就是报错:说不能读取到路由的 push 函数.路由必须在组件里面使用,不能在 ts 或 js 文件中使用. 还要注意的点是,在使用路 ...
- QQ空间数据抓取
title: QQ空间数据抓取 author: 杨晓东 permalink: QQ空间数据抓取 date: 2021-10-02 11:27:04 categories: - 嗯哼 tags: - 无 ...
- CF1744F MEX vs MED
个人思路: 条件可以转化成长度为 \(x\) 的区间需要包含 \([0,\lfloor \frac{(x-1)}{2} \rfloor]\). 我们从小到大枚举每一个数 \(i\),计算长度为 \(i ...
- 【1】第一篇 Postman的初级使用之设置环境快速切换生成环境与测试环境
POSTMAN是有谷歌的开源工具,在开发调试.测试执行过程中使用频率非常广泛,本文将记录一些postman在测试中常见的一些配置和使用方法 一.基本的页面区域 略,很简单,大家都会看,再有,学习下面的 ...
- 09 spark连接mysql数据库
安装启动检查Mysql服务.netstat -tunlp (3306) spark 连接mysql驱动程序.–cp /usr/local/hive/lib/mysql-connector-java-5 ...
- 回归分析 3.X 多元线性回归
多元线性回归模型 参数估计 模型表示 我们先将模型 \[y_{i}=\beta_{0}+\beta_{1} x_{i 1}+\cdots+\beta_{p} x_{i k}+\epsilon_{i}, ...
- CodeGym自学笔记07——入门Java书籍
入门Java书籍 Head First Java Java:The Complete Reference,作者:Herbert Schildt 这本书对初学者也很有好处.与前一本书的主要区别在于素 ...
- mysql主从故障跳过错误
mysql主从故障跳过错误1.从库报错 21,22,23,25无法执行Retrieved_Gtid_Set: 265c6c2a-86ca-11ed-b07a-0242ac120002:1-25Exec ...
- JAVA线段树模板
public class LineTree{ int[] tree,nums; int n; public LineTree(int[] nums){ this.nums = nums; n = nu ...