티스토리 뷰
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int clockswitch[10][16] = {
{1,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0},
{0,0,0,1,0,0,0,1,0,1,0,1,0,0,0,0},
{0,0,0,0,1,0,0,0,0,0,1,0,0,0,1,1},
{1,0,0,0,1,1,1,1,0,0,0,0,0,0,0,0},
{0,0,0,0,0,0,1,1,1,0,1,0,1,0,0,0},
{1,0,1,0,0,0,0,0,0,0,0,0,0,0,1,1},
{0,0,0,1,0,0,0,0,0,0,0,0,0,0,1,1},
{0,0,0,0,1,1,0,1,0,0,0,0,0,0,1,1},
{0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0},
{0,0,0,1,1,1,0,0,0,1,0,0,0,1,0,0}
};
int minsum = INT_MAX;
void trigerswitch(int arr[16], int switches,int sum) {
int count = 0;
for (int i = 0; i < 16; i++) {
if (arr[i] == 12)count++;
}
if (count == 16) {
if(minsum > sum)minsum = sum;
return;
}
if (switches == 10) { return; }
for (int i = 0; i < 4; i++) {
int mem = sum + i;
trigerswitch(arr, switches + 1, mem);
for (int j = 0; j < 16; j++) {
if (clockswitch[switches][j] == 1) {
arr[j] = arr[j] + 3;
if (arr[j] == 15)arr[j] = 3;
}
}
}
return;
}
int main() {
ios_base::sync_with_stdio(0);
cin.tie(0);
int c;
cin >> c;
for (int i = 0; i < c; i++) {
minsum =INT_MAX;
int arr[16];
for (int j = 0; j < 16; j++) {
int a;
cin >> a;
arr[j] = a;
}
trigerswitch(arr, 0, 0);
cout << minsum << "\n";
}
}
'PS' 카테고리의 다른 글
| LIS (0) | 2021.01.28 |
|---|---|
| 2차원 배열을 함수의 인자로 전달(포인터로) (0) | 2021.01.20 |
| boardcover (0) | 2021.01.16 |
| 1010 다리놓기 (0) | 2021.01.13 |
| 1654 랜선자르기 (0) | 2021.01.12 |
- Total
- Today
- Yesterday
- 6018
- tea time
- 1738
- 1918
- 어린왕자 C++
- 6539
- C++
- 스택
- 타임머신
- 벨만-포드
- 골목길
- 중위 표기식 후위 표기식으로 변환
- 상범빌딩
- 7511
- 골목길C++
- 1004
- 백준
- 후위 표기식
- 11657
- 소셜네트워킹어플리케이션
- 벨만포드
| 일 | 월 | 화 | 수 | 목 | 금 | 토 |
|---|---|---|---|---|---|---|
| 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 | 29 | 30 | 31 |
