nan_xing @ 2022-07-29 11:38:07
#include<bits/stdc++.h>
using namespace std;
const int MAXN=1000;
int main()
{
int l,m,a[MAXN],b=0;
cin>>l>>m;
for(int i=1;i<=m*2;i++)
{
cin>>a[i];
}
sort(a+1,a+m+1);
for(int i=2;i<=m*2;i++)
{
for(int j=2;j<=m*2;j++)
{
b+=a[j]-a[i];
}
}
cout<<l-b;
return 0;
}
by 褚橙 @ 2022-07-29 11:41:54
@you_father 是不是这儿错了
sort(a+1,a+1+2*m);
by nan_xing @ 2022-07-29 11:45:51
不对,改了还是一样
by 褚橙 @ 2022-07-29 11:47:23
@you_father 还有就是您的j好像会小于i吧
by 褚橙 @ 2022-07-29 11:52:36
您好像思路错了,它好像不要排序
by nan_xing @ 2022-07-29 11:54:56
那应该怎么改呢?
by 褚橙 @ 2022-07-29 11:55:02
#include<bits/stdc++.h>
using namespace std;
int l,n,a,b,book[10005],ans;
int main()
{
//freopen(".in","r",stdin);
//freopen(".out","w",stdout);
cin>>l>>n;
for(int i=1;i<=n;i++)
{
cin>>a>>b;
for(int j=a;j<=b;j++)
{
book[j]=1;
}
}
for(int i=0;i<=l;i++)
{
if(!book[i])
{
ans++;
}
}
cout<<ans<<endl;
return 0;
}
这是我的代码,您可以改改
by nan_xing @ 2022-07-29 12:49:29
栓Q AC了