题意:

输入一个正整数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. 解决MinGW运行时提示丢失libgmp-10.dll

    如何解决刚安装的MinGW提示"丢失xxx.dll" 解决方案: 1.配置环境变量,出现这种问题的主要原因是因为没配置环境变量,网上的大多数解决方案也是基于这个的. 2.安装包损坏 ...

  2. LR编写webservice协议接口

    转自:http://lovesoo.org/use-loadrunner-call-webservice-interface-testing-optimization-summary.html 本文主 ...

  3. java篇 之 数组

    数组:本身也是对象元素数据类型必须一致,初始值为各种零(跟类型一致),数组中存放 的是对象的引用(地址),对象在其它空间,一旦创建长度不可变,length可以直 接访问 (new的时候才分配空间,创建 ...

  4. 获取浏览器url参数

    //获取浏览器url参数 var methods ={ getQueryString: function (name) { var reg = new RegExp('(^|&)' + nam ...

  5. C# 酒店管理系统知识点

    identity (m,n)自增 m开始n每次增加的值  默认(1,1) 列名  数据类型  约束  identity(m,n) 重新设置identity的值 1.语法 dbcc checkident ...

  6. 使用pycharm创建Django项目,'django-admin' 不是内部或外部命令

    报错信息如下: (笔者的电脑为win10,python3.7,django 2.2.6 ) 第一种情况的解决方案:没有配置环境变量,Django安装之后,需要配置环境变量,命令django-admin ...

  7. Java7任务并行执行神器:Fork&Join框架

    原 Java7任务并行执行神器:Fork&Join框架 2018年01月12日 17:25:03 Java技术栈 阅读数:426 标签: JAVAFORKJOIN 更多 个人分类: Java ...

  8. Webflux是什么东东

    转自:百家号-薇薇心语 各位Javaer们,大家都在用SpringMVC吧?当我们不亦乐乎的用着SpringMVC框架的时候,Spring5.x又悄(da)无(zhang)声(qi)息(gu)的推出了 ...

  9. jdk基础提升

    1. treeMap,treesSet 作用:1具有对应普通的Map,Set的功能,2.能排序Map和Set  (依赖树的结构进行排序---中序循环) TreeSet<String> tr ...

  10. java获取当前机器的公网ip

    package com.Interface.util; import javax.servlet.http.HttpServletRequest; /** * 测试类 * * @author 华文 * ...