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
- 트리
- XR Interaction Toolkit
- 그리디 알고리즘
- 유니온 파인드
- 브루트포스
- 그래프
- 수학
- 다이나믹 프로그래밍
- Team Fortress 2
- DFS
- BFS
- 스택
- 백준
- 정렬
- 알고리즘
- 유니티
- Unreal Engine 5
- VR
- 시뮬레이션
- ue5
- 투 포인터
- 다익스트라
- 자료구조
- 누적 합
- 문자열
- 재귀
- 구현
- c++
- 우선순위 큐
- 백트래킹
Archives
- Today
- Total
1일1알
백준 2016번 미팅 주선하기 C++ 본문
문제에 쓰여있는 대로 구현을 했는데 구현하는데 시간이 꽤 걸렸다. 생각보다 까다로웠던 문제였다.
#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>
using namespace std;
using ll = long long;
vector<vector<int>> v(11, vector<int>(5));
vector<bool> visited(11, false);
vector<int> th;
int origin_match = 0;
int match_max = 100;
void Solve() {
bool isOrigin = true;
for (int i = 0; i < 5; i++) {
v[1][i] = th[i];
if (th[i] != i + 6) isOrigin = false;
}
vector<vector<int>> tjj(11, vector<int>());
vector<int> proposed(6, 0);
vector<bool> tjjed(11, true);
while (true) {
for (int i = 6; i <= 10; i++) {
for (int j = 0; j < 5; j++) {
if (!tjjed[i]) break;
int boy = v[i][j];
if (find(tjj[boy].begin(), tjj[boy].end(), i) != tjj[boy].end()) continue;
if (proposed[boy] == 0) {
proposed[boy] = i;
tjjed[i] = false;
}
else {
auto currIt = find(v[boy].begin(), v[boy].end(), proposed[boy]);
auto newIt = find(v[boy].begin(), v[boy].end(), i);
if (currIt > newIt) {
tjj[boy].push_back(proposed[boy]);
tjjed[i] = false;
tjjed[proposed[boy]] = true;
proposed[boy] = i;
}
else {
tjj[boy].push_back(i);
}
}
break;
}
}
bool isBreak = true;
for (int i = 6; i <= 10; i++) {
if (tjjed[i]) isBreak = false;
}
if (isBreak) break;
}
if (isOrigin) origin_match = proposed[1];
else match_max = min(match_max, proposed[1]);
}
void BT(int cnt) {
if (cnt >= 5) {
Solve();
return;
}
for (int i = 6; i <= 10; i++) {
if (!visited[i]) {
th.push_back(i);
visited[i] = true;
BT(cnt + 1);
th.pop_back();
visited[i] = false;
}
}
}
int main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
int t;
cin >> t;
while (t--) {
for (int i = 2; i <= 10; i++) {
for (int j = 0; j < 5; j++) {
cin >> v[i][j];
}
}
BT(0);
if (match_max < origin_match) cout << "YES" << "\n";
else cout << "NO" << "\n";
origin_match = 0;
match_max = 100;
th.clear();
}
};
'알고리즘' 카테고리의 다른 글
백준 2818번 숙제하기 싫을 때 C++ (0) | 2022.02.01 |
---|---|
백준 1680번 쓰레기 수거 C++ (0) | 2022.02.01 |
백준 3987번 보이저 1호 C++ (0) | 2022.02.01 |
백준 10431번 줄세우기 C++ (0) | 2022.01.31 |
백준 1491번 나선 C++ (0) | 2022.01.30 |