-
algospot - clocksyncAlgorithm/알고스팟 2020. 1. 20. 05:531234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192//algospot - clocksync#include <iostream>#include <vector>using namespace std;#define INF 33333int arr[16];int big(int x, int y){return x > y ? x : y;}vector<vector<int> > button({vector<int>( { 0, 1, 2 }),vector<int>( { 3, 7, 9, 11 }),vector<int>( { 4, 10, 14, 15 }),vector<int>( { 0, 4, 5, 6, 7 }),vector<int>( { 6, 7, 8, 10, 12 }),vector<int>( { 0, 2, 14, 15 }),vector<int>( { 3, 14, 15 }),vector<int>( { 4, 5, 7, 14, 15 }),vector<int>( { 1, 2, 3, 4, 5 }),vector<int>( { 3, 4, 5, 9, 13 })});void init(){int u;for(int i =0; i<16; i++){cin >> u;arr[i] = (u/3) % 4;}}bool isEnd(){int ret = 0;for(int i = 0; i<16; i++)ret += arr[i];if(!ret)return true;return false;}int bf(int idx, int num){if(isEnd())return 0;else if(idx == 10)return INF;int ret = INF;int copy[16];for(int i = 0; i<16; i++)copy[i] = arr[i];for(int i = 0; i<button[idx].size(); i++)arr[button[idx][i]] = (arr[button[idx][i]]+num)%4;for(int i = 0; i<4; i++)ret = min(ret, bf(idx+1, i));for(int i = 0; i<16; i++)arr[i] = copy[i];return ret + num;}int bfAll(){int ret = bf(0, 0);for(int i = 1; i<4; i++)ret = min(ret, bf(0, i));return ret;}int main(){int C; cin >> C;for(int t_num = 0; t_num < C; ++t_num){init();int ans = bfAll();if(ans == INF)cout << -1 << endl;elsecout << ans << endl;}}
cs https://algospot.com/judge/problem/read/CLOCKSYNC
algospot.com :: CLOCKSYNC
Synchronizing Clocks 문제 정보 문제 그림과 같이 4 x 4 개의 격자 형태로 배치된 16개의 시계가 있다. 이 시계들은 모두 12시, 3시, 6시, 혹은 9시를 가리키고 있다. 이 시계들이 모두 12시를 가리키도록 바꾸고 싶다. 시계의 시간을 조작하는 유일한 방법은 모두 10개 있는 스위치들을 조작하는 것으로, 각 스위치들은 모두 적게는 3개에서 많게는 5개의 시계에 연결되어 있다. 한 스위치를 누를 때마다, 해당 스위치와 연결된 시계들
algospot.com
브루트포스 문제
버튼은 4번이상 누르는것은 의미없다는 것과 버튼을 누르는 순서는 상관없다는 것을 이용
'Algorithm > 알고스팟' 카테고리의 다른 글
algospot - nthlon (0) 2020.01.20 algospot - firetrucks (0) 2020.01.20 algospot - gallery (0) 2020.01.20 algospot - hanoi4 (0) 2020.01.17 algospot - picnic (0) 2020.01.17