百题计划-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> # ...
随机推荐
- Word 段落首行缩进
描述 使 Word 段落第一行左突出两个字符的位置,即段落首行缩进的方式有两种. "视图"选项卡--"显示"组--标尺 "开始"选项卡--& ...
- 在 Ubuntu 22 的基础上进行 Hadoop 伪分布式(HDFS)的搭建
一.使用VMware安装Ubuntu虚拟机 在Linux系统各个发行版中,Ubuntu系统在服务端和桌面端使用占比最高,网络上资料最是齐全,所以这里使用Ubuntu LTS. 整体的系统安装文件较大( ...
- c++_成员函数回调
//--------------------------------------------------------------------------- #include <vcl.h> ...
- c#反射优化
https://www.cnblogs.com/xinaixia/p/5777886.html https://www.cnblogs.com/xinaixia/p/5777961.html
- vue3中对于/deep/和::v-deep的警告信息处理
目前发现两处警告信息: ::v-deep usage as a combinator has been deprecated. Use :deep() instead. the >>> ...
- CF生化全模式全装备单机版安装教程(基于CSOL)
喜欢玩CF单机版的朋友平时应该接触过一些基于CS1.6的单机版,但是这种版本有些特性就是:改了分辨率就容易进不去游戏:变为幽灵时被枪射击时会出现视角乱晃的情况:游戏过程中场景宏大变数多时容易突然退出回 ...
- VS2022 17.1.6在windows10下打开winform设计器报timed out while connecting to named pipe错误
.net 6.0的项目,vs2022 17.1.6在windows10下打开winform设计器报timed out while connecting to named pipe错误,同样的项目在wi ...
- go 下的查询数据库的框架 ORM框架:访问mysql数据库
运维的基友 习惯使用python了,学习go的时候是不是被gorm 恶心死了 例如python flask 框架下的orm那么好用简单 ,或者号称 世界上最好用的语言php的同学们也是非常的苦恼呢 很 ...
- iOS开发之长按浮动操作选择项
我们一般会有长按一段文字显示气泡浮动操作选项的需求 我们常用的方法如下 cut: copy: select: selectAll: paste: delete: _promptForRep ...
- PCB走线宽度与电流、温度的关系
测试PCB的线长为24cm 其他: