2776: 2015J-完善2-二分-中位数

内存限制:128 MB 时间限制:1.000 S
评测方式:文本比较 命题人:
提交:10 解决:6

题目描述

#include <iostream>
using namespace std;
const int MAXN = 1000;
int n, i, lbound, rbound, mid, m, count;
int x[MAXN];
int main(){
    cin >> n >> m;
    for (i = 0; i < n; i++)
        cin >> x[i];
    lbound = 0;
    rbound = m;
    while (①){
        mid = (lbound + rbound) / 2;
        ②;
        for (i = 0; i < n; i++)
            if (③)
                ④;
        if (count > n / 2)
            lbound = mid + 1;
        else
            ⑤;
        cout<<mid<<" "<<lbound<<" "<<rbound<<" "<<count<<endl;
    }
    cout << rbound << endl;
    return 0;
}
	(中位数) 给定 n(n 为奇数且小于 1000)个整数,整数的范围在0∼m(0<m<231) 之间,




	请使用二分法求这 n 个整数的中位数。所谓中位数,是指将这 n 个数排序之后,排在正中间的数。


来源/分类