分析:

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

 #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. view抖动效果

    1.使用属性动画 ViewPropertyAnimator.animate(webView).translationX(20).setInterpolator(new CycleInterpolato ...

  2. silverlight简单数据绑定2

    <Grid x:Name="LayoutRoot" Background="white" Loaded="LayoutRoot_Loaded&q ...

  3. AX Dynamics 去中文字符长度:中文字符当2个字符处理

    static void jw_testStrByteLen(Args _args){    str _str = "A你好";                  System.Te ...

  4. java环境

    http://www.iyunv.com/thread-65867-1-1.html http://www.360doc.com/content/15/0525/19/21365845_4732029 ...

  5. VBA_Excel_教程:过程,函数

    Sub s1() Debug.Print "s1" '调用过程:无括号,加call提升可读性 s2 Call s2 End Sub Sub s2() Debug.Print &qu ...

  6. .net实现调用本地exe等应用程序的办法总结

    根据客户需求用户要实现在一个BS系统上打开本地的一应用程序,在网上查了好多资料再加上自己的各种测试,到最后功能是实现了,只不过还存在一些问题,接下来会先把各种方法一一列举出来 1.先写最终测试通过的这 ...

  7. MySQL定时执行脚本(计划任务)命令实例

    在mysql中我们可以直接进行一些参数设置让它成定时为我们执行一些任务了,这个虽然可以使用windows或者linux中的计划任务实现,但是mysql本身也能完成 查看event是否开启 复制代码 代 ...

  8. MVC导出Excel,提供下载Excel

    类1: using System.Collections.Generic;using System.Data;using System.Web.Mvc;using System.IO;using Sy ...

  9. windows 10启动盘制作工具

    Rufus 官方网站:http://rufus.akeo.ie/

  10. FizzlerEx —— 另一个HtmlAgilityPack的CSS选择器扩展,

    之前我介绍过HtmlAgilityPack的CSS选择器扩展——ScrapySharp,它可以非常方便的实现通过CSS选择器表达式来查询HtmlNode.今天在使用的过程中,发现它不支持nth-chi ...