zoukankan      html  css  js  c++  java
  • poj 1262 地板覆盖问题

    Problem

    一个地板被若干砖所覆盖。现在请你判断,这些砖是否恰好不重复,不遗漏的恰好覆盖了整个地板。 
    

    Input

    第一行为一个整数N,表示有N组测试数据。 
    每组测试数据第一行是两个数l, w,表示地板的长和宽(不超过40000)。 
    第二行是一个数t,表示有t块砖(1<=t<=400)。 
    下面t行每行是四个数,xl,yl,xh,yh,其中(xl,yl)是砖的左下角坐标,(xh,yh)是砖的右上角坐标。 
    

    Output

    每组数据输出包含一行。 
    如果输入中砖有交叉覆盖,则输出”NONDISJOINT” 
    否则如果有砖超出了地板,则输出”NONCONTAINED” 
    否则如果有部分地板没有被覆盖,则输   出”NONCOVERING” 
    否则输出”OK” 
    

    题解

    本题的关键盘是判断是否有交叉覆盖,判断标准如下:
    

    这里写图片描述
    如果不覆盖,C在A的右上角或B在A的左下角即可。
    r.left r.right r.up r.down 表示一个矩形r的左边右边上边下边四个判断(r1.left < r2.right) and (r2.left < r1.right) and (r1.up < r2.down) and (r2.up < r1.down)

    代码

    var
      nm,x,y,n,sum:longint;
      x1,y1,x2,y2,s:array [0..401] of longint;
    function max(o,p:longint):longint;
    begin
      if o>p then exit(o);
      exit(p);
    end;
    
    procedure init;
    var
      i,j,l,t,l1,l2:longint;
      f1,f2,f3:boolean;
    begin
      for l:=1 to nm do
        begin
          f1:=false; f2:=false; f3:=false;
          sum:=0;
          readln(x,y);
          readln(n);
          t:=max(x,y);
          for i:=1 to n do
            begin
              readln(x1[i],y1[i],x2[i],y2[i]);
              l1:=abs(x1[i]-x2[i]);
              l2:=abs(y1[i]-y2[i]);
              s[i]:=l1*l2;
              sum:=sum+s[i];
              if (x1[i]<0) or (x2[i]<0) or (y1[i]<0) or (y2[i]<0) then f2:=true;
              if (x1[i]>t) or (x2[i]>t) or (y1[i]>t) or (y2[i]>t) then f2:=true;
            end;
          if sum<x*y then f3:=true;
          for i:=1 to n do
            begin
              if f1 then break;
              for j:=i+1 to n do
                if (x1[j]>=x2[i]) or (x2[j]<=x1[i]) or (y1[j]>=y2[i]) or (y2[j]<=y1[i]) then
                  continue else
                  begin
                    f1:=true;
                    break;
                  end;
            end;
          if f1 then writeln('NONDISJOINT') else
            if f2 then writeln('NONCONTAINED') else
              if f3 then writeln('NONCOVERING') else
                writeln('OK');
        end;
    end;
    
    begin
      readln(nm);
      init;
    end.
    
  • 相关阅读:
    WCF Server Console
    Restart IIS With Powershell
    RestartService (recursively)
    Copy Files
    Stopping and Starting Dependent Services
    多线程同步控制 ManualResetEvent AutoResetEvent MSDN
    DTD 简介
    Using Powershell to Copy Files to Remote Computers
    Starting and Stopping Services (IIS 6.0)
    java中的NAN和INFINITY
  • 原文地址:https://www.cnblogs.com/zyx-crying/p/9319586.html
Copyright © 2011-2022 走看看