SHARE
TWEET

Verify a rectangle covering

a guest Jan 17th, 2015 260 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # Verify a rectangle covering.
  2.  
  3. def main():
  4.     domain, rects = input()
  5.     domain = set(domain)
  6.    
  7.     for (x, y, w, h) in rects:
  8.         if w <= 0 or h <= 0:
  9.             return "Degenerate rectangle at %s."%((x,y),)
  10.         for i in range(x, x+w):
  11.             for j in range(y, y+h):
  12.                 if (i,j) in domain:
  13.                     domain.remove((i,j))
  14.                 else:
  15.                     return "Coordinate %s covered incorrectly."%((i,j),)
  16.         for (x2, y2, w2, h2) in rects:
  17.             if x == x2 and w == w2 and y + h == y2:
  18.                 return "Aligned rectangles at %s and %s."%((x,y),(x2,y2))
  19.             if y == y2 and h == h2 and x + w == x2:
  20.                 return "Aligned rectangles at %s and %s."%((x,y),(x2,y2))
  21.     if domain:
  22.         return "Coordinate %s not covered."%(domain.pop(),)
  23.     else:
  24.         return "The covering is valid."
  25.  
  26. if __name__ == "__main__":
  27.     print main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top