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";
}


}