题目描述
为了进行一种游戏,现决定搭造一些平板,而各个平板的地址已经选定。基于最普遍的认识,没有任何支持物的平板不可能漂浮在空中。说的更精确些,任意一平板的两端必需有支柱或者它在另一块平板上。
你会得到各个平板在坐标系中的坐标(如左下图)。每一块平板的坐标都是由它的高度(与地板间的垂直距离)和它的水平方位(开始和结束)决定的。每个支柱都距它支撑的平板的边缘半个单位(如图)。
算出支持所有平板的支柱的总长度。
输入格式
第一行包括1个整数N,1 ≤ N ≤ 100,即平板的总数。
接下来的N行每行都是一块平板的坐标,是相应的Y,X1和 X2。即高度和水平的边缘坐标。所有的数都是不大于10000的正整数且满足X2 > X1+1(也可这样理解,每一块平板的长度至少为2)。
输入保证任意两块平板间没有重叠部分。
输出格式
要撑起所有平板所需的支柱的总长度。
输入输出样例
输入 #1
3
1 5 10
3 1 5
5 3 7
输出 #1
14
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<queue>
#include<cstdio>
#include<math.h>
#include<climits>
#include <map>
using namespace std;
int n,m,ans = 0;
struct no{
int y,x1,x2;
}a[1010];
int main(){
ios_base::sync_with_stdio(0); // 让cin变快
cin.tie(0); // 让cin变快
cin >> n;
for(int i = 1; i <= n; i++) {
cin >> a[i].y >> a[i].x1 >> a[i].x2;
}
for(int i = 1; i <= n; i++) {
int y = a[i].y,x1 = a[i].x1,x2 = a[i].x2;
int h1 = 0, h2 = 0;
for( int j = 1; j <= n; j++) {
if(i == j) continue;
if(a[j].y >= y) continue;
if(a[j].x2 > x1 && a[j].x1 <= x1 ) {
h1 = max(h1,a[j].y);
}
if(a[j].x2 >= x2 && a[j].x1 < x2 ) {
h2 = max(h2,a[j].y);
}
}
ans+= y * 2 - h1 - h2;
}
cout << ans << endl;
return 0;
}