题目1004:Median

时间限制:1 秒

内存限制:32 兆

特殊判题:

提交:14162

解决:3887

题目描述:

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 non-decreasing 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.

输入:

Each input file may contain more than 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.

输出:

For each test case you should output the median of the two given sequences in a line.

样例输入:
4 11 12 13 14
5 9 10 15 16 17
样例输出:
13
来源:
2011年浙江大学计算机及软件工程研究生机试真题

分析:

模拟归并:

 #include <cstdio>
#include<algorithm>
#include<iostream>
using namespace std;
int a[],b[];
int main()
{
int n,m;
while(cin>>n){
int i;
for(i=;i<n;i++){
scanf("%d",&a[i]);
}
cin>>m;
for(i=;i<m;i++){
scanf("%d",&b[i]);
}
int j=;
i=;
int num=(m+n-)/;
while(i<n&&j<m){
if(a[i]>b[j]){
j++;
num--;
if(num<){
cout<<b[j-]<<endl;
break;
}
}
else{
i++;
num--;
if(num<){
cout<<a[i-]<<endl;
break;
}
}
}
if(num>=){
while(i<n){
num--;
if(num<){
cout<<a[i]<<endl;
break;
}
i++;
}
while(j<m){
num--;
if(num<){
cout<<b[j]<<endl;
break;
}
j++;
}
}
}
return ;
}

九度oj 1004 Median 2011年浙江大学计算机及软件工程研究生机试真题的更多相关文章

  1. 九度oj 1002 Grading 2011年浙江大学计算机及软件工程研究生机试真题

    #include<iostream> #include<queue> #include<cstdio> #include<cstring> #inclu ...

  2. 九度oj 1032 ZOJ 2009年浙江大学计算机及软件工程研究生机试真题

    题目1032:ZOJ 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4102 解决:2277 题目描述: 读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当 ...

  3. 九度oj 1468 Sharing 2012年浙江大学计算机及软件工程研究生机试真题

    题目1468:Sharing 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:2687 解决:550 题目描述: To store English words, one method is ...

  4. 九度oj 1001 A+B for Matrices 2011年浙江大学计算机及软件工程研究生机试真题

    题目1001:A+B for Matrices 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:15235 解决:6172 题目描述: This time, you are supposed ...

  5. 九度oj 1034 寻找大富翁 2009年浙江大学计算机及软件工程研究生机试真题

    题目1034:寻找大富翁 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5323 解决:2123 题目描述:     浙江桐乡乌镇共有n个人,请找出该镇上的前m个大富翁. 输入:     ...

  6. 九度oj 1031 xxx定律 2009年浙江大学计算机及软件工程研究生机试真题

    题目1031:xxx定律 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5153 解决:3298 题目描述:     对于一个数n,如果是偶数,就把n砍掉一半:如果是奇数,把n变成 3*n ...

  7. 九度oj 1006 ZOJ问题 2010年浙江大学计算机及软件工程研究生机试真题

    题目1006:ZOJ问题 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:16244 解决:2742 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC.是 ...

  8. 九度oj 1437 To Fill or Not to Fill 2012年浙江大学计算机及软件工程研究生机试真题

    题目1437:To Fill or Not to Fill 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:1488 解决:345 题目描述: With highways availabl ...

  9. 九度oj 1464 Hello World for U 2012年浙江大学计算机及软件工程研究生机试真题

    题目1464:Hello World for U 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:3872 解决:1082 题目描述: Given any string of N (> ...

随机推荐

  1. Window 服务启动出错 14001

    在安装windows服务时,没有异常情况,但是在启动的过程中出现 14001错误. 错误 14001 应用程序无法启动 因为应用程序的并行配置不正确 有关详细信息 请参阅应用程序事件日志 或使用命令行 ...

  2. 学习做爬虫-vs2017

    最近新装了vs2017,安装过程发生了很大的变化,操作变的更加容易了. 下载vs安装程序进行安装.更新界面如图所示,我选择了安装免费个人版(这个是已安装的更新界面,和安装界面差不多) 如图所示,这样的 ...

  3. 2、ASP .NETCore 2.0之视图

    一.Razor基础 声明:Razor不是编程语言,是服务器端标记语言.Razor是一种允许开发者在网页中嵌入服务器端代码的标记语法(主要是针对VB和C#). 1.C#中Razor基本语法 (1).Ra ...

  4. LA 3401

    彩色立方体. [分析] 弄清楚24种状态,可以由标准姿态旋转而来. 计算24种状态: #include <iostream> #include <string> ,,,,, } ...

  5. Win7系统下搭建FTP

    一.创建FTP站点  1.打开:控制面板---系统和安全---管理工具---Internet 信息服务 2. 建站:右键点击网站---添加FTP站点 3. 输入FTP 站点名称---选择你的 FTP ...

  6. Mysql表操作《一》表的增删改查

    一.表介绍 表相当于文件,表中的一条记录就相当于文件的一行内容,不同的是,表中的一条记录有对应的标题,称为表的字段 id,name,qq,age称为字段,其余的,一行内容称为一条记录 二.创建表 语法 ...

  7. “全栈2019”Java第三十六章:类

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  8. composer手动安装到windows

    1.配置系统变量 Path 计算机->高级系统设置->环境变量->找到系统变量Path  双击 加入  ;php根目录地址:php中ext地址    如 :“;D:\phpStudy ...

  9. [ActionScript 3.0] 自制简单拾色器

    colorBoard为库中绑定的影片剪辑,colorBoard中包含影片剪辑currColor,文本colorText,影片剪辑close: colorDot为库中绑定的影片剪辑,colorDot中包 ...

  10. css中设置background属性

    属性解释 background属性是css中应用比较多,且比较重要的一个属性,它是负责给盒子设置背景图片和背景颜色的,background是一个复合属性,它可以分解成如下几个设置项: backgrou ...