1029. Median (25)
分析:
考察归并排序,用简单的快排会超时。
#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)的更多相关文章
- 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 ...
- PAT 甲级 1029 Median (25 分)(思维题,找两个队列的中位数,没想到)*
1029 Median (25 分) Given an increasing sequence S of N integers, the median is the number at the m ...
- 1029 Median (25 分)
1029 Median (25 分) Given an increasing sequence S of N integers, the median is the number at the m ...
- 【PAT】1029. Median (25)
Given an increasing sequence S of N integers, the median is the number at the middle position. For e ...
- 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 ...
- 1029 Median (25分)
Given an increasing sequence S of N integers, the median is the number at the middle position. For e ...
- PAT 1029 Median (25分) 有序数组合并与防坑指南
题目 Given an increasing sequence S of N integers, the median is the number at the middle position. Fo ...
- PAT (Advanced Level) 1029. Median (25)
scanf读入居然会超时...用了一下输入挂才AC... #include<cstdio> #include<cstring> #include<cmath> #i ...
- PAT甲题题解-1029. Median (25)-求两序列的中位数,题目更新了之后不水了
这个是原先AC的代码,但是目前最后一个样例会超内存,也就是开不了两个数组来保存两个序列了,意味着我们只能开一个数组来存,这就需要利用到两个数组都有序的性质了. #include <iostrea ...
随机推荐
- JS Math对象中一些小技巧
JS中快速获取数组中最大/最小值 var a=[1,2,3,5]; alert(Math.max.apply(Math, a));//最大值 alert(Math.min.apply(Math, a) ...
- OAF_文件系列3_实现OAF多行表中附件功能AttachmentImage(案例)
20150727 Created By BaoXinjian
- PHP取当前年、月、日开始时间戳和下年、月、日开始时间戳函数
1.当前年的时间戳 2.当前月的时间戳 3.当前日的时间戳 4.明年的开始时间戳 5.下月的开始时间戳 6.明日的开始时间戳 7.当前时间戳 函数代码: /** * 获取时间戳 * $Ymd = Y ...
- ruby中proc和lambda的return区别
学习ruby有一段时间了,但是我看了好几遍proc和lambda的return区别的区别讲解,始终没明白到底什么区别,今天上午又看,终于感觉是茅塞顿开有点领悟了 一下内容部分来自<<rub ...
- spring mvc定时任务的简单使用
版权声明:本文为楼主原创文章,未经楼主允许不得转载,如要转载请注明来源. 说起定时任务,开发的小伙伴们肯定不陌生了.有些事总是需要计算机去完成的,而不是傻傻的靠我们自己去.可是好多人对定时器总感觉很陌 ...
- javascript立即执行函数 (function(){})()
看到一段代码: (function(){ var outer = $('#subject'); outer.find('li').on('mouseover', mouseover); })() ( ...
- jquery tmpl遍历
最近发现大家用模板渲染一些顺带逻辑功能代码块时,用jquery tmpl较多,遇到了一些问题,现在就个人以前研究过的一切常用功能作介绍,主要针对遍历,其它的大家可以自行浏览一起网站,如:http:// ...
- Extract QQ from iPhone and analyze it
QQ is one of the most popular chat App in the world. Now let me show you how to extract QQ from iPho ...
- highcharts相关属性
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding= ...
- (知识分享)软硬件调试九法:第九条规则 如果你不修复一个bug,它将永远存在
1.查证问题确已被修复 如果遵循了“制造失败”这条规则,就知道如何验证你确实修复了问题.无论问题和修复看起来多么明显,你都无法保证修复是有效的,直到做了测试并验证. 2.查证确实你的修复措施解决了问题 ...