Skip to content

Instantly share code, notes, and snippets.

@unionx
Created March 31, 2012 13:53
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unionx/2264942 to your computer and use it in GitHub Desktop.
Save unionx/2264942 to your computer and use it in GitHub Desktop.
admaster_2012_3_30_count_rectangles
#!/usr/bin/env python
#coding:utf-8
# 题目:下图中一共有多少个矩形?星号表示挖空不计的部分
# # # # # # # # # # #
# # # # # # # # # # #
# # # * * * * # # # #
# # # * * * * # # # #
# # # * * * * # # # #
# # # # # # # # # # #
# # # # # # # # # # #
# # # # # # # # # # #
# # # # # # # # # # #
x_ran = 11
y_ran = 9
bad_x1 = 4
bad_x2 = 7
bad_y1 = 3
bad_y2 = 5
def good(x, y, x_l, y_l):
if x + x_l - 1 > x_ran or y + y_l - 1 > y_ran:
return False
for i in (x, x + x_l):
for j in (y, y + y_l):
if i >= bad_x1 and i <= bad_x2 and j >= bad_y1 and j <= bad_y2:
return False
return True
if __name__ == '__main__':
s = 0
for x in range(1, x_ran + 1):
for y in range(1, y_ran + 1):
for x_l in range(1, x_ran + 1):
for y_l in range(1, y_ran + 1):
if good(x, y, x_l, y_l):
s += 1
print(s)
@kidrane
Copy link

kidrane commented Mar 31, 2012

这程序写得到处都是魔法数啊

@unionx
Copy link
Author

unionx commented Mar 31, 2012

刚才写得比较急了,现在重构了一下,但是结果还是没对上啊

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment