题意:

输入一个正整数N(<=2e5),接着输入N个非递减序的长整数。

输入一个正整数N(<=2e5),接着输入N个非递减序的长整数。(重复一次)

输出两组数合并后的中位数。(200ms,合并后排序会超时,利用两组数是有序的进行模拟)

AAAAAccepted code:

 #define HAVE_STRUCT_TIMESPEC
#include<bits/stdc++.h>
using namespace std;
long a[];
int main(){
int n;
cin>>n;
for(int i=;i<=n;++i)
cin>>a[i];
int m;
cin>>m;
long x;
int l=,r=n+m;
int mid=(l+r-)/+;
int cnt=;
++l;
for(int i=;i<=m;++i){
cin>>x;
while(l<=n&&a[l]<x){
++cnt;
if(cnt==mid)
cout<<a[l];
++l;
}
++cnt;
if(cnt==mid)
cout<<x;
}
while(l<=n){
++cnt;
if(cnt==mid)
cout<<a[l];
++l;
}
return ;
}

【PAT甲级】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 分)

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

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

  4. PAT 甲级 1078 Hashing (25 分)(简单,平方二次探测)

    1078 Hashing (25 分)   The task of this problem is simple: insert a sequence of distinct positive int ...

  5. PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)

    1070 Mooncake (25 分)   Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...

  6. PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)

    1032 Sharing (25 分)   To store English words, one method is to use linked lists and store a word let ...

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

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

  8. 【PAT】1029. Median (25)

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

  9. PAT 甲级 1029 Median

    https://pintia.cn/problem-sets/994805342720868352/problems/994805466364755968 Given an increasing se ...

随机推荐

  1. Aggregate 聚合用法

    var listb= ListA.Where(x => x.Id.Equals(obj.Id)).Select(x => x.SubData).Aggregate((x, y) => ...

  2. iso15693芯片读写工具套件 icode-slix2读写 nfc type 5 tag读写

    iso15693芯片读写工具套件 icode-slix2读写 nfc type 5 tag读写校验套件 iso15693工具套件支持icode-slix,icode-slix2芯片的读写,支持iso1 ...

  3. Re(正则表达式)库入门

    一.正则表达式的概念 正则表达式 "一行胜千言" regular expression regex RE 是用来简洁表达一组字符串的表达式. 'PN' 'PYN' 'PYTN' & ...

  4. SoapUI学习(1)- WebService基础

    转载:http://luyongxin88.blog.163.com/blog/static/92558072011320101454287/ WebService 它是一种构建应用程序的普遍模型,可 ...

  5. [C++_QT] 同步方式提交GET和POST请求

    #开始 最近在做一个需要用到提交HTTP请求的工具 但是遇到一个问题 如下 在Qt中提交一个get请求之后(或者post) 在收到回复之后会调用之前连接好的槽函数 但是问题就是在主调函数中不知道什么时 ...

  6. VMware安装ACS5.8

    1.所需组件: VMware ACS5.8 iso 2.安装要求: 2 Core Processor 4 GB RAM 60 GB Hard drive 这些要求算是比较低的要求,不能比这个更low了 ...

  7. 【MySQL】存储引擎

    " 目录 #. MySQL支持的存储引擎 1. InnoDB 2. MyISAM 3. NDB 4. Memory 5. Infobright 6. NTSE 7. BLACKHOLE My ...

  8. 纯CSS实现吸顶效果

    position的属性有哪些? {  position: static;  position: relative;  position: absolute;  position: fixed; pos ...

  9. Operating systems Chapter 4

    There are two processes to switch, when one run:io instruction, switch on other process. After ios, ...

  10. 【笔记5-购物车及地址模块】从0开始 独立完成企业级Java电商网站开发(服务端)

    购物车模块 数据库表设计 购物车表 CREATE TABLE mmall_ cart ( 'id' int(11) NOT NULL AUTO_ INCREMENT, 'user_ id' int(1 ...