解题思路:
注意事项:
参考代码:
#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 人评分
C语言程序设计教程(第三版)课后习题11.1 (C语言代码)浏览:724 |
C语言程序设计教程(第三版)课后习题6.9 (C语言代码)浏览:806 |
C语言程序设计教程(第三版)课后习题1.5 (C语言代码)浏览:644 |
C语言程序设计教程(第三版)课后习题8.4 (C语言代码)浏览:631 |
Wu-求圆的面积 (C++代码)浏览:1994 |
母牛的故事 (C语言代码)浏览:1451 |
1009题解浏览:802 |
矩阵加法 (C语言代码)浏览:1768 |
C语言程序设计教程(第三版)课后习题5.7 (C语言代码)浏览:537 |
简单的a+b (C语言代码)浏览:572 |