当前位置:网站首页>山寨版归并【上】
山寨版归并【上】
2022-04-23 15:32:00 【MC快乐的苦小怕】
题目:
题目描述
问题描述
可可和乐乐手头有很多游戏卡片,卡片上都有数字编号,他们各自将他们的卡片按照由小到大顺序排序,现在他们想将他们的卡片放到一起,并且还要保证是由小到大排序。由于卡片数目可能达到数百万张,而且要在一秒钟时间完成卡片的合并,现在请你帮忙!
输入格式
共三行。
第一行:空格分隔的两个整数n和m,分别表示可可和乐乐的卡片数;
第二行:n个用空格分隔的整数,表示可可卡片从小到大的编号;
第三行:m个用空格分隔的整数,表示乐乐卡片从小到大的编号;
输出格式
仅一行:n+m个整数,以空格分隔,表示合并后的卡片由小到大的编号。
输入样例
3 4
3 5 7
1 3 4 6
输出样例
1 3 3 4 5 6 7
数据范围
n<=1000000,m<=1000000
这道题开始老师设定的时间是2 Sec,哈哈哈,暴力直接100到手:
定义a[2000010]
接着直接来各个 sort暴力完美。

可是老师见我们操作这么N,就把时间改成了1 Sec。
wawawaw,顿时泪如雨下.
…
shua代码开始
弄了两个“指针”(这里不是*x的那个指针)。
i,j;
话不多说,上代码:
#include <bits/stdc++.h>
using namespace std;
int a[1000010],b[1000010];
int main(){
int n,m;
cin>>n>>m;
for(int i=1;i<=n;i++)scanf("%d",&a[i]);
for(int j=1;j<=m;j++)scanf("%d",&b[j]);
int i=1,j=1;
for(int x=1;x<=n+m;x++){
if(a[i]>b[j])printf("%d ",a[i]),i++;
else printf("%d ",b[j]),j++;
}
return 0;
}
goodbye!!!
山寨版归并【下】传送门
版权声明
本文为[MC快乐的苦小怕]所创,转载请带上原文链接,感谢
https://xiaoguogsc.blog.csdn.net/article/details/122589048
边栏推荐
- 木木一路走好呀
- Llvm - generate addition
- Deeply learn the skills of parameter adjustment
- What exactly does the distributed core principle analysis that fascinates Alibaba P8? I was surprised after reading it
- Detailed explanation of redirection and request forwarding
- Basic operation of sequential stack
- 机器学习——逻辑回归
- Deep learning - Super parameter setting
- G007-hwy-cc-estor-03 Huawei Dorado V6 storage simulator construction
- Three uses of kprobe
猜你喜欢

移动金融(自用)

Five data types of redis

G007-hwy-cc-estor-03 Huawei Dorado V6 storage simulator construction

On the day of entry, I cried (mushroom street was laid off and fought for seven months to win the offer)

regular expression

API gateway / API gateway (II) - use of Kong - load balancing

Explanation 2 of redis database (redis high availability, persistence and performance management)

Cookie&Session

Mumu, go all the way

Detailed explanation of kubernetes (IX) -- actual combat of creating pod with resource allocation list
随机推荐
Sorting and replying to questions related to transformer
Wechat applet customer service access to send and receive messages
如果conda找不到想要安装的库怎么办PackagesNotFoundError: The following packages are not available from current
How to use OCR in 5 minutes
Llvm - generate addition
Tun equipment principle
MySQL Basics
Have you learned the basic operation of circular queue?
通过 PDO ODBC 将 PHP 连接到 MSSQL
Recommended search common evaluation indicators
Design of digital temperature monitoring and alarm system based on DS18B20 single chip microcomputer [LCD1602 display + Proteus simulation + C program + paper + key setting, etc.]
考试考试自用
Grep was unable to redirect to the file
Common types of automated testing framework ▏ automated testing is handed over to software evaluation institutions
The El tree implementation only displays a certain level of check boxes and selects radio
What are the mobile app software testing tools? Sharing of third-party software evaluation
What exactly does the distributed core principle analysis that fascinates Alibaba P8? I was surprised after reading it
Explanation of redis database (III) redis data type
How to design a good API interface?
Tun model of flannel principle