目录
Time Limit:1s Memory Limit: 256M
I.合并有序数组
Time Limit:1s Memory Limit: 256M
Description:
假设有两个非递增序列 A 与 B ,要求将它们合并为一个非递增序列 C 。
(不可使用任何排序算法完成)
Input:
第一行输入第一个非递增序列,以-1结尾。
第二行输入第二个非递增序列,以-1结尾。
Output:
输出合并后的非递增序列
Sample input:
8 5 4 -1 7 6 3 1 -1
Sample output:
8 7 6 5 4 3 1
约束:
每个序列中元素个数最多不超过100000 ,所有数字都在带符号的 32 位整数范围内(signed 32-bit integers)。
思路+代码:
1.暴力法
我们可以将第二个输入的数组加到第一个输入的数组后面,然后进行从大到小排序,然后遍历输出就可以了,这就是最简单的暴力法!
1.2暴力代码:
#include<bits/stdc++.h>
using namespace std;
int cmp(int a,int b){ //比大小函数
return a>b; //从大到小
}
int main(){
int a[200002]