CCF 201912-2 回收站选址 python 满分

    科技2022-07-11  101

    CCF 201912-2 回收站选址 python 满分

    题目叙述问题描述:略输入格式:略输出格式:略样例 满分证明解题思路满分代码满分代码一满分代码二思路正确,但爆内存

    题目叙述

    问题描述:略

    输入格式:略

    输出格式:略

    样例

    样例输入 7 1 2 2 1 0 0 1 1 1 0 2 0 0 1 样例输出 0 0 1 0 0 样例输入 2 0 0 -100000 10 样例输出 0 0 0 0 0 样例输入 11 9 10 10 10 11 10 12 10 13 10 11 9 11 8 12 9 10 9 10 11 12 11 样例输出 0 2 1 0 0

    满分证明

    解题思路

    思路应该特别简单,只是我想难了;直接存在list中,用in去判断就好了;另一种就是用数组模拟整个坐标系(坐标系小还可以尝试),但这样内存会爆,下面附代码,你可以试试,(#.#)!

    满分代码

    满分代码一

    ss = [] n = int(input()) fc = [0] * 5 def sxzy(mzb): tx = mzb[0] ty = mzb[1] if ([tx, ty + 1] in ss) & ([tx, ty - 1] in ss) & ([tx + 1, ty] in ss) & ([tx - 1, ty] in ss): return True else: return False def js(pzb): te = 0 tx = pzb[0] ty = pzb[1] # 右上 if [tx + 1, ty + 1] in ss: te += 1 # 左下 if [tx - 1, ty - 1] in ss: te += 1 # 右下 if [tx + 1, ty - 1] in ss: te += 1 # 左上 if [tx - 1, ty + 1] in ss: te += 1 return te for _ in range(n): ss.append(list(map(int, input().split()))) for i in range(n): if sxzy(ss[i]): if js(ss[i]) == 0: fc[0] += 1 elif js(ss[i]) == 1: fc[1] += 1 elif js(ss[i]) == 2: fc[2] += 1 elif js(ss[i]) == 3: fc[3] += 1 elif js(ss[i]) == 4: fc[4] += 1 for i in range(5): print(fc[i])

    满分代码二

    n = int(input()) zb=[] count=[0,0,0,0,0] for _ in range(n): x,y=map(int,input().split()) zb.append([x,y]) for zz in zb: ct=0 if ([zz[0],zz[1]+1] in zb ) &([zz[0],zz[1]-1] in zb )&([zz[0]-1,zz[1]] in zb )&([zz[0]+1,zz[1]] in zb ): if [zz[0]-1,zz[1]+1] in zb: ct=ct+1 if [zz[0]-1,zz[1]-1] in zb: ct=ct+1 if [zz[0]+1,zz[1]-1] in zb: ct=ct+1 if [zz[0]+1,zz[1]+1] in zb: ct=ct+1 count[ct]=count[ct]+1 for cc in count: print(cc)

    思路正确,但爆内存

    zb = ["0" * (2 * 10 ** 9 + 3) for _ in range(2 * 10 ** 9 + 3)] ss = [] n = int(input()) fc = [0] * 5 def sxzy(mzb): tx = mzb[0] ty = mzb[1] if zb[tx][ty + 1] == zb[tx][ty - 1] == zb[tx + 1][ty] == zb[tx - 1][ty] == "1": return True else: return False def js(pzb): te = 0 tx = pzb[0] ty = pzb[1] if zb[tx - 1][ty + 1] == "1": te += 1 if zb[tx + 1][ty - 1] == "1": te += 1 if zb[tx + 1][ty + 1] == "1": te += 1 if zb[tx - 1][ty - 1] == "1": te += 1 return te for _ in range(n): jx, jy = map(int, input().split()) x = 10 ** 9 + 1 - jy y = 10 ** 9 + 1 + jx zb[x] = zb[x][:y] + "1" + zb[x][y + 1:] ss.append([x, y]) for i in range(n): if sxzy(ss[i]): if js(ss[i]) == 0: fc[0] += 1 elif js(ss[i]) == 1: fc[1] += 1 elif js(ss[i]) == 2: fc[2] += 1 elif js(ss[i]) == 3: fc[3] += 1 elif js(ss[i]) == 4: fc[4] += 1 for i in range(5): print(fc[i])
    Processed: 0.013, SQL: 8