栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

poj 2623 Sequence Median

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

poj 2623 Sequence Median

#include <string>#include <vector>#include <algorithm>#include <iostream>#include <sstream>#include <fstream>#include <map>#include <set>#include <cstdio>#include <cmath>#include <cstdlib>#include <ctime>#include <queue>#include <utility>#include <cstring>#include <list>#include <stack>#include <cstdio>using namespace std;#define ft first#define sd secondtypedef long long LL;typedef unsigned int UI;const int MAXN = 511111;const int MOD = 1e9 + 7;const double eps = 1e-6;const LL MAXL = (0x7fffffffffffffffLL);const int MAXI = 0x7fffffff;long long a[1111111];int partition(int l, int r) {    int i = rand() % (r - l + 1) + l;    swap(a[l], a[i]);    int s = l, e = r;    LL pivot = a[l];    while (s < e) {        while (s < e && a[e] > pivot) e--;        if(s < e) a[s++] = a[e];        while (s < e && a[s] < pivot) s++;        if(s < e) a[e--] = a[s];    }    a[s] = pivot;    return s;}LL solve(int l, int r, int k) {    int p = partition(l, r);    if (p == k) {        return a[p];    }    if (k > r || k < 0) {        return -1;    }    if (k < p) {        return solve(l, p-1, k);    }    if (k > p) {        return solve(p+1, r, k);    }    return 0;}int main() {    int n, k;    while (cin >> n) {        for (int i = 1; i <= n; i++) scanf("%lld", a+i);        sort(a+1, a+n+1);        if(n&1) printf("%.1fn", a[(n+1)/2]*1.0);        else printf("%.1fn", (a[n/2]*1.0+a[n/2+1]*1.0)/2);    }}
转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/366293.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号