Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
Tags
- frontend
- 코딩테스트
- algorhtim
- typescript
- 42587
- 1844
- data platform
- Algorithm
- queue
- python
- summerwintercoding
- pymodbus
- modbus
- 알고리즘
- React
- 완전탐색
- Two Pointer
- 좌표이동
- 개발브로그
- InfluxDB
- 프로그래머스
- set활용
- configfile
- javascript
- 파이썬
- 스택/큐
- dfs
- javascirpt
- Stack
- DP
Archives
- Today
- Total
DM Log
[PCCP 기출문제] 1번 / 붕대 감기 - Python/JavaScript 본문
문제 링크 - https://school.programmers.co.kr/learn/courses/30/lessons/250137?language=javascript
프로그래머스
SW개발자를 위한 평가, 교육, 채용까지 Total Solution을 제공하는 개발자 성장을 위한 베이스캠프
programmers.co.kr
[문제 간단 요약]
1. 붕대 감기 기술은 매초 x만큼 체력 회복 / t초 연속 회복 시 y만큼 추가 회복
2. 몬스터는 특정 시간 때 데미지를 입혀 체력을 감소
3. 붕대 감기 기술은 몬스터 공격 시간에는 사용 불가
4. 몬스터의 모든 공격이 끝났을때 남은 체력을 구하는 구현 문제
[문제 해결 방안]
- 단순 구현 문제로 조건 분기를 통해 문제 해결
[문제 해결 코드 - Python]
def solution(bandage, health, attacks):
answer = 0
attack_chk = 0
bandage_chk = 0
max_health = health
for stage_time in range(attacks[-1][0]+1):
if attacks[attack_chk][0] == stage_time:
health -= attacks[attack_chk][1]
if health < 1 :
return -1
bandage_chk = 0
attack_chk += 1
else:
bandage_chk += 1
health = min(max_health, health+bandage[1])
if bandage_chk == bandage[0]:
health = min(max_health, health+bandage[2])
bandage_chk = 0
return health
[문제 해결 코드 - JavaScript]
function solution(bandage, health, attacks) {
let attack_chk = 0;
let bandage_chk = 0;
const max_health = health
for (stage_time=0; stage_time< attacks[attacks.length-1][0]+1; stage_time++) {
if (attacks[attack_chk][0] === stage_time) {
health -= attacks[attack_chk][1]
if (health < 1) {
return -1
}
bandage_chk = 0;
attack_chk += 1
} else {
bandage_chk += 1
health = Math.min(max_health, health+bandage[1])
if (bandage_chk === bandage[0]) {
health = Math.min(max_health, health + bandage[2])
bandage_chk = 0
}
}
}
return health;
}
'알고리즘 > 프로그래머스' 카테고리의 다른 글
[연습문제] 인사고과 - Python/JavaScript (2) | 2025.01.21 |
---|---|
[코딩테스트 연습] 혼자서 하는 틱택토 - Python (3) | 2025.01.12 |
[2023 KAKAO BLIND RECRUITMENT] 이모티콘 할인 행사 - Python (7) | 2025.01.11 |
[PCCP 기출문제] 2번 / 석유 시추 - Python/JavaScript (3) | 2025.01.08 |
[PCCP 기출문제] 2번 / 퍼즐 게임 챌린지 - Python/JavaScript (0) | 2025.01.05 |