就是从输入的点(两个坐标为一个点),找它上下左右是有存在点在输入里面,如果有,就可以作为回收站点,再判断它的左上、左下、右上、右下是否存在点在输入里面,存在一个加一分,从而得出对应回收站点的得分。
def rub_stand():
n = int(input())
a = [[0] * 2 for i in range(n)] #创建二维列表 列:2 行:n
count = [0]*5 #创建一维列表
for i in range(n):
a[i][0],a[i][1] = map(int,input().split()) #一组空格为间隔的输入
for j,k in a:
score = 0;
left = [j-1,k] #用括号也是可以的
right = [j+1,k]
up = [j,k-1]
down = [j,k+1]
if left in a and right in a and up in a and down in a:
l_u = [j-1,k+1]
l_d = [j-1,k-1]
r_u = [j+1,k+1]
r_d = [j+1,k-1]
if l_d in a:
score += 1
if l_u in a:
score += 1
if r_d in a:
score += 1
if r_u in a:
score += 1
count[score] += 1
for l in count:
print(l)
if __name__ == '__main__':
rub_stand()
1、创建二维列表:
a = [[0] * 2 for i in range(n)]
2、空格输入
map(int,input().split())