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 |
Tags
- 다이나믹 프로그래밍
- 재귀
- 브루트포스
- Team Fortress 2
- 그래프
- 백준
- 그리디 알고리즘
- Unreal Engine 5
- 시뮬레이션
- 구현
- 우선순위 큐
- 유니티
- VR
- DFS
- 알고리즘
- 누적 합
- 스택
- 유니온 파인드
- 투 포인터
- 다익스트라
- 정렬
- 백트래킹
- 자료구조
- 수학
- 트리
- XR Interaction Toolkit
- c++
- ue5
- BFS
- 문자열
Archives
- Today
- Total
1일1알
백준 3258번 컴포트 C++ 본문
k를 1부터 증가시켜가면서 검사하면 되는데, 같은 구간을 계속 반복하는 경우도 있어서 반복되는것을 체크해주는것이 필요하다.
#include <iostream>
#include <string>
#include <vector>
#include <math.h>
#include <algorithm>
#include <utility>
#include <stack>
#include <queue>
#include <math.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <iomanip>
using namespace std;
using ll = long long;
int n, z, m;
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin >> n >> z >> m;
vector<int> circle(n + 1, 0);
circle[z] = 1;
for (int i = 0; i < m; i++) {
int obs;
cin >> obs;
circle[obs] = -1;
}
int ans = 0;
while (true) {
ans++;
int idx = 1;
bool isAns = false;
vector<bool> visited(n + 1, false);
while (true) {
int curr = idx + ans;
if (curr > n) curr %= n;
if (circle[curr] == -1) {
break;
}
if (circle[curr] == 1) {
isAns = true;
break;
}
if (visited[curr]) break;
visited[curr] = true;
idx = curr;
}
if (isAns) break;
}
cout << ans;
};
'알고리즘' 카테고리의 다른 글
백준 2418번 단어 격자 C++ (0) | 2022.02.14 |
---|---|
백준 2705번 팰린드롬 파티션 C++ (0) | 2022.02.13 |
백준 2082번 시계 C++ (0) | 2022.02.11 |
백준 1730번 판화 C++ (0) | 2022.02.10 |
백준 2374번 같은 수로 만들기 C++ (0) | 2022.02.09 |