1029 Median (25分)(一个字短!)

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 }... 阅读详情

1029 Median (25分)

分析

为了节省时间,先将第一个数组全部输入,而第二个数组一边输入一边找中位数,cnt记录在中位数之前一共有多少个数字,cnt_i用于计数在中位数之前,有多少个数字是属于第一个数组的,cnt_j用于计数在中位数之前有多少个数字是属于第二个数组的,当cnt_i+cnt_j=cnt时,表明中位数已经找到。
当cnt_i为n或者cnt_j为m,则表示第一个数组或者第二个数组中的元素全部位于中位数之前。
当cnt_i+cnt_j=cnt时,若cnt_i为n,则中位数为b,若cnt_j为m,则中位数为a[cnt_i],若cnt_i<n且cnt_j<m,则中位数为b和a[cnt_i]中较小的那一个。

代码

#include<iostream>
using namespace std;
int n, m, cnt, cnt_i = 0, cnt_j = 0;
long int a[200010], b;
int main() {
 scanf("%d", &n);
 for (int i = 0; i < n; ++i)scanf("%ld", &a[i]);
 scanf("%d", &m);
 if (m)scanf("%ld", &b);
 cnt = (m + n) / 2 + (m + n) % 2 - 1;
 while (cnt_i + cnt_j < cnt) {
  if (cnt_i < n && cnt_j < m) {
   if (b >= a[cnt_i])++cnt_i;
   else {
    scanf("%ld", &b);
    ++cnt_j;
   }
  }
  if (cnt_i == n)++cnt_j;
  if (cnt_j == m)++cnt_i;
 }
 if (cnt_i < n && cnt_j < m)printf("%ld", a[cnt_i] < b ? a[cnt_i] : b);
 else if (cnt_i == n)printf("%ld", b);
 else printf("%ld", a[cnt_i]);
 return 0;
}
ObjectMapper解析JSON数据 的时候捕获的数据,往往需要结合文档所定义的类进行转换,也就是。库中的一个关键类,它的作用是将。对象之间进行相互转换。 阅读详情

相关推荐

麒麟和UOS系统编写桌面点击可执行文件

