Skip to content

Instantly share code, notes, and snippets.

@lethe2211
Created May 12, 2014 15:10
Show Gist options
  • Save lethe2211/68e2ba47a2ae4bd8356a to your computer and use it in GitHub Desktop.
Save lethe2211/68e2ba47a2ae4bd8356a to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
def func():
hw = map(int, raw_input().split())
h = hw[0]
w = hw[1]
display = []
for i in range(h):
row = raw_input()
display.append(row)
n = int(raw_input())
for i in range(n):
widget = raw_input().split()
s = int(widget[0])
t = int(widget[1])
count = 0
for j, row in enumerate(display):
for i, elem in enumerate(row):
flag = False
for dy in range(s):
for dx in range(t):
if j+dy >= h or i+dx >= w or display[j+dy][i+dx] == '1':
flag = True
break
if flag == True:
break
else:
count += 1
print count
return None
if __name__ == '__main__':
func()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment