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 ...
随机推荐
- 阿里 classloader
http://blog.csdn.net/scythe666/article/details/51956047
- android studio新项目时提示:Plugin is too old, please update to a more recent version
今天想写一个程序来测试一下android studo代码,但是创建好项目后,提示: Error:(1, 0) Plugin is too old, please update to a more re ...
- crosswalk-webview
https://github.com/crosswalk-project/cordova-plugin-crosswalk-webview https://cordova.apache.org/doc ...
- 初始化成员列表 ——— 类的const成员和引用成员的初始化
class A { public: A(){}; const int num; CString& s; } A::A() { cout<<A con<<endl; } ...
- PHP常见方法
1.获取字符串长度: preg_match_all('/./us', $only, $match); echo count($match[0]); 2.Php除法取整 2.1.round — 对浮点数 ...
- projecteuler Problem 9 Special Pythagorean triplet
A Pythagorean triplet is a set of three natural numbers, a < b < c, for which, a2 + b2 = c2 Fo ...
- Python之路【第十八篇】:Web框架们
Python之路[第十八篇]:Web框架们 Python的WEB框架 Bottle Bottle是一个快速.简洁.轻量级的基于WSIG的微型Web框架,此框架只由一个 .py 文件,除了Pytho ...
- cocos2d-js版本A*算法
[转]http://blog.csdn.net/realcrazysun1/article/details/43054229 A*算法的东西网上讲了很多~但还是不可避免的要去研究一下,cocos官网上 ...
- {Reship}Precision, Accuracy & Recall
============================================================== This aritcle came from here ========= ...
- linux C学习笔记03--单链表
单链表一直是程序员的基础,我也来复习下,下面是link.c中的代码,供main.c 调用,代码很简单,单链表的插入,删除,查找和遍历输出, #include <stdio.h> #incl ...