当前位置:网站首页>山寨版归并【上】
山寨版归并【上】
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
边栏推荐
- 今日睡眠质量记录76分
- Detailed explanation of C language knowledge points -- data types and variables [1] - carry counting system
- Collation of errors encountered in the use of redis shake
- Detailed explanation of redirection and request forwarding
- Lotus DB design and Implementation - 1 Basic Concepts
- Tun model of flannel principle
- [backtrader source code analysis 18] Yahoo Py code comments and analysis (boring, interested in the code, you can refer to)
- Mysql连接查询详解
- PHP PDO ODBC将一个文件夹的文件装载到MySQL数据库BLOB列,并将BLOB列下载到另一个文件夹
- Explanation of redis database (I)
猜你喜欢
Openstack command operation
Tun model of flannel principle
cadence SPB17.4 - Active Class and Subclass
今日睡眠质量记录76分
Basic operation of circular queue (Experiment)
X509 certificate cer format to PEM format
setcontext getcontext makecontext swapcontext
T2 iCloud日历无法同步
Detailed explanation of kubernetes (XI) -- label and label selector
Design of digital temperature monitoring and alarm system based on DS18B20 single chip microcomputer [LCD1602 display + Proteus simulation + C program + paper + key setting, etc.]
随机推荐
Recommended search common evaluation indicators
About UDP receiving ICMP port unreachable
The El tree implementation only displays a certain level of check boxes and selects radio
Special analysis of China's digital technology in 2022
网站建设与管理的基本概念
Precautions for use of dispatching system
今日睡眠质量记录76分
Knn,Kmeans和GMM
el-tree实现只显示某一级复选框且单选
Have you learned the basic operation of circular queue?
GFS distributed file system (Theory)
How did the computer reinstall the system? The display has no signal
php函数
Explanation of redis database (III) redis data type
API gateway / API gateway (III) - use of Kong - current limiting rate limiting (redis)
Sword finger offer (2) -- for Huawei
机器学习——逻辑回归
SSH connects to the remote host through the springboard machine
Application of skiplist in leveldb
Common interview questions of operating system: