百题计划-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> # ...
随机推荐
- vue2 使用x2js json转换成xml
安装: 在项目终端运行以下命令 cnpm install x2js --save 引用: // 引入模块 import x2js from 'x2js' 全部代码: <template> ...
- K8S 实用工具之一 - 如何合并多个 kubeconfig?
开篇 引言: 磨刀不误砍柴工 工欲善其事必先利其器 K8S 集群规模,有的公司倾向于少量大规模 K8S 集群,也有的公司会倾向于大量小规模的 K8S 集群. 如果是第二种情况,是否有一个简单的 kub ...
- LeetCode-1220 统计元音字母序列的数目
来源:力扣(LeetCode)链接:https://leetcode-cn.com/problems/count-vowels-permutation 题目描述 给你一个整数 n,请你帮忙统计一下我们 ...
- 使用树莓派PICO点灯
使用树莓派PICO点灯树莓派PICO简介具体步骤方式①下载Thonny软件②为PICO烧录MicroPython固件①下载UF2文件②PICO进入boot模式烧录固件③进行点灯效果总结 具体步骤方式① ...
- sql(上)例题
一.数据库概述 数据库(DataBase,DB):指长期保存在计算机的存储设备上,按照一定规则组织起来,可以被各种用户或应用共享的数据集合. 数据库管理系统(DataBase Management S ...
- 提供一个方法,遍历获取HashMap<String,String>中的所有value,并存放在list中返回,考虑泛型的使用
public List<String> getValueList(HashMap<String,String> map){ ArrayList<String> va ...
- 068_Apex&Page中的ReadOnly 使用方式
一.page页面遇到需要检索大量数据的处理方式需要时会用Readonly 通常,对单个Visualforce页面请求的查询可能无法检索超过50,000行. 在Read only模式下,此限制将放宽允许 ...
- mysqldump备份命令使用参数
参数 参数说明 导出全部数据库. mysqldump -uroot -p --all-databases 导出全部表空间. mysqldump -uroot -p --all-databases -- ...
- 常用ansible命令梳理
命令的具体格式 : ansible <host-pattern> [-f forks] [-m module_name] [-a args] 场景 命令 查询线上所有机器某个文件的含有某个 ...
- 【实验】B站资源免费下载技巧you-get
搭建环境, python pip3 install you-get 查看可以下载格式 you-get -i https://www.bilibili.com/video/BV1yN411d7KH?p ...