https://school.programmers.co.kr/learn/courses/30/lessons/250137
프로그래머스
코드 중심의 개발자 채용. 스택 기반의 포지션 매칭. 프로그래머스의 개발자 맞춤형 프로필을 등록하고, 나와 기술 궁합이 잘 맞는 기업들을 매칭 받으세요.
programmers.co.kr
간만에 코테문제..
알고리즘은 다 까먹고, 우선 오랜만에 쓰는 파이썬과 친해지기 위해 단순구현 문제 풀이
import copy
def solution(bandage, health, attacks):
answer = 0;
attTime = [];
attDamage = [];
# 공격분류
for i in range(len(attacks)):
attTime.append(attacks[i][0]);
attDamage.append(attacks[i][1]);
maxTime = max(attTime);
maxHealth = copy.deepcopy(health);
# 계산
cnt = 0;
for i in range(1, maxTime + 1):
cnt += 1;
# 공격시간인 경우
if i in attTime:
health -= attDamage[0];
attDamage.pop(0);
attTime.pop(0);
cnt = 0;
if health <=0:
return -1
# 공격시간이 아닌경우
else:
# 연속 성공이 성공했을 때,
if cnt == bandage[0]:
cnt = 0;
if maxHealth - (health + bandage[1] + bandage[2]) >= 0:
health += bandage[1];
health += bandage[2];
else:
health = maxHealth;
# 연속 성공이 아직 안된경우
else:
if maxHealth - (health + bandage[1]) >= 0:
health += bandage[1];
else:
health = copy.deepcopy(maxHealth);
answer = health;
if health <= 0:
return -1
return answer'Algorithm > programmers' 카테고리의 다른 글
| [파이썬] programmers: 공원 산책 (0) | 2024.01.25 |
|---|---|
| [파이썬]PCCP 기출문제 2번/ 석유 시추 (0) | 2024.01.09 |
| [파이썬]programmers: 게임 맵 최단거리 (0) | 2023.03.31 |
| [파이썬]programmers: 할인 행사 (0) | 2023.03.06 |
| [파이썬]programmers: 스킬트리 (0) | 2023.03.05 |
댓글