Given an increasing sequence S of N integers, the median is the number at the middle position. For example, the median of S1={11, 12, 13, 14} is 12, and the median of S2={9, 10, 15, 16, 17} is 15. The median of two sequences is defined to be the median of the nondecreasing sequence which contains all the elements of both sequences. For example, the median of S1 and S2 is 13.
Given two increasing sequences of integers, you are asked to find their median.
Input
Each input file contains one test case. Each case occupies 2 lines, each gives the information of a sequence. For each sequence, the first positive integer N (<=1000000) is the size of that sequence. Then N integers follow, separated by a space. It is guaranteed that all the integers are in the range of long int.
Output
For each test case you should output the median of the two given sequences in a line.
Sample Input
4 11 12 13 14 5 9 10 15 16 17
Sample Output
13
====================================
这题其实没什么技术含量,因为输入序列都帮你排序好了,时间内存都没啥限制
要注意的一点就是,假定输入序列为A,B,当A或B某个已经被掏空时,需要另外处理,不然就会报段错误什么的…
在优化方面,其实可以先读第一个序列进队列,第二个序列读入时直接处理而不存储,能比原来节省一半空间。
由于题目比较松,没有做这方面处理。
====================================
#include#include using namespace std; int main() { ///////////Init queue q_a ,q_b; long N1, N2; //两个序列的长度 //不存储第二个序列,直接用来比较处理 /////////// //读第一个序列 scanf("%ld", &N1); long temp; for(long i=0; i 另外测试结果比较恐怖,哈哈
测试点 结果 用时(ms) 内存(kB) 得分/满分
0 答案正确 0 660 4/4
1 答案正确 0 790 2/2
10 答案正确 320 17270 3/3
11 答案正确 320 17260 1/1
12 答案正确 320 17260 3/3
13 答案正确 0 740 1/1
2 答案正确 0 740 4/4
3 答案正确 0 750 1/1
4 答案正确 0 790 1/1
5 答案正确 0 750 1/1
6 答案正确 150 9000 1/1
7 答案正确 160 9000 1/1
8 答案正确 160 9010 1/1
9 答案正确 150 8870 1/1