A - Lucky Direction
Time Limit: 2 sec / Memory Limit: 1024 MB
Problem Statement
You are given a string DDD representing one of the eight directions (north, east, west, south, northeast, northwest, southeast, southwest). The correspondence between the directions and their representing strings is as follows.
- North:
N - East:
E - West:
W - South:
S - Northeast:
NE - Northwest:
NW - Southeast:
SE - Southwest:
SW
Print the string representing the direction opposite to the direction denoted by DDD.
给你一个字符串 DDD 代表八个方向(北、东、西、南、东北、西北、东南、西南)之一。方向与其代表字符串之间的对应关系如下。
- 北
N - 东:`E
- 西:
W - 南:
S - 东北:
NE - 西北:
NW - 东南:`SE
- 西南:
SW
打印与 DDD 表示的方向相反的字符串。
Constraints
-
DDD is one of
N,E,W,S,NE,NW,SE,SW. -
DDD 是
N、E、W、S、NE、NW、SE、SW中的一个。
题解
将 DDD 中的 N 替换为 S ,S 替换为 N ,E 替换为 W ,W 替换为 E 即可。
s = input()
ns = ''
for i in s:
if i == 'N':
ns += 'S'
elif i=='S':
ns += 'N'
elif i=='W':
ns += 'E'
else:
ns += 'W'
print(ns)
B - Seek Grid
Time Limit: 2 sec / Memory Limit: 1024 MB
Problem Statement
You are given an N×NN \times NN×N grid SSS and an M×MM \times MM×M grid TTT. The cell at the iii-th row from the top and the jjj-th column from the left is denoted by (i,j)(i,j)(i,j).
The colors of the cells in SSS and TTT are represented by N2N^2N2 characters Si,jS_{i,j}Si,j (1≤i,j≤N1\leq i,j\leq N1≤i,j≤N) and M2M^2M2 characters Ti,jT_{i,j}Ti,j (1≤i,j≤M1\leq i,j\leq M1≤i,j≤M), respectively. In grid SSS, cell (i,j)(i,j)(i,j) is white if Si,jS_{i,j}Si,j is ., and black if Si,jS_{i,j}Si,j is #. The same applies for grid TTT.
Find TTT within SSS. More precisely, output integers aaa and bbb (1≤a,b≤N−M+11 \leq a,b \leq N-M+11≤a,b≤N−M+1) that satisfy the following condition:
- Sa+i−1,b+j−1=Ti,jS_{a+i-1,b+j-1} = T_{i,j}Sa+i−1,b+j−1=Ti,j for every i,ji,ji,j (1≤i,j≤M1\leq i,j \leq M1≤i,j≤M).
给你一个 N×NN \times NN×N 网格 SSS 和一个 M×MM \times MM×M 网格 TTT 。位于从上往下第 iii 行和从左往上第 jjj 列的单元格用 (i,j)(i,j)(i,j) 表示。
SSS 和 TTT 中单元格的颜色分别用 N2N^2N2 字符 Si,jS_{i,j}Si,j ( 1≤i,j≤N1\leq i,j\leq N1≤i,j≤N )和 M2M^2M2 字符 Ti,jT_{i,j}Ti,j ( 1≤i,j≤M1\leq i,j\leq M1≤i,j≤M )表示。在网格 SSS 中,如果 Si,jS_{i,j}Si,j 为".",则单元格 (i,j)(i,j)(i,j) 为白色;如果 Si,jS_{i,j}Si,j 为 “#”,则单元格 (i,j)(i,j)(i,j) 为黑色。网格 TTT 也是如此。
在 SSS 中找到 TTT 。更精确地说,输出满足以下条件的整数 aaa 和 bbb ( 1≤a,b≤N−M+11 \leq a,b \leq N-M+11≤a,b≤N−M+1 ):
- 每个 i,ji,ji,j ( 1≤i,j≤M1\leq i,j \leq M1≤i,j≤M ) 都有 Sa+i−1,b+j−1=Ti,jS_{a+i-1,b+j-1} = T_{i,j}Sa+i−1,b+j−1=Ti,j 个整数。
Constraints
- 1≤M≤N≤501 \leq M \leq N \leq 501≤M≤N≤50
- NNN and MMM are integers.
- NNN 和 MMM 都是整数。
- Each of Si,jS_{i,j}Si,j and Ti,jT_{i,j}Ti,j is
.or#. - Si,jS_{i,j}Si,j 和 Ti,jT_{i,j}Ti,j 中的每一个都是
.或#。 - There is exactly one pair (a,b)(a,b)(a,b) satisfying the condition.
- 正好有一对 (a,b)(a,b)(a,b) 满足条件。
题解
暴力遍历所有可能得左上角,如果匹配则输出。
def solve():
n, m = map(int, input().split())
gs = [list(input()) for i in range(n)]
gt = [list(input()) for i in range(m)]
for bx in range(n-m+1):
for by in range(n-m+1):
f = 1
for x in range(m):
for y in range(m):
if gt[x][y] != gs[bx+x][by+y]:
f = 0
break

最低0.47元/天 解锁文章
852

被折叠的 条评论
为什么被折叠?



