题解【洛谷P2003】平板

题面

由于本题中\(n\)很小,\(\Theta(n^2)\)的暴力也可以通过。

具体可参照洛谷题解区

#include <bits/stdc++.h>
#define itn int
#define gI gi

using namespace std;

inline int gi()
{
	int f = 1, x = 0; char c = getchar();
	while (c < '0' || c > '9') {if (c == '-') f = -1; c = getchar();}
	while (c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return f * x;
}

int n, m, ans, cnt1, cnt2;
struct Node
{
	int y, x1, x2;
} a[103];

int main()
{
	//freopen(".in", "r", stdin);
	//freopen(".out", "w", stdout);
	n = gi();
	for (int i = 1; i <= n; i+=1) a[i].y = gi(), a[i].x1 = gi(), a[i].x2 = gi();
	for (int i = 1; i <= n; i+=1)
	{
		cnt1 = cnt2 = 0;
		for (int j = 1; j <= n; j+=1)
		{
			if (i == j || a[j].y >= a[i].y) continue;
			if (a[i].x1 < a[j].x2 && a[i].x1 >= a[j].x1) cnt1 = max(cnt1, a[j].y);
			if (a[i].x2 <= a[j].x2 && a[i].x2 > a[j].x1) cnt2 = max(cnt2, a[j].y);
		}
		ans += a[i].y * 2 - cnt1 - cnt2;
	}
	printf("%d\n", ans);
	return 0;
}
posted @ 2020-01-31 21:27  csxsi  阅读(151)  评论(0编辑  收藏  举报