sdb


私信TA

用户名:dotcpp0714234

访问量:84

签 名:

等  级
排  名 38984
经  验 346
参赛次数 0
文章发表 8
年  龄 0
在职情况 学生
学  校
专  业

  自我简介:

TA的其他文章

解题思路:

注意事项:

参考代码:


#include<stdio.h>
#include<stdlib.h>

void sortTwoArray(int* pArrayA,int*pArrayB,int total)
{
    int i,j,temp,min;
    for(i = 0; i < total; i++)
    {
        min = i;
         for(j = i; j<total;j++)
         {
            if(*(pArrayA + j) < *(pArrayA + min))
                min = j;
         }
         temp = *(pArrayA + i);
         *(pArrayA + i) = *(pArrayA + min);
         *(pArrayA + min) = temp;
         
         temp = *(pArrayB + i);
         *(pArrayB + i) = *(pArrayB + min);
         *(pArrayB + min) = temp;
    }
}

int countNoRepeat(int *pStart,int *pEnd, int num)
{
    int i,total;
    int endMax;
    total = *pEnd - *pStart + 1;
    endMax= *pEnd;
    for(i = 1; i < num; i++)
    {
        if((*(pStart+i) > endMax)&&(*(pEnd+i) > *(pStart+i)))
        {
            total+=*(pEnd+i)-*(pStart+i)+1;
            endMax = *(pEnd+i);
        }
        else if(*(pEnd+i)>endMax)
        {
            total+=*(pEnd+i) - endMax;
            endMax = *(pEnd+i);
        }
    }
    return total;
}
    
int main()
{
    int len,num,i;
    int *pStart;
    int *pEnd;
    
    scanf("%d%d", &len, &num);
    pStart = (int*)malloc(num*sizeof(int));
    pEnd = (int*)malloc(num*sizeof(int));
    for(i = 0; i<num; i++)
    {
        scanf("%d%d", pStart+i, pEnd+i);    
    }
    
    sortTwoArray(pStart, pEnd, num);
    printf("%d\n", len - countNoRepeat(pStart, pEnd, num)+1);
    free(pStart);
    free(pEnd);
    return 0;
}

 

0.0分

0 人评分

看不懂代码?想转换其他语言的代码? 或者想问其他问题? 试试问问AI编程助手,随时响应你的问题:

编程语言转换

万能编程问答  

代码解释器

代码纠错

SQL生成与解释

  评论区