PAT甲 1029. Median (25) 2016-09-09 23:11 27人阅读 评论(0) 收藏
1029. Median (25)
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
整体排序即可
#include<stdio.h>
#include<iostream>
#include<algorithm>
using namespace std;
long int a[2000005]; int main()
{
long int k1, k2, i, j;
while (~scanf("%ld",&k1))
{
for (i = 0; i < k1; i++)
scanf("%ld",&a[i]);
scanf("%ld", &k2);
for (i = k1; i < k1 + k2; i++)
scanf("%ld", &a[i]);
sort(a, a + k1 + k2);
j = (k1 + k2 -1) / 2;
printf("%ld\n", a[j]);
}
return 0;
}
PAT甲 1029. Median (25) 2016-09-09 23:11 27人阅读 评论(0) 收藏的更多相关文章
- PAT甲 1011. World Cup Betting (20) 2016-09-09 23:06 18人阅读 评论(0) 收藏
1011. World Cup Betting (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Wit ...
- PAT甲 1032. Sharing (25) 2016-09-09 23:13 27人阅读 评论(0) 收藏
1032. Sharing (25) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue To store Engl ...
- PAT 甲 1005. Spell It Right (20) 2016-09-09 22:53 42人阅读 评论(0) 收藏
1005. Spell It Right (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Given ...
- PAT甲 1048. Find Coins (25) 2016-09-09 23:15 29人阅读 评论(0) 收藏
1048. Find Coins (25) 时间限制 50 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Eva loves t ...
- PAT甲 1009. Product of Polynomials (25) 2016-09-09 23:02 96人阅读 评论(0) 收藏
1009. Product of Polynomials (25) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yu ...
- PAT甲 1046. Shortest Distance (20) 2016-09-09 23:17 22人阅读 评论(0) 收藏
1046. Shortest Distance (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The ...
- PAT甲 1041. Be Unique (20) 2016-09-09 23:14 33人阅读 评论(0) 收藏
1041. Be Unique (20) 时间限制 100 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue Being uniqu ...
- PAT甲 1008. Elevator (20) 2016-09-09 23:00 22人阅读 评论(0) 收藏
1008. Elevator (20) 时间限制 400 ms 内存限制 65536 kB 代码长度限制 16000 B 判题程序 Standard 作者 CHEN, Yue The highest ...
- Poj 1029 分类: Translation Mode 2014-04-04 10:18 112人阅读 评论(0) 收藏
False coin Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 16418 Accepted: 4583 Descr ...
随机推荐
- js中函数传参的情况
<!DOCTYPE html><html lang="en"><head> <meta charset="UTF-8" ...
- destoon 分页
php: global $pagesize,$page; $pagesize = 10;//分页改为10条一页 $offset or $offset = ($page-1)*$pagesize; $t ...
- 基于JS的文本验证
1,不能为空 <input type="text" onblur="if(this.value.replace(/^ +| +$/g,'')=='')alert(' ...
- kegg富集分析之:KEGGREST包(9大功能)
这个包依赖极有可能是这个:https://www.kegg.jp/kegg/docs/keggapi.html ,如果可以看懂会很好理解 由于KEGG数据库分享数据的策略改变,因此KEGG.db包不在 ...
- ccf认证模拟题之三---最大的矩形
问题描述 在横轴上放了n个相邻的矩形,每个矩形的宽度是1,而第i(1 ≤ i ≤ n)个矩形的高度是hi.这n个矩形构成了一个直方图.例如,下图中六个矩形的高度就分别是3, 1, 6, 5, 2, 3 ...
- 38. Count and Say (String; DP)
The count-and-say sequence is the sequence of integers beginning as follows:1, 11, 21, 1211, 111221, ...
- 使用UltraISO制作光盘镜像
为什么使用光盘镜像文件: 1. 有些光盘中的内容必须在光盘运行环境中运行: 有些光盘的内容要在光盘运行的时候才能运行,即使你安装到电脑上都不行!例如某些游戏光盘等,这样就得每次使用时都要用光盘,对光驱 ...
- sign和token设计
签名设计 对于敏感的api接口,需使用https协议 https是在http超文本传输协议加入SSL层,它在网络间通信是加密的,所以需要加密证书. https协议需要ca证书,一般需要交费. 签名的设 ...
- Navicat Premium11连接Oracle出现ORA-28547:connection to server failed
环境描述:本地Oracle正常安装,中途没有出现任何异常.确保Oracle的主要服务都启动了.1.OracleServiceORCL2.OracleOraDb11g_home1TNSListener ...
- linux文件管理2
1.显示文件内容 cat : 显示文件内容 tac : 倒序显示内容 2.更改文件权限 chmod :更改文件权限 -R 递归改变 chown :更改文件拥有者 -R 递归改变 chgrp :更改文件 ...