首页 > 试题广场 >

取中值

[编程题]取中值
  • 热度指数:9965 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 64M,其他语言128M
  • 算法知识视频讲解
     存在两组数组,和4个数字a,b,c,d,要求做如下操作,将第一个数组第a个数到第b个数,第二个数组的第c个数到第d个数放到一个数组中,求出合并后数组的中间值,如果有两个中间值,取下标较小的那个。

输入描述:
    第一行两个整数,表示两个数组的长度,
    接下来两行表示两个数字的值,
    最后一行有四个整数a,b,c,d。
    数组长度不会超过1000000。


输出描述:
    每行一个整数,对应合并数组的下标在中间的那个值。
示例1

输入

5 4
1 2 3 4 5
6 7 8 9
1 2
1 3

输出

6
头像 nzxkc
发表于 2022-02-11 23:37:52
芭比Q了家人们, 一开始看到中位数还以为要用对顶堆或者排序,结果看下这个合并完直接取合并后的中间值就可以了 #include<iostream> #include<cstring> #include<vector> #include<algorit 展开全文
头像 机试秒杀者
发表于 2025-03-17 21:16:56
#include<bits/stdc++.h> using namespace std; int main() { int m,n; while(cin>>m>>n) { int num1[m],num2[n]; 展开全文
头像 csyfZhang
发表于 2020-04-26 12:37:14
看到很多人先把他们依次放入一个数组中,其实复杂度可以进一步降低到,直接通过从两个数组中取出的元素个数进行判断看中值在那个数组里并同时确定他的下标即可。至于为什么下标可以这样表示,画画图就知道了/ int main() { ll n1, n2, a, b, c, d; while (c 展开全文
头像 BrianWu
发表于 2021-07-06 19:13:11
/*描述 存在两组数组,和4个数字a,b,c,d,要求做如下操作,将第一个数组第a个数到第b个数,第二个数组的第c个数到第d个数放到一个数组中,求出合并后数组的中间值,如果有两个中间值,取下标较小的那个。输入描述: 第一行两个整数,表示两个数组的长度, 接下来两行表示两个数字的 展开全文
头像 rainman_
发表于 2023-03-06 22:40:51
#include <iostream> #include <algorithm> using namespace std; int arr1[1000001]; int arr2[1000001]; int newArr[1000001]; int main() { 展开全文
头像 牛客7777779号
发表于 2023-03-20 22:00:45
这题的中位数不需要排序,合并完输出数组的最中间那个数就行。 #include <iostream> using namespace std; #define N 1000000 void input(int a[],int n){ for (int i = 0; i < n; 展开全文
头像 牛客382094256号
发表于 2026-03-18 19:37:06
#include <stdio.h> int main() { int length1,length2; scanf("%d%d",&length1,&length2); int shu1[1000001]; int 展开全文
头像 粉詹眉
发表于 2024-02-29 15:17:14
#include <iostream> using namespace std; const int N=1000010; int x[N],y[N],nums[N]; int main() { int n,m; cin>>n>>m; f 展开全文
头像 粉詹眉
发表于 2024-02-29 15:18:57
#include <iostream> using namespace std; const int N=1000010; int x[N],y[N],nums[N]; int main() { int n,m; cin>>n>>m; f 展开全文
头像 爱吃的懒羊羊离上岸不远了
发表于 2025-03-09 19:56:53
#include <iostream> #include <algorithm> #include <cmath> #define maxn 1000010 using namespace std; int n1[maxn],n2[maxn]; int main 展开全文