상세 컨텐츠

본문 제목

파이썬으로 풀어보는 SW Expert Academy 무선 충전 (삼성 A형 기출 문제)

Python/문제풀이 (삼성 A형 대비)

by 코딩하는 낙타 2020. 1. 22. 17:09

본문

https://swexpertacademy.com/main/code/problem/problemDetail.do?contestProbId=AWXRDL1aeugDFAUo

 

SW Expert Academy

SW 프로그래밍 역량 강화에 도움이 되는 다양한 학습 컨텐츠를 확인하세요!

swexpertacademy.com

 

내 풀이:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
def move(location, style):
    if style == 0:
        return location
    elif style == 1:
        location[0-= 1
        return location
    elif style == 2:
        location[1+= 1
        return location
    elif style == 3:
        location[0+= 1
        return location
    elif style == 4:
        location[1-= 1
        return location
 
 
def score(location):
    score = [0* A
    for tt in range(A):
        if abs(location[0- AP[tt][1]+1+ abs(location[1- AP[tt][0]+1<= AP[tt][2]:
            score[tt] = AP[tt][3]
    return score
 
 
def cal(score1, score2):
    result = 0
    if A ==1:
        return max(score1[0], score2[0])
    for i in range(A):
        for j in range(A):
            if i == j:
                pass
            else:
                if score1[i] + score2[j] > result:
                    result = score1[i] + score2[j]
    return result
 
 
= int(input())
for _ in range(T):
    M, A = map(int, input().split())
    move1 = list(map(int, input().split()))
    move2 = list(map(int, input().split()))
    AP = []
    for t in range(A):
        AP.append(list(map(int, input().split())))
    user1 = [0,0]
    user2 = [9,9]
    result = 0
    result += cal(score(user1),score(user2))
 
    for __ in range(M):
        user1 = move(user1, move1[__])
        user2 = move(user2, move2[__])
        result += cal(score(user1), score(user2))
    print("#%d %d" % (_ + 1, result))
 

Python, 319ms

문제를 제대로 안 읽고 풀다가 BC (Battery Charger)가 1~8개라는 조건을 뒤늦게 알고 코드를 고치느라 고생했다. 문제를 꼼꼼히 읽자.

관련글 더보기

댓글 영역