在桌面上创建一个快捷方式(.desktop 文件)来运行脚本。打开文本编辑器,创建一个新文件,如。这可以通过文本编辑器来完成。首先,确保您的脚本具有执行权限。现在,您应该可以双击桌面上的。保存此文件到桌面目录,例如,在桌面上创建一个快捷方式(文件来运行您的脚本了。使用图形界面或命令行给。现在您可以双击桌面上的。为您脚本的实际路径。是您脚本的实际路径。文件来运行您的脚本了。

u013934107的博客 7253

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

永无止境 307

Jaspersoft Studio 6.20.0 免注册安装指南(附下载链接)

本文提供了Jaspersoft Studio 6.20.0社区版的免注册安装详细指南。文章介绍了绕过官网注册获取安装包的多种可靠途径,并逐步详解了从启动安装器到首次运行的全过程,帮助用户快速完成安装与基础配置,高效开启报表设计工作。

mars5的博客 1697

【PAT甲级】1029 Median (25分)

解题过程的小记录,如有错误欢迎指出。 难度:二星(用two pointers的合并算法并不难,merge的模板要背一下,不懂通过率为何这么低) 小导航~题目分析注意点我的解题过程思路bug代码dalao的代码借鉴点 题目分析 给出两个递增序列,求合并后(依旧要求递增)的中位数 注意点 题目涉及的数据量大,改用scanf进行输入 我的解题过程 思路 找出中位数所在的位置(因为合并后是递增数列,中位数所在的位置和两个数串长度的和是否奇数有关) 利用two pointers指向两个数列的开始,取小的排入合并

SpicyChicken的自我修养 319

树莓派4B串口舵机控制全攻略:从pigpio库安装到Python脚本调试

本文详细介绍了如何在树莓派4B上通过pigpio库和Python脚本实现串口舵机的精确控制。从硬件串口配置、pigpio库安装到舵机通信协议解析和Python脚本开发,提供了完整的解决方案和调试技巧,适用于机械臂控制等实际项目应用。

k8s6orchestrator的博客 431

NotebookLM平替实测:用Open Notebook+Ollama零成本搭建私有AI知识库

本文提供了一份详细的实战指南,教你如何利用Open Notebook与Ollama,在本地零成本搭建一个功能强大且完全私有的AI知识库。通过Docker容器化部署,实现数据绝对安全、模型自由选择与离线运行,是NotebookLM等云端工具的绝佳平替方案,尤其适合注重数据隐私的教育工作者、研究者及小团队。

weixin_29052717的博客 514

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

weixin_43725617的博客 131

接入穿山甲SDK时,Unity打Android包报错日志

SDK工程设置为Enable,项目工程设置为Disable。2、将unitypackage导入包名为:com.DefaultCompany.Myproject的另一个工程,打包报错。3、点击工程默认弹出Enable Android Auto-resolution 设置选项,点击Enable。1、新建一个空工程,设置包名为:com.ceshi.hewen,正常打包无报错,导出unitypackage。2、点击Reset to Defaults 重置参数,再点击ok关闭设置窗口。

不文不武的禾文 3586

1029 Median (25 分)(two pointer)

1029 Median (25 分)(two pointer) 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 ...

virgilshi的博客 402

Java数据可视化实战:基于JFreeChart的数学函数绘图工具开发

JFreeChart是一个开源的Java图表库,适用于Swing和JavaFX应用程序。折线图和面积图柱状图和饼图散点图和气泡图组合图表3D图表等实现自定义数学表达式解析:java复制下载throw new IllegalArgumentException("表达式不能为空");// 验证表达式try {}");throw new IllegalArgumentException("无效的数学表达式: " + e.getMessage());try {

2201_76125393的博客 365

【GEE数据库】WRF常用数据集总结

【GEE数据库】WRF常用数据集总结

WW、forever的博客 638

PTA A1029Median算法笔记的方法过不了最后一个测试点“内存超限”--解决办法

算法笔记解题方法 #include <iostream> using namespace std; #define maxn 1000010 #define INF 0x7fffffff int a[maxn], b[maxn]; int n, m; int main() { //freopen("D:/in.txt", "r", stdin); scanf("%...

Nicole_177的博客 2734

INCA ProF文件解析

本博文从实际应用出发,介绍INCA prof文件的关键信息,通过实例,描述当得到一个刷写需求后,如何在不改变用户之前的使用习惯的前提下,满足原有的INCA刷写应用数据和标定程序的需求。 声明:本文不涉及项目名称,没有商业目的,纯属分享技术,乐享知识。

汽车电子软件领域知识分享 1万+

1029 Median (25 分)

1029 Median (25 分) 题目入口 目录1029 Median (25 分)思想AC代码TLE代码 思想 这题在考归并排序 然鹅STL的sort就完事了 还写了个set应该是超时了 有时间再改set吧 到这里讲解结束 AC代码 #include <iostream> #include <cstdio> #include <algorithm> usi...

恒治学 271

WINCC7.3破解文件

WINCC7.3硬件够破解文件,有需要的下载!WINCC7.3硬件够破解文件,有需要的下载!

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

甲级1029 Median (25分)

甲级1029 Median (25分) 测试点3过不了啊???? 还有一点不明白 为啥要加&? 我用的long long *array,但是我没加&时就是过不了啊啊啊啊啊(;´д`)ゞ 等待大佬解答 题目如下 1029 Median (25分) Given an increasing sequence S of N integers, the median is the number...

qq_46586095的博客 269

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

PAT A 1029 Median (25分)

1029 Median (25分) 吐槽 这题目……嗯。 逼着我不让我用set和priority_queue啊…… 还有就是这题大家交一遍程序的用时都太长啦!要等好久啊!(虽然我也是) 逻辑 用vector存储,然后用sort排序。 不能使用set和priority_queue。反正我一直超时。 原因应该是每次读入进去就做一次排序的开销,对于这个输入时就一半有序的输入来说,远高于最后做一次排序。 ...

虚境的博客 180

efm32 入门.pdf

本PDF共计22页,介绍的是操作驱动API,下载与否自己斟酌。

PAT甲级 1029 Median (25分)

1029 Median (25分) 题目链接:PAT A 1029 题目大意:给出两个升序的序列,要求输出将他们合并后序列的中位数。 思路分析:由于只需要输出合并序列的中位数,所以其实没必要将两个序列合并到一起。可以采用一种算法思想:two pointers。即定义两个变量i和j,分别从两个序列的开始扫描这两个序列,如果a[i]<b[j],就让i自增,否则让j自增,当到达中位数的下标时退出...

weixin_43684054的博客 253

PAT A1029 Median (25分)

PAT甲级:A1029 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 =...

只想用最简短的代码刷题 152

A1029 Median (25分)【C语言】

A1029 Median (25分)【C语言】 原题链接 题目描述: 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 tw

SASAKI_130的博客 295

PAT A1029 Median (25 分)

PAT A1029 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

weixin_48165493的博客 192

PAT Advanced 1029 Median (25 )

PAT Advanced 1029 Median (25 )题目描述Input Specification:Output Specification:Sample Input:Sample Output:解题思路Code 题目描述 Given an increasing sequence S of N integers, the median is the number at the middl...

gq__97的博客 197

PAT 1029 Median(25分)

归并、减治法

cwtnice的博客 242

B1029 Median (two points)

B1029 Median (25分) //该题容易爆内存 2×2×10^5×(int)4/1024=1562.5kb 用两个数组存数据就会爆内存 但是第一次没注意内存的问题用分块法水过去了,也不晓得为啥≧ ﹏ ≦,网上看了别人的解法。 two points 最多占用1152KB #include <iostream> #include <alg...

没有期待的日子反而会顺顺利利 153

Day58: [PAT甲级] 1029 Median (25分)

Day58: [PAT甲级] 1029 Median (25分) 题源: 来自PAT真题库: https://pintia.cn/problem-sets/994805342720868352/problems/994805466364755968 代码: dirty code凑合看吧 #include<iostream> #include<string> #includ...

qq2215459786的博客 212
上一篇: 1028 List Sorting (25分)(一个字短!)
下一篇: 1030 Travel Plan (30分)(一个字短!)
大了七八个
博客等级 码龄8年 2粉丝 30原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值