洛谷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;
}

上一篇:分布式应用测试工作遐想


下一篇:洛谷P7735题解