当前位置:网站首页>山寨版归并【上】
山寨版归并【上】
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
边栏推荐
- cadence SPB17.4 - Active Class and Subclass
- Openstack theoretical knowledge
- Explanation of redis database (I)
- Functions (Part I)
- What are the mobile app software testing tools? Sharing of third-party software evaluation
- MySQL InnoDB transaction
- Connect PHP to MySQL via PDO ODBC
- Tun equipment principle
- Rsync + inotify remote synchronization
- 函数(第一部分)
猜你喜欢
T2 icloud calendar cannot be synchronized
Machine learning - logistic regression
Sorting and replying to questions related to transformer
Tun model of flannel principle
Basic operation of sequential stack
Sword finger offer (1) -- for Huawei
Today's sleep quality record 76 points
Detailed explanation of C language knowledge points -- first understanding of C language [1] - vs2022 debugging skills and code practice [1]
API gateway / API gateway (II) - use of Kong - load balancing
Analysis of common storage types and FTP active and passive modes
随机推荐
【backtrader源码解析18】yahoo.py 代码注释及解析(枯燥,对代码感兴趣,可以参考)
setcontext getcontext makecontext swapcontext
字节面试 transformer相关问题 整理复盘
【Leetcode-每日一题】安装栅栏
Tun model of flannel principle
On the day of entry, I cried (mushroom street was laid off and fought for seven months to win the offer)
My raspberry PI zero 2W toss notes to record some problems and solutions
推荐搜索 常用评价指标
Basic operation of circular queue (Experiment)
Connect PHP to MySQL via PDO ODBC
adobe illustrator 菜单中英文对照
PSYNC synchronization of redis source code analysis
移动金融(自用)
Common types of automated testing framework ▏ automated testing is handed over to software evaluation institutions
T2 icloud calendar cannot be synchronized
Compiling OpenSSL
Educational Codeforces Round 127 A-E题解
MySQL sync could not find first log file name in binary log index file error
[backtrader source code analysis 18] Yahoo Py code comments and analysis (boring, interested in the code, you can refer to)
Basic operation of sequential stack