Last time Solve today's problem.
** Thoughts ** Just put it in set and len
n = int(input())
s = set(input().split())
if len(s) == 4:
print('Four')
else:
print('Three')
** Thoughts ** I did it a while ago. Examine all cells adjacent to all cells
h, w = map(int,input().split())
s = [input() for _ in range(h)]
g = [[]*w for _ in range(h)]
for i in range(h):
for j in range(w):
c = 0
if s[i][j] == '#':
g[i].append('#')
continue
for n, m in ([-1,1],[-1,0],[-1,-1],[0,1],[0,-1],[1,1],[1,0],[1,-1]):
new_h, new_w = i + n, j + m
if new_h < 0 or new_h >= h or new_w < 0 or new_w >= w:
continue
if s[new_h][new_w] == '#':
c += 1
g[i].append(str(c))
ans = ''
for i in range(h): #This way of writing is not dirty
c = ''.join(g[i])
ans += c
if i != h-1:
ans += '\n'
print(ans)
** Thoughts ** I implemented it because I was told in a comment earlier that the sum of squares is the minimum when the average value of each element is taken. The average used statistics. It can also be implemented using len and sum. ** Please note that PyPy does not have statistics **
import statistics
n = int(input())
a = list(map(int,input().split()))
mean = round(statistics.mean(a))
ans = 0
for i in range(n):
ans += (a[i]-mean)**2
print(ans)
** Thoughts ** The first round trip is the normal minimum distance. The second round trip should go around the outside.
sx, sy, tx, ty = map(int,input().split())
n = tx - sx #x coordinate distance
m = ty - sy #y coordinate distance
ans = 'R' * n + 'U' * m + 'L' * n + 'D' * m + 'L' + 'U' * (m+1) + 'R' * (n+1) + 'D' + 'R' + 'D' * (m+1) + 'L' * (n+1) + 'U'
print(ans)
E retired because he couldn't understand the meaning of the problem. It was 4 complete in 40 minutes. It was a simple problem, so I feel that I could solve it faster if I concentrated on solving it. See you again, good night
Recommended Posts