Last time I will do Boot camp for Beginners
#34 ABC075-B
** Thoughts ** Just replace with for and if
h, w = map(int,input().split())
s = [list(input()) for _ in range(h)]
for i in range(h):
for j in range(w):
count = 0
if s[i][j] == '#':
continue
for n, m in ([-1,1],[-1,0],[-1,-1],[0,1],[0,-1],[1,1],[1,0],[1,-1]):
if i + n < 0 or i + n >= h or j + m < 0 or j + m >= w:
continue
if s[i+n][j+m] == '#':
count += 1
s[i][j] = str(count)
ans = ''
for i in range(h):
c = ''.join(s[i])
ans += c
if i != h-1:
ans += '\n'
print(ans)
** Thoughts ** Just search all
n = int(input())
s = input()
ans = 0
for i in range(1,n):
x = list(set(list(s[:i])))
y = list(set(list(s[i:])))
c, d = 0, 0
for j in x:
c += y.count(j)
for j in y:
d += x.count(j)
ans = max(c,d,ans)
print(ans)
ABC064-C 2WA
** Thoughts ** I made a mistake in writing the conditions and got 2WA. The minimum value is when 3200 or more people match the color of 3200 or less people, or if there are no 3200 or less people, 3200 or more people use the same color. The maximum value is taken when more than 3200 people use different colors.
n = int(input())
a = list(map(int,input().split()))
check = [False] * 8
r = 0
for i in range(n):
if a[i] < 400:
check[0] = True
elif 400 <= a[i] < 800:
check[1] = True
elif 800 <= a[i] < 1200:
check[2] = True
elif 1200 <= a[i] < 1600:
check[3] = True
elif 1600 <= a[i] < 2000:
check[4] = True
elif 2000 <= a[i] < 2400:
check[5] = True
elif 2400 <= a[i] < 2800:
check[6] = True
elif 2800 <= a[i] < 3200:
check[7] = True
else:
r += 1
color = 0
ans_max = r
for i in range(8):
if check[i]:
color += 1
ans_max += 1
ans_min = max(color,1)
print(ans_min,ans_max)
ABC060-B 1WA,1TLE
** Thoughts ** No matter how many multiples of A are added, it is a multiple of A, so I searched all over a. The range can be up to b, but I searched up to about 10 ** 5.
import math
a, b, c = map(int,input().split())
for i in range(10**5):
n = a * i
if n % b == c:
print('YES')
quit()
print('NO')
** Thoughts ** Record the integers produced by each operation and take their maximum. The same number cannot be produced by the operation (because the integers are +1, -1, +0), so this method was used.
n = int(input())
a = list(map(int,input().split()))
num = [0] * (10**5+3)
for i in range(n):
num[a[i]] += 1
num[a[i]+2] += 1
num[a[i]+1] += 1
print(max(num))
** Thoughts ** For each student, the distance to all checkpoints is calculated and the minimum value is taken.
n, m = map(int,input().split())
ab = [list(map(int,input().split())) for _ in range(n)]
cd = [list(map(int,input().split())) for _ in range(m)]
for i in range(n):
dis = []
for j in range(m):
dis.append(abs(ab[i][0]-cd[j][0])+abs(ab[i][1]-cd[j][1]))
ans = dis.index(min(dis))
print(ans+1)
** Thoughts ** Handling columns and rows was very tedious. It's a dirty code ...
h, w = map(int,input().split())
a = [input() for _ in range(h)]
remove_a = []
for i in range(h): #next to'.'Delete the connection
if '#' in a[i]:
remove_a.append(list(a[i]))
n = len(remove_a)
l = []
for i in range(w):
s = ''
for j in range(n):
s += remove_a[j][i]
if '#' in s: #Vertical'.'Delete the connection
l.append(list(s))
ans = ''
for i in range(len(l[0])): #Since the vertical and horizontal are switched by the above operation, fix it
s = ''
for j in range(len(l)):
s += l[j][i]
ans += s
if i != len(l[0])-1: #The last line does not break
ans += '\n' #Don't forget the line breaks
print(ans)
It was easy except for the last problem. See you again, good night
Recommended Posts