CSP-2回收站选址


回收站选址

百度代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
n=int(input())
trashDict=[]
listKeys=[]
listScoreCount=[0,0,0,0,0]

def toStr(x,y):
return str(x)+' '+str(y)

def toFind(x,y):
return toStr(x+1,y) in trashDict and\
toStr(x-1,y) in trashDict and\
toStr(x,y+1) in trashDict and\
toStr(x,y-1) in trashDict

def getScore(x,y):
score=0;
if toStr(x+1,y+1) in trashDict:
score+=1
if toStr(x+1,y-1) in trashDict:
score+=1
if toStr(x-1,y+1) in trashDict:
score+=1
if toStr(x-1,y-1) in trashDict:
score+=1
listScoreCount[score]+=1

for i in range(n):
temp_a,temp_b=map(int,input().split(' '))
listKeys.append(temp_a)
listKeys.append(temp_b)
trashDict.append(toStr(temp_a,temp_b))

for j in range(0,2*n,2):
x,y=listKeys[j],listKeys[j+1]
if toFind(x,y):
getScore(x,y)

print(*listScoreCount,sep='\n')

自己的代码

两个例子都通过但只有40分,不知道怎么回事

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
n = int(input())
li_out = [0]*5
li_point = []
m = 0
for i in range(n):
p = list(map(int, input().split()))
li_point.append(p)
for i in li_point:
if [i[0], i[1]+1] in li_point and [i[0], i[1]-1] in li_point and [i[0]+1, i[1]] in li_point and [i[0]-1, i[1]] in li_point:
if [i[0]+1, i[1]+1] in li_point:
m += 1
if [i[0]+1, i[1]-1] in li_point:
m += 1
if [i[0]-1, i[1]+1] in li_point:
m += 1
if [i[0]-1, i[1]-1] in li_point:
m += 1
if m > 0:
li_out[m] += 1
m = 0
for i in li_out:
print(i)

错误

新知识

1
2
# 
for i in range(0, n, 2)
1
2
# 快速打印列表里的值并换行输出
print(*list, sep='\n')

本文标题:CSP-2回收站选址

文章作者:TTYONG

发布时间:2020年07月26日 - 16:07

最后更新:2020年07月26日 - 17:07

原始链接:http://tianyong.fun/CSP-2%E5%9B%9E%E6%94%B6%E7%AB%99%E9%80%89%E5%9D%80.html

许可协议: 转载请保留原文链接及作者。

多少都是爱
0%