Daily AtCoder # 34 in Python

Introduction

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)

ABC098-B

** 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')

ABC072-C

** 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))

ABC057-B

** 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)

ABC107-B

** 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)

Summary

It was easy except for the last problem. See you again, good night

Recommended Posts

Daily AtCoder # 2 in Python
Daily AtCoder # 6 in Python
Daily AtCoder # 18 in Python
Daily AtCoder # 53 in Python
Daily AtCoder # 33 in Python
Daily AtCoder # 24 in Python
Daily AtCoder # 37 in Python
Daily AtCoder # 8 in Python
Daily AtCoder # 42 in Python
Daily AtCoder # 21 in Python
Daily AtCoder # 17 in Python
Daily AtCoder # 38 in Python
Daily AtCoder # 54 in Python
Daily AtCoder # 11 in Python
Daily AtCoder # 15 in Python
Daily AtCoder # 47 in Python
Daily AtCoder # 13 in Python
Daily AtCoder # 45 in Python
Daily AtCoder # 30 in Python
Daily AtCoder # 40 in Python
Daily AtCoder # 10 in Python
Daily AtCoder # 5 in Python
Daily AtCoder # 28 in Python
Daily AtCoder # 39 in Python
Daily AtCoder # 20 in Python
Daily AtCoder # 19 in Python
Daily AtCoder # 52 in Python
Daily AtCoder # 3 in Python
Daily AtCoder # 14 in Python
Daily AtCoder # 50 in Python
Daily AtCoder # 26 in Python
Daily AtCoder # 4 in Python
Daily AtCoder # 29 in Python
Daily AtCoder # 22 in Python
Daily AtCoder # 49 in Python
Daily AtCoder # 27 in Python
Daily AtCoder # 1 in Python
Daily AtCoder # 25 in Python
Daily AtCoder # 16 in Python
Daily AtCoder # 12 in Python
Daily AtCoder # 48 in Python
Daily AtCoder # 23 in Python
Daily AtCoder # 34 in Python
Daily AtCoder # 51 in Python
Daily AtCoder # 31 in Python
Daily AtCoder # 46 in Python
Daily AtCoder # 35 in Python
Daily AtCoder # 9 in Python
Daily AtCoder # 44 in Python
Daily AtCoder # 41 in Python
Atcoder ABC164 A-C in Python
Python Input Note in AtCoder
Atcoder ABC167 A-D in Python
Atcoder ABC165 A-D in Python
Atcoder ABC166 A-E in Python
Atcoder ABC169 A-E in Python
AtCoder ABC177 A-D in python
Solve Atcoder ABC169 A-D in Python
[Python] Basic knowledge used in AtCoder
Quadtree in Python --2
Python in optimization