2 篇文章 0 订阅

# [NOIP2015 普及组] 扫雷游戏

NOIP2015 普及组 T2

## 样例 #1

### 样例输入 #1

3 3
*??
???
?*?


### 样例输出 #1

*10
221
1*1


## 样例 #2

### 样例输入 #2

2 3
?*?
*??


### 样例输出 #2

2*1
*21


## 提示

x=input().split(' ')
xx=[]
ls=[]
ss=int(x[0])*int(x[1])
#整个矩阵
for i in range(ss+1):
xx.append(0)
#矩阵初始化，给每行赋值为0，准备计数
for i in range(1,int(x[0])+1):
zz=input()
for j in range(1,int(x[1])+1):
if zz[j-1]=='?':
continue
elif zz[j-1]=='*':
ls.append((i-1)*int(x[1])+j)
if (i-2)*int(x[1])+j>=(i-3)*int(x[1])+1 and (i-2)*int(x[1])+j <= (i-1)*int(x[1]) and (i - 2) * int(x[1]) + j >=1 and(i - 2) * int(x[1]) + j <=ss:
xx[(i-2)*int(x[1])+j]+=1
if (i - 2) * int(x[1]) + j-1 >=(i-2)*int(x[1])+1 and (i - 2) * int(x[1]) + j-1 <= (i-1)*int(x[1]) and (i - 2) * int(x[1]) + j-1 >=1 and(i - 2) * int(x[1]) + j-1 <=ss :
xx[(i - 2) * int(x[1]) + j-1] += 1
if (i - 2) * int(x[1]) + j +1 >= (i-2)*int(x[1])+1 and (i - 2) * int(x[1]) + j + 1 <= (i-1)*int(x[1]) and (i - 2) * int(x[1]) + j+1 >=1 and(i - 2) * int(x[1]) + j+1 <=ss:
xx[(i - 2) * int(x[1]) + j +1]+=1
#上方
if (i - 1) * int(x[1]) + j -1>= (i-1)*int(x[1])+1 and (i - 1) * int(x[1]) + j -1 <= i*int(x[1]) and (i - 1) * int(x[1]) + j-1 >=1 and(i - 1) * int(x[1]) + j-1 <=ss:
xx[(i - 1) * int(x[1]) + j -1]+=1
if (i - 1) * int(x[1]) + j +1>= (i-1)*int(x[1])+1 and (i - 1) * int(x[1]) + j +1 <= i*int(x[1]) and (i - 1) * int(x[1]) + j+1 >=1 and(i - 1) * int(x[1]) + j+1 <=ss:
xx[(i - 1) * int(x[1]) + j +1]+=1
#本行
if i * int(x[1]) + j +1>= (i)*int(x[1])+1 and i * int(x[1]) + j +1 <= (i+1)*int(x[1]) and (i) * int(x[1]) + j+1 >=1 and i * int(x[1]) + j+1 <=ss:
xx[i * int(x[1]) + j +1]+=1
if i * int(x[1]) + j -1>= i*int(x[1])+1 and i * int(x[1]) + j -1 <= (i+1)*int(x[1]) and (i) * int(x[1]) + j-1 >=1 and i * int(x[1]) + j-1 <=ss:
xx[i * int(x[1]) + j -1]+=1
if i * int(x[1]) + j>= i*int(x[1])+1 and i * int(x[1]) + j<= (i+1)*int(x[1]) and (i) * int(x[1]) + j >=1 and i * int(x[1]) + j <=ss:
xx[i * int(x[1])+j] += 1
#下方
#八个方向，都进行判断是否在相同行之内，然后进行计数
for i in range(1,int(x[0])+1):
for j in range(1,int(x[1])+1):
if (i-1)*int(x[1])+j not in ls:
print(xx[(i-1)*int(x[1])+j],end='')
else:
print('*',end='')
print('')

• 0
点赞
• 0
收藏
觉得还不错? 一键收藏
• 打赏
• 0
评论
08-04
09-05
01-13 96
04-09 1万+
03-30 714
10-17
05-27 2816
04-22 2万+
03-08 935

### “相关推荐”对你有帮助么？

• 非常没帮助
• 没帮助
• 一般
• 有帮助
• 非常有帮助

ctf^_^

¥2 ¥4 ¥6 ¥10 ¥20

1.余额是钱包充值的虚拟货币，按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载，可以购买VIP、C币套餐、付费专栏及课程。