CF 1370D 浜屽垎 2e5
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了CF 1370D 浜屽垎 2e5相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/int' title='int'>int
names 閫夋嫨 color its font main style while 1 #include<bits/stdc++.h>
2 #define ll long long
3 #define INF 1e17
4 using namespace std;
5 const int N = 2e5 + 10;
6 ll n, k;
7 ll a[N];
8
9 bool check(ll mid, ll cur)
10 {
11 int len = 0;
12 for(int i = 1 ; i <= n ; i++){
13 if(cur){
14 if(a[i] <= mid){
15 len++;
16 cur ^= 1;
17 }
18 }else{
19 len++;
20 cur ^= 1;
21 }
22 }
23 return len >= k;
24 }
25
26 int main(){
27 scanf("%lld%lld",&n,&k);
28 for(int i = 1 ; i <= n ; i++){
29 scanf("%lld",&a[i]);
30 }
31 ll l = 1, r = INF;
32 while(l < r)
33 {
34 ll mid = (l + r) >> 1;
35 if(check(mid, 0) || check(mid, 1)){
36 r = mid;
37 }else{
38 l = mid + 1;
39 }
40 }
41 printf("%lld
",l);
42
43 return 0;
44 }
涓や釜check杩涜T/F鍒ゆ柇锛屽浜庣被浼?0101鎴?1010鐨勬儏鍐碉紝鎴戝彧闇€瑕佽€冭檻鍙栨墍鏈?浣嶄笂鐨勫€间腑鐨勬渶澶т綔涓烘渶灏忥紝鍗硆es锛岃€?浣嶄笂鐨勬暟鍊煎垯鍙互浠绘剰閫夋嫨锛涗袱涓猚heck鍒氬ソ鍙互瑕嗙洊鎵€鏈夋儏鍐点€?/span>
以上是关于CF 1370D 浜屽垎 2e5的主要内容,如果未能解决你的问题,请参考以下文章
hdu 6406 Taotao Picks Apples 锛?018 Multi-University Training Contest 8 1010锛夛紙浜屽垎锛屽墠缂€鍜岋級