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 Specification:

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 (≤2×10​5​​) 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 Specification:

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

注意点:1.要考虑到m个数字已经输入完但是k还没到count的情况
    2.必须用cin.tie(0),否则超时。
#include<bits/stdc++.h>
using namespace std; const int maxn = ; int a[maxn]; int n,m; int main(){ ios::sync_with_stdio(false);
cin.tie(); cin>>n; int i,j; for(i=;i<n;i++)
cin>>a[i]; cin>>m; int count=; bool flag=false; count=(m+n+)/; int k=; int b; int ans; i=; for(j=;j<m&&k<count;j++){
cin>>b; if(a[i]<=b){
while(i<n&&a[i]<b){
k++;
if(k==count)
{
ans=a[i];
break;
} i++;
} } k++;
if(k==count)
{
ans=b;
break;
} } while(k<count&&i<n){
ans=a[i];
i++;
k++;
} // cout<<count<<endl;
cout<<ans<<endl; }
 

1029 Median (25 分)的更多相关文章

  1. PAT 甲级 1029 Median (25 分)(思维题,找两个队列的中位数,没想到)*

    1029 Median (25 分)   Given an increasing sequence S of N integers, the median is the number at the m ...

  2. 1029 Median (25分)

    Given an increasing sequence S of N integers, the median is the number at the middle position. For e ...

  3. PAT 1029 Median (25分) 有序数组合并与防坑指南

    题目 Given an increasing sequence S of N integers, the median is the number at the middle position. Fo ...

  4. 【PAT甲级】1029 Median (25 分)

    题意: 输入一个正整数N(<=2e5),接着输入N个非递减序的长整数. 输入一个正整数N(<=2e5),接着输入N个非递减序的长整数.(重复一次) 输出两组数合并后的中位数.(200ms, ...

  5. 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 ...

  6. 【PAT】1029. Median (25)

    Given an increasing sequence S of N integers, the median is the number at the middle position. For e ...

  7. A1029 Median (25 分)

    一.技术总结 最开始的想法是直接用一个vector容器,装下所有的元素,然后再使用sort()函数排序一下,再取出中值,岂不完美可是失败了,不知道是容器问题还是什么问题,就是编译没有报错,最后总是感觉 ...

  8. 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 ...

  9. 1029. Median (25)

    分析: 考察归并排序,用简单的快排会超时. #include <iostream> #include <stdio.h> #include <algorithm> ...

随机推荐

  1. CenterOS 设置静态IP

    本文主要介绍这样再CenterOS 中设定静态IP. 工具 centerOS 6.9 步骤 执行命令:vi /etc/sysconfig/network-scripts/ifcfg-eth0 编辑,填 ...

  2. 01java基础笔记

    计算机组成:运算器,控制器,存储器,输入输出设备(外部设备I/O设备) 机器语言:机器语言,汇编语言,高级语言 人机交互:命令行方式,图形化界面交互方式 JAVA语言平台分为:J2SE,J2ME,J2 ...

  3. 泛微oa系统com.eweaver.base.DataAction文件sql参数sql注入

    URL/ServiceAction/com.eweaver.base.DataAction?sql=select%201,2,3,4,5,6,7,8,9,233%20from%20DUAL%20

  4. NMS python实现

    import numpy as np ''' 目标检测中常用到NMS,在faster R-CNN中,每一个bounding box都有一个打分,NMS实现逻辑是: 1,按打分最高到最低将BBox排序 ...

  5. editplus 正则表达式 分组替换

    editplus :zz正则表达式替换 /开头的api+换行符 替换为   /开头的api+空格 \1后有空格 editplus :zz正则表达式替换 行首两个数字+换行符 替换为  行首两个数字+空 ...

  6. (1.3)学习笔记之mysql体系结构(C/S整体架构、内存结构、物理存储结构、逻辑结构)

    目录 1.学习笔记之mysql体系结构(C/S架构) 2.mysql整体架构 3.存储引擎 4.sql语句处理--SQL层(内存层) 5.服务器内存结构 6.mysql如何使用磁盘空间 7.mysql ...

  7. 为什么javaBean要有get/set方法的设计

    可以应对将来的修改,比如有一个以长度计算的项目开发好了,过段时间客户说这个项目要在美国上市,有了javaBean只要把所有以厘米计算的单位都乘以2.54转化为正确单位交给客户 public class ...

  8. android绑定usb前后摄像头

    在Android的系统会有前置摄像头和后置摄像头的定义,摄像头分为SOC类型的摄像头和USB这一类的摄像头,接下要分析就是USB摄像头这一类 . 一般在android或者linux系统中分析一个模块, ...

  9. makefile自动编译

    1.格式:  目标:依赖 规则    规则前有一个tab键 ,缺少tab键出错,使用空格替代也不可以 (1). 例子: 编写makefile 编译 main.c ,fun.c , fun.h test ...

  10. Git版本控制及gitlab私有仓库

    Git版本控制系统 版本控制系统简介 版本控制系统是一种记录一个或若干个文件内容变化,以便将来查阅特定版本内容情况的系统 记录文件的所有历史变化 随时恢复到任何一个历史状态 多人协作开发 常见版本管理 ...