【PAT甲级】1029 Median (25 分)
题意:
输入一个正整数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 分)的更多相关文章
- PAT 甲级 1029 Median (25 分)(思维题,找两个队列的中位数,没想到)*
1029 Median (25 分) Given an increasing sequence S of N integers, the median is the number at the m ...
- 1029 Median (25 分)
1029 Median (25 分) Given an increasing sequence S of N integers, the median is the number at the m ...
- 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 ...
- PAT 甲级 1078 Hashing (25 分)(简单,平方二次探测)
1078 Hashing (25 分) The task of this problem is simple: insert a sequence of distinct positive int ...
- PAT 甲级 1070 Mooncake (25 分)(结构体排序,贪心,简单)
1070 Mooncake (25 分) Mooncake is a Chinese bakery product traditionally eaten during the Mid-Autum ...
- PAT 甲级 1032 Sharing (25 分)(结构体模拟链表,结构体的赋值是深拷贝)
1032 Sharing (25 分) To store English words, one method is to use linked lists and store a word let ...
- PAT 1029 Median (25分) 有序数组合并与防坑指南
题目 Given an increasing sequence S of N integers, the median is the number at the middle position. Fo ...
- 【PAT】1029. Median (25)
Given an increasing sequence S of N integers, the median is the number at the middle position. For e ...
- PAT 甲级 1029 Median
https://pintia.cn/problem-sets/994805342720868352/problems/994805466364755968 Given an increasing se ...
随机推荐
- Python 语法特点:注释/编写规则/命名规范
1.注释 1)单行注释 # 2) 多行注释 前后三个单引号或双引号 ‘’‘ ... ''' """ ...""" ...
- Python隐藏特性:字符串驻留、常量折叠
下面是Python字符串的一些微妙的特性,绝对会让你大吃一惊. 案例一: >>> a = "some_string" >>> id(a) 140 ...
- Zabbix监控工具介绍及软件监控、硬件监控及报警练习
zabbix介绍 zabbix([`zæbiks])是一个基于WEB界面的提供分布式系统监视以及网络监视功能的企业级的开源解决方案. zabbix能监视各种网络参数,保证服务器系统的安全运营:并提供 ...
- SpringCloud全家桶学习之概览(一)
一.概览 根据百度百科的描述,微服务架构是一项在云中部署应用和服务的新技术.而SpringCloud是微服务架构思想的一个具体实现,它为开发人员提供了构建分布式系统中一些常见模式的工具(服务注册与发现 ...
- jmeter csv 插件讲解
1.变量名称 name,pwd 格式表示因为文本中分割默认是逗号所以变量设置也是按此格式如果想按其他格式可以在分隔符栏自定义 2.忽略首行: 有的csv读取你希望读取的数据有header如: user ...
- Vue-全局变量和方法
一.单文件引入 1.创建存放全局变量和方法的vue文件 Common.uve <script> const userName = 'yangjing'; function add(a,b) ...
- ASP.NET Core搭建多层网站架构【6-注册跨域、网站核心配置】
2020/01/29, ASP.NET Core 3.1, VS2019, NLog.Web.AspNetCore 4.9.0 摘要:基于ASP.NET Core 3.1 WebApi搭建后端多层网站 ...
- Linux - 常用GUI软件
1. gdebi -- 可以代替Ubuntu software安装软件 2. System monitor -- 监控流量 3. uget -- 下载软件 4. Okular -- pdf reade ...
- 攻防世界 web 进阶区 刷题记录
1.Training-WWW-Robots 题目提示了robots协议,直接访问robots.txt 继续访问fl0g.php 2.baby_web 题目描述:想想初始页面是哪个 百度搜了下,inde ...
- 在xwindows界面中切换KDE与GNOME
在xwindows界面中切换KDE与GNOME 方法1: 在xwindows界面下通过菜单来切换,找到所需的菜单后执行,选择所需的桌面,重新启动xwindows即可. 方法2: 在命令提示符在xwin ...