当前位置:网站首页>山寨版归并【上】
山寨版归并【上】
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
边栏推荐
- What are the mobile app software testing tools? Sharing of third-party software evaluation
- 考试考试自用
- Krpano panorama vtour folder and tour
- Mysql database explanation (VII)
- Application of skiplist in leveldb
- X509 certificate cer format to PEM format
- Hj31 word inversion
- 自主作业智慧农场创新论坛
- Knn,Kmeans和GMM
- [backtrader source code analysis 18] Yahoo Py code comments and analysis (boring, interested in the code, you can refer to)
猜你喜欢
Basic operation of circular queue (Experiment)
How to use OCR in 5 minutes
MySQL InnoDB transaction
Reptile exercises (1)
T2 iCloud日历无法同步
How to design a good API interface?
What exactly does the distributed core principle analysis that fascinates Alibaba P8? I was surprised after reading it
Sword finger offer (1) -- for Huawei
Cookie&Session
Analysis of common storage types and FTP active and passive modes
随机推荐
Hj31 word inversion
考试考试自用
Five data types of redis
Adobe Illustrator menu in Chinese and English
Code live collection ▏ software test report template Fan Wen is here
Wechat applet customer service access to send and receive messages
Krpano panorama vtour folder and tour
Async void caused the program to crash
机器学习——逻辑回归
Common types of automated testing framework ▏ automated testing is handed over to software evaluation institutions
我的树莓派 Raspberry Pi Zero 2W 折腾笔记,记录一些遇到的问题和解决办法
C语言超全学习路线(收藏让你少走弯路)
码住收藏▏软件测试报告模板范文来了
移动金融(自用)
2022年中国数字科技专题分析
MySQL InnoDB transaction
Have you learned the basic operation of circular queue?
Detailed explanation of C language knowledge points - data types and variables [2] - integer variables and constants [1]
C语言超全学习路线(收藏让你少走弯路)
Deep learning - Super parameter setting