티스토리 뷰

PS

clock sync

Eastplanet 2021. 1. 17. 03:07
더보기

#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
링크
«   2026/01   »
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
글 보관함