分析:

  考察归并排序,用简单的快排会超时。

 #include <iostream>
#include <stdio.h>
#include <algorithm>
#include <cstring>
#include <string>
#include <vector>
#include <cctype>
#include <stack>
#include <map> using namespace std; // 归并排序 int a[];
int b[];
int c[]; int merge(int n, int m)
{
int i = , j = , k = ;
while (i < n && j < m)
{
if (a[i] > b[j])
c[k++] = b[j], j++;
else
c[k++] = a[i], i++;
}
while (i < n)
c[k++] = a[i], i++;
while (j < m)
c[k++] = b[j], j++;
return k;
} int main()
{
int n, m;
while (scanf("%d", &n) != EOF)
{
for (int i = ; i < n; i++)
scanf("%d", &a[i]); scanf("%d", &m);
for (int i = ; i < m; i++)
scanf("%d", &b[i]); int l = merge(n, m); if (l % == )
printf("%d\n", c[l >> ]);
else
printf("%d\n", c[(l - ) >> ]);
}
return ;
}

1029. Median (25)的更多相关文章

  1. 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 ...

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

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

  3. 1029 Median (25 分)

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

  4. 【PAT】1029. Median (25)

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

  5. 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 ...

  6. 1029 Median (25分)

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

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

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

  8. PAT (Advanced Level) 1029. Median (25)

    scanf读入居然会超时...用了一下输入挂才AC... #include<cstdio> #include<cstring> #include<cmath> #i ...

  9. PAT甲题题解-1029. Median (25)-求两序列的中位数,题目更新了之后不水了

    这个是原先AC的代码,但是目前最后一个样例会超内存,也就是开不了两个数组来保存两个序列了,意味着我们只能开一个数组来存,这就需要利用到两个数组都有序的性质了. #include <iostrea ...

随机推荐

  1. java readLine()

    原文 虽然写IO方面的程序不多,但BufferedReader/BufferedInputStream倒是用过好几次的,原因是: 它有一个很特别的方法:readLine(),使用起来特别方便,每次读回 ...

  2. sp_help 快速查看表结构、视图信息

    sp_helptext: 是MS SQL Server的一个系统存储过程,可以通过它来查看存储过程或者视图.函数源码 示例:sp_helptext viewName (viewName  即要查询的存 ...

  3. AX 2012 query应用collections

    QueryBuildRange range; super(); this.query().dataSourceName('VendTop10VendorsByPurchase').clearDynal ...

  4. windows下scrapy 的安装

    2016-07-18  20:27:53 安装python 根据你的需求下载python安装包,安装python(本文基于python27)https://www.python.org/downloa ...

  5. .Net的Excel 导出 格式设置

    添加引用:Microsoft   Excel   11.0   Object   Library ; 添加:using Microsoft.Office.Interop.Excel; 一.打开Exce ...

  6. [转载]: delphi中XLSReadWrite控件的使用(1)---简介

    XLSReadWrite控件简介: 一个你需要的,能在Delphi和.NET下访问Excel文件的完美解决方案. 一个经典的读写Excel的控件,对于使用Excel 开发很有帮助 官方网站: http ...

  7. PHP基于数组的分页函数(核心函数array_slice())

    关于数组的分页函数,用数组进行分页的好处是可以方便的进行联合多表查询,只需要将查询的结果放在数组中就可以了以下是数组分页的函数,函数page_array用于数组的分页,函数show_array用于分页 ...

  8. NHibernate系列文章三:简单的增删改查询

    摘要 上一篇文章只完成了简单的NHibernate安装.配置和连接数据库.这篇文章介绍怎样实现最简单的数据库读写操作. 1. 重构ISessionFactory生成过程 将生成ISessionFact ...

  9. postman-根据接口文档进行测试

    根据接口文档来测试 1.get请求

  10. gsons

    java 处理 json格式字符串,目前只使用过Google的Gson库. pom: <dependency> <groupId>com.google.code.gson< ...