平台

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

程序:

var
   y,x1,x2:array [0..101] of longint;
   i,j,k,k1,l,l1,n,ans:longint;
begin
   assign(input,'platforme.in'); 
   reset(input);
   assign(output,'platforme.out');
   rewrite(output);
   readln(n);
   for i:=1 to n do
   begin
       readln(y[i],x1[i],x2[i]);
       inc(x1[i]);
   end;
   for i:=1 to n do
   begin
        k:=0; l:=0;
        for j:=1 to n do
          if i<>j then
           if y[j]<y[i] then
           begin
               if (y[j]>k) and (x1[i]>=x1[j]) and (x1[i]<=x2[j])
                  then k:=y[j];
               if (y[j]>l) and (x2[i]>=x1[j]) and (x2[i]<=x2[j])
                  then l:=y[j];
           end; 
        ans:=ans+(y[i]-k)+(y[i]-l);
   end;
   writeln(ans);
   close(input); 
   close(output);
end.

原文地址:https://www.cnblogs.com/YYC-0304/p/9500062.html