Created
March 31, 2012 13:53
-
-
Save unionx/2264942 to your computer and use it in GitHub Desktop.
admaster_2012_3_30_count_rectangles
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
这程序写得到处都是魔法数啊