解题思路:
注意事项:
参考代码:
#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++代码)这里推荐使用宏定义浏览:1911 |
陶陶摘苹果 (C语言代码)浏览:1607 |
C语言程序设计教程(第三版)课后习题7.4 (Java代码)浏览:843 |
分糖果 (C++代码)浏览:1447 |
C语言程序设计教程(第三版)课后习题11.3 (C语言代码)浏览:1039 |
1024题解浏览:811 |
前10名 (C语言代码)浏览:727 |
幸运数 (C++代码)浏览:2871 |
汽水瓶 (C语言代码)浏览:537 |
【偶数求和】 (C语言代码)浏览:441 |