其他分享
首页 > 其他分享> > 洛谷P1047

洛谷P1047

作者:互联网

在比赛中能用一维数组,较少的代码就用较少的

#include <bits/stdc++.h>

using namespace std;
const int N = 1e4 + 5;
bool st[N];

int main()
{
	int m, l, sum = 0;
	cin >> l >> m;
	memset(st, 1, sizeof st);
	for (int i = 0; i <= l; ++i)
		st[i] = 1;
	for (int i = 1; i <= m; ++i)
	{
		int s, e;
		cin >> s >> e;
		for (int j = s; j <= e; ++j)
			st[j] = 0;
	}
	for (int i = 0; i <= l; ++i)
		if (st[i])
			++sum;
	cout << sum << endl;
	return 0;
}

标签:洛谷,int,memset,st,P1047,using,sizeof,1e4
来源: https://blog.csdn.net/weixin_51658332/article/details/122410704