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 二分检查的更多相关文章

  1. 【第一期百题计划进行中,快来打卡学习】吃透java、细化到知识点的练习题及笔试题,助你轻松搞定java

    [快来免费打卡学习]参与方式 本期百题计划开始时间:2022-02-09,今日打卡题已在文中标红. 0.本文文末评论区打卡,需要登录才可以打卡以及查看其他人的打卡记录 1.以下练习题,请用对应的知识点 ...

  2. 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 最后填出一个单调非 ...

  3. CF&&CC百套计划4 Codeforces Round #276 (Div. 1) A. Bits

    http://codeforces.com/contest/484/problem/A 题意: 询问[a,b]中二进制位1最多且最小的数 贪心,假设开始每一位都是1 从高位i开始枚举, 如果当前数&g ...

  4. 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的数 维护 ...

  5. CF&&CC百套计划1 Codeforces Round #449 C. Willem, Chtholly and Seniorious (Old Driver Tree)

    http://codeforces.com/problemset/problem/896/C 题意: 对于一个随机序列,执行以下操作: 区间赋值 区间加 区间求第k小 区间求k次幂的和 对于随机序列, ...

  6. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) E. Jeff and Permutation

    http://codeforces.com/contest/351/problem/E 题意: 给出一些数,可以改变任意数的正负,使序列的逆序对数量最少 因为可以任意加负号,所以可以先把所有数看作正数 ...

  7. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) B. Jeff and Furik

    http://codeforces.com/contest/351/problem/B 题意: 给出一个n的排列 第一个人任选两个相邻数交换位置 第二个人有一半的概率交换相邻的第一个数>第二个数 ...

  8. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) A. Jeff and Rounding

    http://codeforces.com/problemset/problem/351/A 题意: 2*n个数,选n个数上取整,n个数下取整 最小化 abs(取整之后数的和-原来数的和) 先使所有的 ...

  9. CF&&CC百套计划3 Codeforces Round #204 (Div. 1) D. Jeff and Removing Periods

    http://codeforces.com/problemset/problem/351/D 题意: n个数的一个序列,m个操作 给出操作区间[l,r], 首先可以删除下标为等差数列且数值相等的一些数 ...

  10. 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> # ...

随机推荐

  1. 使用flex布局(多行,一行三个),换行后最后一行左右对齐问题

    <html> <head> <style> html, body, ul { margin: 0; padding: 0; } ul { width: 100%; ...

  2. 世界UTC时间时区对照图

  3. 麒麟v10系统安Influxdb2.0教程

    1.下载安装包:wget https://dl.influxdata.com/influxdb/releases/influxdb2-2.1.1-linux-amd64.tar.gz 2.解压 tar ...

  4. 6. Texture

    Texture 作用:可以将默认的贴图转换为自己想要的贴图类型. Texture Type: 贴图类型 Default: 默认的 Normal map: 法线贴图 Editor GUI and Leg ...

  5. DataTransfer.setDragImage()自定义拖拽图像遇到的坑

    发生拖动时,从拖动目标(dragstart事件触发的元素)生成半透明图像,并在拖动过程中跟随鼠标指针.这个图片是自动创建的,你不需要自己去创建它.然而,如果想要设置为自定义图像,那么 DataTran ...

  6. vs2019中添加rdlc的报表设计器

    在Visual studio 2019中,不会默认安装rdlc的报表设计器,所以需要自行添加. 1. 打开VS2019, 找到扩展-->管理扩展 2. 在扩展管理中,点击"联机&quo ...

  7. python threading.Thread暂停、唤醒、退出 不消耗cpu

    class MyThreadSound(threading.Thread): def __init__(self): super(MyThreadSound, self).__init__() sel ...

  8. 高校github课程资源汇总

    序号 学校名称 学校类型 课程资源链接 1 清华大学 Top 计算机系课程攻略 https://github.com/Salensoft/thu-cst-cracker https://github. ...

  9. .net core解决时间格式转换问题或日期取当前时间

    一.时间格式转换 1.新建一个格式化类DatetimeJsonConverter,继承自JsonConverter,然后重写里面的方法 public class DatetimeJsonConvert ...

  10. 【QT+MSVC2015】不安装VS2015,QT配置MSVC2015编译环境

    本文介绍不安装VS2015的情况下在QT5.10中配置MSVC2015编译器. 系统:windows系统 QT版本:5.10.1 所需文件: QT安装程序--qt-opensource-windows ...