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
- 누적 합
- 스택
- 자료구조
- BFS
- VR
- c++
- 우선순위 큐
- 다이나믹 프로그래밍
- 그래프
- Unreal Engine 5
- 알고리즘
- 브루트포스
- 정렬
- 투 포인터
- 수학
- 백준
- 유니온 파인드
- 구현
- 트리
- ue5
- DFS
- 재귀
- 다익스트라
- 그리디 알고리즘
- 문자열
- Team Fortress 2
- 시뮬레이션
- 백트래킹
- 유니티
- XR Interaction Toolkit
Archives
- Today
- Total
1일1알
백준 1331번 나이트 투어 C++ 본문
입력받은대로 나이트가 움직일 수 있고 마지막 칸에서 처음 칸으로 올 수 있다면 Valid, 아니면 Invalid를 출력하도록 했다.
#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 dAlp[8] = { -2,-1, 1, 2, 2, 1,-1,-2 };
int dNum[8] = { 1, 2, 2, 1,-1,-2,-2,-1 };
set<string> st;
bool CanGo(string target, string curr) {
for (int i = 0; i < 8; i++) {
string next = "";
next += curr[0] + dAlp[i];
next += curr[1] + dNum[i];
if (next[0] < 'A' || next[0]>'F') continue;
if (next[1] < '1' || next[1]>'6') continue;
if (next != target) continue;
if (st.find(next) != st.end()) continue;
st.insert(target);
return true;
}
return false;
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
vector<string> v(35);
string curr, start;
cin >> start;
curr = start;
st.insert(curr);
bool isValid = true;
for (int i = 0; i < 35; i++) {
cin >> v[i];
}
for (int i = 0; i < 35; i++) {
string target = v[i];
if (CanGo(v[i], curr)) {
curr = target;
}
else {
isValid = false;
break;
}
}
st.erase(start);
if (isValid) {
if (!CanGo(start, v[v.size() - 1])) {
isValid = false;
}
}
if (isValid) cout << "Valid";
else cout << "Invalid";
};
'알고리즘' 카테고리의 다른 글
백준 1347번 미로 만들기 C++ (0) | 2022.04.24 |
---|---|
백준 1337번 올바른 배열 C++ (0) | 2022.04.23 |
백준 1292번 쉽게 푸는 문제 C++ (0) | 2022.04.21 |
백준 1283번 단축키 지정 C++ (0) | 2022.04.20 |
백준 1270번 전쟁-땅따먹기 C++ (0) | 2022.04.19 |