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
- 보배반점
- 레지스터 제어
- 송도 가츠동
- 백준
- 트리플스트리트 일식
- 박가네
- 카카오링크
- 송도 에비동
- 송도맛집
- 송도 짬뽕 맛집
- 듀에
- 울릉도 스쿠버
- 울릉도 다이빙
- 트리플스트리트 짬뽕
- 카카오톡 api
- 아두이노
- 카카오링크 api
- 테크노파크 짬뽕
- 트리플스트리트 맛집
- 카카오api
- 트리플스트리트
- 테크노파크 맛집
- 울릉다이브리조트
- 카카오메시지 api
- 트리플스트리트 돈까스
- 트리플스트리트 중식
- 송도 홍대돈부리
- 삼성코테
- 송도 가츠동 맛집
- 알고리즘
Archives
- Today
- Total
라바 세마리
[알고리즘/삼성SW역량테스트]백준 14891 톱니바퀴 본문
*
알고리즘 분류는 시뮬레이션으로 되어있는데,
나는 BFS를 약간 넣어서 풀이했다.
//출처 :https://www.acmicpc.net/problem/14891
#pragma warning (disable:4996)
#include <iostream>
#include <queue>
using namespace std;
int t[4][8];
int n;
int spin[100][2];
int result;
void spin_f(int spin_t, int spin_d) {
if (spin_d == 1) {
int tmp = t[spin_t][7];
for (int i = 6; i >= 0; i--) t[spin_t][i + 1] = t[spin_t][i];
t[spin_t][0] = tmp;
}
else if (spin_d == -1) {
int tmp = t[spin_t][0];
for (int i = 1; i < 8; i++) t[spin_t][i - 1] = t[spin_t][i];
t[spin_t][7] = tmp;
}
}
int main() {
for (int i = 0; i < 4 * 8; i++) scanf("%1d", &t[i/8][i%8]);
scanf("%d", &n);
for (int i = 0; i < n; i++) scanf("%d %d", &spin[i][0], &spin[i][1]);
for (int i = 0; i < n; i++) {
queue<pair<int, int>> q;
bool vis[4] = { 0, };
int spin_t = spin[i][0] - 1;
int spin_d = spin[i][1];
q.push(make_pair(spin_t, spin_d));
while (!q.empty()) {
int cur_t = q.front().first;
int cur_d = q.front().second;
vis[cur_t] = 1;
q.pop();
if (cur_t + 1 < 4) { // 오른쪽 방향
if (t[cur_t][2] != t[cur_t + 1][6] && vis[cur_t + 1] == 0) {
q.push(make_pair(cur_t + 1, cur_d * (-1)));
}
}
if (cur_t - 1 >= 0) { // 왼쪽 방향
if (t[cur_t][6] != t[cur_t - 1][2] && vis[cur_t - 1] == 0) {
q.push(make_pair(cur_t - 1, cur_d * (-1)));
}
}
spin_f(cur_t, cur_d);
}
}
if (t[0][0] == 1) result += 1;
if (t[1][0] == 1) result += 2;
if (t[2][0] == 1) result += 4;
if (t[3][0] == 1) result += 8;
printf("%d", result);
return 0;
}
'알고리즘 일기' 카테고리의 다른 글
[알고리즘/삼성SW역량테스트] 백준14889 스타트와 링크(1등기념!) (0) | 2020.08.15 |
---|