ATION001 @ 2024-06-16 19:50:12
被第一个测试点卡了……
代码:
#include<bits/stdc++.h>
using namespace std;
int b[1010],n,m,l,r,ans;
int main(){
ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
cin>>n>>m;
while(m--){
cin>>l>>r;
for(int i=l;i<=r;i++){
b[i]=1;
}
}
for(int i=1;i<=n;i++){
ans+=!b[i];
}
cout<<ans+1;
return 0;
}
by MuYuMC @ 2024-06-16 19:53:57
@ATION001 看看我的代码吧
#include <iostream>
#include <string>
#include <cmath>
#include <algorithm>
#include <iomanip>
using namespace std;
int book[10100],L,m,l,r,ans,i;
int main()
{
cin >> L >> m;
for(i = 0;i <= L;i++)book[i] = 1;
while(m--)
{
cin >> l >> r;
for(i = l;i <= r;i++)book[i] = 0;
}
for(i = 0;i <= L;i++)
{
if(book[i])ans++;
}
cout << ans;
return 0;
}
求关
by qcx2024 @ 2024-06-18 20:10:54
#include<bits/stdc++.h>
using namespace std;
int main()
{
int a[10010],b,c,d,e,num=0;
cin>>b>>c;
for(int i=0;i<=b;i++)
{
a[i]=1;
}
for(int j=0;j<=c-1;j++)
{
cin>>d>>e;
for(int k=d;k<=e;k++)
{
a[k]=0;
}
}
for(int l=0;l<=b;l++)
{
if (a[l]==1)
num++;
}
cout<<num;
}
by qcx2024 @ 2024-06-18 20:11:21
更简洁的c++
by ATION001 @ 2024-07-01 14:14:07
@MuYuMC @qcx2024 能告诉我哪里错了吗?
by Syncc @ 2024-07-01 17:51:40
@ATION001 路的起点是0
by ATION001 @ 2024-07-01 17:59:58
@Razer_System 谢谢,已AC,可以互关吗?
by Syncc @ 2024-07-01 18:13:10
@ATION001 OK
by YFXxlZem @ 2024-07-14 18:54:43
第一个测试点有一组是0 100,这个0可能没有被算进去