首页 > 其他 > 详细

K-th Number(二分答案+尺取法判断)

时间:2020-04-14 12:20:50      阅读:49      评论:0      收藏:0      [点我收藏+]

 

我写的,第二个样例不对,感觉按照题目说的写出来

技术分享图片
#include <bits/stdc++.h>

using namespace std;
const int maxn = 1e5 + 10;
int t,n,m,k,a[maxn],b[maxn];
int c;
int main() {
    //freopen("in","r",stdin);
    ios::sync_with_stdio(0);
    cin >> t;
    while (t--) {
        cin >> n >> k >> m;
        c = 0;
        for (int i = 1; i <= n; i++) {
            cin >>  a[i];
            if(i > 1 ){
                if(abs(a[i] - a[i - 1]) >= k){
                    if(a[i] > a[i - 1])
                        b[++c] = a[i - 1] + k - 1;
                    else  b[++c] = a[i] + k - 1;
                }
            }
        }
        sort(b+1,b+1+c);
        if(c > m) cout << b[m] << endl;
        else cout << b[c] << endl;
    }

    return 0;
}
View Code

https://ac.nowcoder.com/acm/problem/14301

 

https://blog.csdn.net/lzc504603913/article/details/78514649

https://blog.csdn.net/codeswarrior/article/details/82827902

 

K-th Number(二分答案+尺取法判断)

原文:https://www.cnblogs.com/xcfxcf/p/12696764.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!