2016普级组模拟试题(20161114) 平台

来源:互联网 发布:jenkins windows节点 编辑:程序博客网 时间:2024/05/17 07:34

Description

为了进行一种游戏,现决定搭造一些平板,而各个平板的地址已经选定。基于最普遍的认识,没有任何支持物的平板不可能漂浮在空中。说的更精确些,任意一平板的两端必需有支柱或者它在另一块平板上。
你会得到各个平板在坐标系中的坐标(如左下图)。每一块平板的坐标都是由它的高度(与地板间的垂直距离)和它的水平方位(开始和结束)决定的。每个支柱都距它支撑的平板的边缘半个单位(如右下图)。
算出支持所有平板的支柱的总长度。

Input

输入文件platforme.in第一行包括1个整数N,1 ≤ N ≤ 100,即平板的总数。
接下来的N行每行都是一块平板的坐标,是相应的Y,X1和 X2。即高度和水平的边缘坐标。所有的数都是不大于10000的正整数且满足X2 > X1+1(也可这样理解,每一块平板的长度至少为2)。
输入保证任意两块平板间没有重叠部分。

Output

输出文件platforme.out要撑起所有平板所需的支柱的总长度。

Sample Input

3
1 5 10
3 1 5
5 3 7
Sample Output

14

题解

在其他n-1条线段中找到包含这条线段两根支柱的最高的线段,统计。

代码

var  n,i,j,max1,max2,ans1,ans2,sum:longint;  h,l,r:array[1..1000] of longint;begin  readln(n);  for i:=1 to n do readln(h[i],l[i],r[i]);  for i:=1 to n do    begin      for j:=1 to n do        begin          if (i<>j)and(h[i]>h[j])and(h[j]>max1)and(l[i]>=l[j])and(l[i]<r[j]) then            begin              max1:=h[j];              ans1:=j;            end;          if (i<>j)and(h[i]>h[j])and(h[j]>max2)and(r[i]<=r[j])and(r[i]>l[j]) then            begin              max2:=h[j];              ans2:=j;            end;        end;      if ans1=0 then sum:=sum+h[i]      else sum:=sum+h[i]-h[ans1];      if ans2=0 then sum:=sum+h[i]      else sum:=sum+h[i]-h[ans2];      ans1:=0;ans2:=0;      max1:=0;max2:=0;    end;  writeln(sum);end.
1 0