Dingding2007 @ 2022-11-11 21:15:53
没过的点数据如下 1000 5 0 100 101 200 900 1000 207 400 401 899
#include <bits/stdc++.h>
int u[10000],v[10000],a[10000];
using namespace std;
int main()
{
int l,m,i,sum=1,ans;
cin>>l>>m;
for(i=0;i<=m-1;i++)
{
cin>>u[i]>>v[i];
}
for(int k=0;k<=i;k++)
{
for(int j=u[k];j<=v[k];j++)
a[j]=1;
}
for(int k=0;k<=l;k++)
{ if(a[k]==0)
sum++;
}
cout<<sum;
return 0;
}
by 鱼跃于渊 @ 2022-11-11 21:25:24
@Dingding2007
by Kevin_Mamba @ 2022-11-11 21:30:03
@Dingding2007
#include <bits/stdc++.h>
int u[10000],v[10000],a[10000];
using namespace std;
int main()
{
int l,m,i,sum=0,ans;
cin>>l>>m;
for(i=0;i<=m-1;i++)
{
cin>>u[i]>>v[i];
}
for(int k=0;k<i;k++)
{
for(int j=u[k];j<=v[k];j++)
a[j]=1;
}
for(int k=0;k<=l;k++)
{ if(a[k]==0)
sum++;
}
cout<<sum;
return 0;
}
by 鱼跃于渊 @ 2022-11-11 21:33:13
@2124Kobe
by Dingding2007 @ 2022-11-12 15:48:40
多谢指点
by FJ_00460 @ 2022-11-15 13:30:28
using namespace std; const int N = 10005; bool tree[N]; int x, y, sum, l, m; int main() { memset(tree,1, sizeof(tree)); cin >> l >> m; //输入 for(int i = 1 ; i <= m ; i++) { cin >> x >> y; for(int j = x; j <= y; j++) tree[j] = 0; //区域中树为0 } for(int i = 0 ; i <= l; i++) sum += tree[i]; cout << sum; return 0; }