【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 ...
随机推荐
- 大组合数Lucas
https://blog.csdn.net/sr_19930829/article/details/39058487 LL Lucas(LL n, LL m, int p){ ; } Saving B ...
- 实现在vue中element-ui的el-dialog弹框拖拽
参考:实现在vue中element-ui的el-dialog弹框拖拽 1.在 utils 中新建 directives.js 文件 import Vue from 'vue' // v-dialogD ...
- 2000G电脑大型单机游戏合集
激活码 游戏名称(ctrl+F查找) 下载链接005875 艾迪芬奇的记忆 游戏下载链接http://pan.baidu.com/s/1t2PYRAj546_1AcOB-khJZg554158 暗影: ...
- netty(一)---服务端源码阅读
NIO Select 知识 select 示例代码 : //创建 channel 并设置为非阻塞 ServerSocketChannel serverChannel = ServerSocketCha ...
- contextField 键盘只允许输入数字和小数点,并且现在小数点后位数
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementS ...
- Django项目配置数据库时,已安装mysqlclient,却提示 Did you install mysqlclient错误,后右报错ImproperlyConfigured: mysqlclient 1.3.13 or newer is required; you have 0.9.3
错误信息如下: 解决方案是: 找到自己的项目文件夹下的__init__.py 添加如下代码 解决这个问题后,右报错django2.2/mysql ImproperlyConfigured: mysq ...
- Fluent_Python_Part2数据结构,02-array-seq,序列类型
1. 序列数据 例如字符串.列表.字节序列.元组.XML元素.数据库查询结果等,在Python中用统一的风格去处理.例如,迭代.切片.排序.拼接等. 2. 容器序列与扁平序列 容器序列:容器对象包含任 ...
- 通过命令创建Django项目
本人是使用window10操作系统进行讲解Django框架,Linux系统和windows版本几乎一致,可以自行学习就可以解决. 首先在系统上创建了虚拟环境,如果不会创建,可以根据这篇文章学习:htt ...
- ThinkPHP3.2.2的函数扩展
ThinkPHP的函数扩展:为了更好的在前台模板中显示变量,例如,商品分类中,分类名称之间的缩进.此时,在APP/Common/Common文件夹下(APP为新建的应用目录),新建一个php文件,如: ...
- ZOJ4114 Flipping Game(2019山东省赛)
有n个开关,有起始状态和终状态,问如果每次必须选m个开关进行改变状态,一共进行k次,那么有多少种方式可以从起始状态到终状态~ #include<bits/stdc++.h> using n ...