oooczk @ 2022-09-18 23:41:37
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<math.h>
int main()
{
int l, m, u, v,i,arr[10000]={0};
int keshu=0;
scanf("%d%d", &l, &m);
for (i = 0; i < m; i++)
{
scanf("%d%d", &u, &v);
for (; u <= v; u++)
{
arr[u - 1] = 1;
}
}
for (i= 0; i < l; i++)
{
if (arr[i] == 1)
keshu++;
}
printf("%d\n", l-keshu+1);
return 0;
}
by 不食嗟来之食 @ 2022-09-19 07:35:05
#include<stdio.h>
#include<math.h>
const int N=1e4+5;
int main() {
int l,m,u,v,i,arr[N]= {0};
int keshu=0;
scanf("%d%d",&l,&m);
for (i=0;i<m;i++) {
scanf("%d%d",&u,&v);
for (;u<=v;u++)arr[u]=1;
}
for (i=0;i<=l;i++)if (arr[i]==1)keshu++;
printf("%d\n",l-keshu+1);
return 0;
}
改了两个边界 原代码很容易Hack掉, 比如 1 1 1 1,这样输出是1,而正确答案是0