九度oj 1004 Median 2011年浙江大学计算机及软件工程研究生机试真题
题目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
分析:
模拟归并:
#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年浙江大学计算机及软件工程研究生机试真题的更多相关文章
- 九度oj 1002 Grading 2011年浙江大学计算机及软件工程研究生机试真题
#include<iostream> #include<queue> #include<cstdio> #include<cstring> #inclu ...
- 九度oj 1032 ZOJ 2009年浙江大学计算机及软件工程研究生机试真题
题目1032:ZOJ 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:4102 解决:2277 题目描述: 读入一个字符串,字符串中包含ZOJ三个字符,个数不一定相等,按ZOJ的顺序输出,当 ...
- 九度oj 1468 Sharing 2012年浙江大学计算机及软件工程研究生机试真题
题目1468:Sharing 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:2687 解决:550 题目描述: To store English words, one method is ...
- 九度oj 1001 A+B for Matrices 2011年浙江大学计算机及软件工程研究生机试真题
题目1001:A+B for Matrices 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:15235 解决:6172 题目描述: This time, you are supposed ...
- 九度oj 1034 寻找大富翁 2009年浙江大学计算机及软件工程研究生机试真题
题目1034:寻找大富翁 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5323 解决:2123 题目描述: 浙江桐乡乌镇共有n个人,请找出该镇上的前m个大富翁. 输入: ...
- 九度oj 1031 xxx定律 2009年浙江大学计算机及软件工程研究生机试真题
题目1031:xxx定律 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:5153 解决:3298 题目描述: 对于一个数n,如果是偶数,就把n砍掉一半:如果是奇数,把n变成 3*n ...
- 九度oj 1006 ZOJ问题 2010年浙江大学计算机及软件工程研究生机试真题
题目1006:ZOJ问题 时间限制:1 秒 内存限制:32 兆 特殊判题:否 提交:16244 解决:2742 题目描述: 对给定的字符串(只包含'z','o','j'三种字符),判断他是否能AC.是 ...
- 九度oj 1437 To Fill or Not to Fill 2012年浙江大学计算机及软件工程研究生机试真题
题目1437:To Fill or Not to Fill 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:1488 解决:345 题目描述: With highways availabl ...
- 九度oj 1464 Hello World for U 2012年浙江大学计算机及软件工程研究生机试真题
题目1464:Hello World for U 时间限制:1 秒 内存限制:128 兆 特殊判题:否 提交:3872 解决:1082 题目描述: Given any string of N (> ...
随机推荐
- Spreadsheet 常用属性
标题栏是否可见 Spreadsheet1.TitleBar.Visible=true 标题栏背景颜色 Spreadsheet1.TitleBar.Interior.Color="Green& ...
- 比特币解锁脚本中的ScriptSignature都包含了什么东西
比特币 解锁脚本signature script 包含了那些东西? 使用 UTXO 需要私钥签名,私钥到底都签了什么东西呢?一直比较好奇. 比特币的私钥签名总共有五中类型,具体见 btcd 代码,如下 ...
- CookieJar和HTTPCookieProcessor
CookieJar和HTTPCookieProcessor 我们在使用爬虫的时候,经常会用到cookie进行模拟登陆和访问.在使用urllib库做爬虫,我们需要借助http.cookiejar库中的C ...
- “全栈2019”Java第十九章:关系运算符、条件运算符和三元运算符
难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...
- CodeChefSeries Sum (伯努利数+生成函数+FFT)
题面 传送门 给定\(a_1,..,a_n\),定义\(f(x,k)=\sum_{i=1}^n(x+a_i)^k,g(t,k)=\sum_{x=0}^tf(x,k)\),给定\(T,K\),请你对\( ...
- [ActionSprit 3.0] FMS客户端调用服务器端命令或方法
有时候客户端需要和服务器端进行通信,服务器端会有个main.asc文件(当然,文件名可以自己定义),这个就是服务器端程序,是在服务器上执行的,你可以用trace调试,trace的内容会在管理服务器的页 ...
- 如何在Linux下禁用IPv6
如何在Linux下禁用IPv6 echo 1 > /proc/sys/net/ipv6/conf/all/disable_ipv6 禁用IP ...
- 使用 final 关键字修饰一个变量时,是引用不能变,还是引用的对象不能变?
使用 final 关键字修饰一个变量时,是指引用变量不能变,引用变量所指向的对象中的内容还是可以改变的.例如,对于如下语句:final StringBuffer a=new StringBuffer( ...
- javascript 判断对象的内置类型
判断某个对象值属于哪种内置类型,最靠谱的做法就是通过Object.prototype.toString方法.在toString方法被调用时,会执行下面的操作步骤:1. 获取this对象的[[Class ...
- 04. prosition 的值都有哪些,其最本质的区别在哪里?
4.prosition 的值都有哪些,其最本质的区别在哪里? position:relative 相对定位 position:fixed 相对浏览器定位 position:absolute 绝对定位 ...