문제 링크입니다: www.acmicpc.net/problem/1333
1333번: 부재중 전화
첫째 줄에 N, L, D가 공백을 사이에 두고 주어진다. 모든 수는 1,000보다 작거나 같은 자연수이다.
www.acmicpc.net
남들보다 훨씬 복잡하게 푼 문제였습니다.
저 같은 경우 최악의 케이스를 미리 계산한 후,
앨범이 재생되는 시간 내 전화벨을 들을 수 있을 경우 해당 초를 출력해주도록 코드를 작성했습니다.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
using namespace std; | |
const int SILENT_SECTION = 5; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int N, L, D; | |
cin >> N >> L >> D; | |
int result; | |
// 최악 케이스 | |
for(int i=1; ; i++) | |
{ | |
if (D * i > N * L + (N - 1) * SILENT_SECTION) | |
{ | |
result = D * i; | |
break; | |
} | |
} | |
for (int n = 1; n <= N; n++) | |
{ | |
int silentStart = n * L + (n - 1) * SILENT_SECTION; | |
int silentEnd = silentStart + SILENT_SECTION; | |
bool foundAnswer = false; | |
for (int i = 1; D * i < silentEnd; i++) | |
{ | |
if (silentStart <= D * i && D * i < silentEnd) | |
{ | |
result = D * i; | |
foundAnswer = true; | |
break; | |
} | |
// 동시에 끝날 경우 X | |
if (silentStart < D * i + 1 && D * i + 1 < silentEnd) | |
{ | |
result = D * i + 1; | |
foundAnswer = true; | |
break; | |
} | |
} | |
if (foundAnswer) | |
{ | |
break; | |
} | |
} | |
cout << result << "\n"; | |
return 0; | |
} |


개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 1598번 꼬리를 무는 숫자 나열 (0) | 2021.04.04 |
---|---|
백준 1547번 공 (0) | 2021.04.04 |
백준 1284번 집 주소 (0) | 2021.04.04 |
백준 21335번 Another Eruption (0) | 2021.04.02 |
백준 1247번 부호 (0) | 2021.03.31 |