小编GTL*_*GTL的帖子

解决一次查找最大值的算法

问题:我们得到一组2n个整数,其中这个整数数组中的每一对分别代表恐龙的出生年份和死亡年份.我们要考虑的有效年份范围是[-100000到2005].例如,如果输入是:

-80000 -79950 20 70 22 60 58 65 1950 2004
Run Code Online (Sandbox Code Playgroud)

这意味着第一只恐龙的出生年份为-80000,死亡年份为-79950.同样,第二只恐龙的寿命为20至70岁,依此类推.

我们想知道有史以来最多的恐龙活着.在给定上述2n个整数数组的情况下,编写一个计算方法.

谁能建议找出解决方案的方法?

编辑尝试使用this->粗略代码

#include<stdio.h>
#include<stdlib.h>
#include <stddef.h>
static void insertion_sort(int *a, const size_t n) {
    size_t i, j;
    int value;
    for (i = 1; i < n; i++) {
        value = a[i];
        for (j = i; j > 0 && value < a[j - 1]; j--) {
            a[j] = a[j - 1];
        }
        a[j] = value;
    }
}


int  main(){
    int arr[10]={-80000,-79950,20,70,22,60,58,65,1950,2004};
    int strt[5],end[5];
    int bal[5];
     int i,j,k,l,m,length; …
Run Code Online (Sandbox Code Playgroud)

language-agnostic algorithm

4
推荐指数
1
解决办法
1249
查看次数

标签 统计

algorithm ×1

language-agnostic ×1