尼玛,数组偶数个数的时候取中位数是取中间两者中的前者,还tmd一直再算平均,卧槽

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <vector> using namespace std; int min(int a, int b) {
return a<b? a:b;
} int main() { int na, nb; scanf("%d", &na);
vector<int> a(na); for (int i=; i<na; i++) {
scanf("%d", &a[i]);
} scanf("%d", &nb);
vector<int> b(nb); for (int i=; i<nb; i++) {
scanf("%d", &b[i]);
} int ia = , ib = ; int idx = ;
int mid = (na + nb) / ; int mv = , mv2;
while (ia < na && ib < nb && idx < mid) {
if (a[ia] <= b[ib]) {
mv = a[ia];
ia++;
} else {
mv = b[ib];
ib++;
}
idx++;
} while (ia < na && idx < mid) {
mv = a[ia];
ia++;
idx++;
} while (ib < nb && idx < mid) {
mv = b[ia];
ib++;
idx++;
} if (ia < na && ib < nb) {
mv2 = min(a[ia], b[ib]);
} else if (ia < na) {
mv2 = a[ia];
} else if (ib < nb) {
mv2 = b[ib];
} if ((na + nb) & ) {
// odd
cout<<mv2<<endl;
} else {
// even
cout<<mv<<endl;
} system("pause");
return ;
}

log(na+nb)算法见:http://www.cnblogs.com/lailailai/p/3982103.html

PAT 1029. Median的更多相关文章

  1. PAT 1029 Median[求中位数][难]

    1029 Median(25 分) Given an increasing sequence S of N integers, the median is the number at the midd ...

  2. PAT 1029 Median (25分) 有序数组合并与防坑指南

    题目 Given an increasing sequence S of N integers, the median is the number at the middle position. Fo ...

  3. PAT甲 1029. Median (25) 2016-09-09 23:11 27人阅读 评论(0) 收藏

    1029. Median (25) 时间限制 1000 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given an incr ...

  4. PAT 甲级 1029 Median (25 分)(思维题,找两个队列的中位数,没想到)*

    1029 Median (25 分)   Given an increasing sequence S of N integers, the median is the number at the m ...

  5. 浙大pat 1029题解

    1029. Median (25) 时间限制 400 ms 内存限制 32000 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given an incre ...

  6. 1029 Median (25 分)

    1029 Median (25 分)   Given an increasing sequence S of N integers, the median is the number at the m ...

  7. 【PAT】1029. Median (25)

    Given an increasing sequence S of N integers, the median is the number at the middle position. For e ...

  8. PAT 甲级 1029 Median

    https://pintia.cn/problem-sets/994805342720868352/problems/994805466364755968 Given an increasing se ...

  9. PAT Advanced 1029 Median (25) [two pointers]

    题目 Given an increasing sequence S of N integers, the median is the number at the middle position. Fo ...

随机推荐

  1. 解决 MySQL 1045错误的三种方法 (转)

    连接MySQL数据库时难免会遇到1045错误,主要是因为用户输入的用户名或密码错误被拒绝访问,如果不想重装,需要找回密码或者重置密码. 问题描述: 1045-Access denied for use ...

  2. 初识gulp

    之前一段时间学习使用了gulp自动化构建工具,并在现在使用的项目上部署使用,同时在这做个笔记进行小结,以便加深记忆,如有理解错误的地方请不吝赐教 gulp 的解释我就不多说了 这里引用官网的一句话   ...

  3. iOS开发debug跟release版本NSLog屏蔽方法

    简单介绍以下几个宏: 1) __VA_ARGS__ 是一个可变参数的宏,这个可变参数的宏是新的C99规范中新增的,目前似乎只有gcc支持(VC6.0的编译器不支持).宏前面加上##的作用在于,当可变参 ...

  4. docker阿里云镜像加速器使用

    加速器使用:加快镜像下载速度 访问www.aliyun.com: 登录之后点击”控制台“,选择“产品与服务“: 选择“容器镜像服务“: 设定密码后选择“镜像加速器”:  这里会有一个加速器地址:  在 ...

  5. SQL语句02(连表查询)

    ---恢复内容开始--- sql1992sql分类    1.笛卡尔积 (表乘表) 例:select * from emp,dept;    2.等值连接 表的连接条件使用“=” 例:select * ...

  6. Keras2.2 predict和fit_generator的区别

    1.使用predict时,需设置batch_size 查看keras文档中,predict函数原型:predict(self, x, batch_size=32, verbose=0) 说明:只使用b ...

  7. (一)Audio子系统之AudioRecord.getMinBufferSize

    在文章<基于Allwinner的Audio子系统分析(Android-5.1)>中已经介绍了Audio的系统架构以及应用层调用的流程,接下来,继续分析AudioRecorder方法中的ge ...

  8. Mac下配置git环境和客户端SourceTree+Git常用命令大全(Mac 10.12)

    前言: 如果不想折腾,直接下载GitHub桌面端,高度集成git,不需要学习git的任何命令. https://desktop.github.com/ 一.配置git环境 1.上官网https://g ...

  9. Ubuntu 安装ftp

    Ubuntu 用vsftpd 配置FTP服务器 网上的文章好难懂啊..只想要简单粗暴,弄好能用就行啊,复杂的以后研究不行吗...折腾好久,其实弄出来能用不就这么点内容吗... 本文在Ubuntu Se ...

  10. auguements实参对象的数组化

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...