CCF2019-12-Python题解

报数

试题编号: 201912-1
试题名称: 报数
时间限制: 1.0s
内存限制: 512.0MB

 

 

 题解:7的倍数和含有数字7的 不算入计数内

 1 num=int(input())
 2 
 3 ans=[0,0,0,0]
 4 
 5 i=0
 6 while num:
 7     i+=1
 8     if i%7==0 or '7'in str(i):
 9         if i%4==0:
10             index=3
11         else:
12             index=i%4-1
13         ans[index]+=1
14     else:
15         num-=1
16 
17 for a in ans:
18     print(a)

 

 

回收站选址

试题编号: 201912-2
试题名称: 回收站选址
时间限制: 1.0s
内存限制: 512.0MB

 

 

 

题解:一个点,8个方向的判断,对于(x, y)满足4个蓝色点才能建造垃圾厂,红色每满足一个点,加一分,

(x-1, y+1)(x, y+1)(x+1, y+1)

(x-1, y)    (x, y)    (x+1, y)

(x-1, y-1)(x, y-1) (x+1, y-1)

7
1 2
2 1
0 0
1 1
1 0
2 0
0 1

 

 1 n=int(input())
 2 
 3 ans=[]
 4 for _ in range(n):
 5     tmp=list(map(int, input().split()))
 6     ans.append(tmp)
 7 score=[0,0,0,0,0]
 8 for a in ans:
 9     x,y=a[0],a[1]
10     if ([x-1,y] in ans) and ([x+1,y] in ans ) and ([x,y-1] in ans) and ([x,y+1] in ans):
11         summ=0
12         if ([x+1,y+1] in ans):
13             summ+=1
14         if ([x-1,y+1] in ans):
15             summ+=1
16         if ([x-1,y-1] in ans):
17             summ+=1
18         if ([x+1,y-1] in ans):
19             summ+=1
20 
21         score[summ]+=1
22 
23 for i in score:
24     print(i)

 

posted @ 2021-04-03 17:57  浅忆~  阅读(68)  评论(0编辑  收藏  举报