문제 링크입니다: https://www.acmicpc.net/problem/4307
"두 개미가 만나게 된다면, 방향을 반대로 바꾸어 걸어가게 된다." 해당 문구 때문에 헷갈릴 수 있는 문제였습니다.
결론부터 말하자면 이런 경우는 전혀 고려하지 않아도 되는 문제였습니다.
개미들이 각자 갈길을 가며 최소 시간은 해당 지점부터 더 빠르게 떨어지는 막대 끝, 최대 시간은 해당 지점부터 더 빠르게 떨어지는 막대 끝으로 가는 시간을 구해주면 되는 그리디 문제였습니다.
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> | |
#include <algorithm> | |
using namespace std; | |
int L, N; | |
int main(void) | |
{ | |
ios_base::sync_with_stdio(0); | |
cin.tie(0); | |
int T; | |
cin >> T; | |
for (int t = 0; t < T; t++) | |
{ | |
cin >> L >> N; | |
int minTime = 0, maxTime = 0; | |
for (int i = 0; i < N; i++) | |
{ | |
int ant; | |
cin >> ant; | |
//왼족으로 가는 경우, 오른쪽으로 가는 경우 중 최소 | |
int antMin = min(ant, L - ant); | |
//왼쪽으로 가는 경우, 오른쪽으로 가는 경우 중 최대 | |
int antMax = max(ant, L - ant); | |
minTime = max(minTime, antMin); | |
maxTime = max(maxTime, antMax); | |
} | |
cout << minTime << " " << maxTime << "\n"; | |
} | |
return 0; | |
} |
개발환경:Visual Studio 2017
지적, 조언, 질문 환영입니다! 댓글 남겨주세요~
반응형
'알고리즘 > BOJ' 카테고리의 다른 글
백준 6568번 귀도 반 로썸은 크리스마스날 심심하다고 파이썬을 만들었다 (2) | 2019.03.27 |
---|---|
백준 16551번 Potato Sacks (0) | 2019.03.27 |
백준 10826번 피보나치 수 4 (0) | 2019.03.15 |
백준 10757번 큰 수 A+B (7) | 2019.03.15 |
백준 1850번 최대공약수 (0) | 2019.03.15 |