분류 전체보기
-
1158) 요세푸스 문제백준코딩일기 2020. 11. 5. 13:46
문제 ) www.acmicpc.net/problem/1158 1158번: 요세푸스 문제 첫째 줄에 N과 K가 빈 칸을 사이에 두고 순서대로 주어진다. (1 ≤ K ≤ N ≤ 5,000) www.acmicpc.net 풀이 ) 이번 문제는 연결리스트를 활용하는 대표적인 문제이다. c++ STL list 는 양방향 연결 리스트인데, 이걸 응용해서 원형 연결 리스트로 바꿔서 사용했다. 리스트를 선언한 뒤, push_back 을 이용해서 1~n 번까지 list에 넣어 준다. 이터레이터를 만들어서 리스트의 begin()을 가리키케 만든다. n번째에 있는 사람부터 제거한다고 했으니, 이터레이터를 움직이면서 1명이 남을 때까지 제거할 번호를 찾는다. 원형 연결 리스트로 만들기 위해 erase 를 한 뒤, del = l..