-
Notifications
You must be signed in to change notification settings - Fork 0
/
clocksync.cpp
224 lines (170 loc) · 3.14 KB
/
clocksync.cpp
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
HeeJoong-Dominic
드라이브
.
폴더 경로
내 드라이브
자소서
새로 만들기
폴더 및 보기
내 드라이브
공유 문서함
Google 포토
최근
중요
휴지통
.
Word
2010920023_김희중_과학에세이_수정.hwp
PDF
2010920023_김희중_과학에세이_수정.pdf
Word
2010920023_김희중_과학에세이.hwp
PDF
2010920023_김희중_과학에세이.pdf
C++
clocksync.cpp
텍스트
clocksync.txt
C++
color.cpp
텍스트
color.txt
C++
door.cpp
텍스트
door.txt
C++
narrow_path.cpp
텍스트
narrow_path.txt
C++
nqueen.cpp
텍스트
nqueen.txt
C++
scales.cpp
텍스트
scales.txt
Google 문서
sk 자소서
C++
sudoku.cpp
텍스트
sudoku.txt
텍스트
clocksync.txt
세부정보
활동
clocksync.txt
공유 정보
공유되지 않음
일반 정보
유형
텍스트
크기
2KB (2,079바이트)
위치
자소서
소유자
나
수정한 날짜
오후 8:36, 나
열어본 날짜
오후 8:39, 나
만든 날짜
오후 8:36
설명
설명 추가
다운로드 권한
보기 권한만 있는 사용자는 다운로드 금지
5GB 사용함(30%)
저장용량 추가 구입
닫힘
clocksync.txt열기
/*
VC, GCC에서 사용
*/
#include <stdio.h>
/*
두뇌폭발 시계
*/
bool is_end;
int ans;
int link_rules[10][10] = {
{0, 1, 2, -1},
{3, 7, 9, 11, -1},
{4, 10, 14, 15, -1},
{0, 4, 5, 6, 7, -1},
{6, 7, 8, 10, 12, -1},
{0, 2, 14, 15, -1},
{3, 14, 15, -1},
{4, 5, 7, 14, 15, -1},
{1, 2, 3, 4, 5, -1},
{3, 4, 5, 9, 13, -1}
};
int time_switch(int time){
time += 3;
if(time == 15){
time = 3;
}
return time;
}
void click_switch(int switch_num, int* field){
int i;
for(i=0; link_rules[switch_num][i] != -1; i++){
field[link_rules[switch_num][i]] = time_switch(field[link_rules[switch_num][i]]);
}
}
bool is_all_set(int field[]){
int i;
for(i=0; i<16; i++){
if(field[i] != 12){
return false;
}
}
return true;
}
void solve(int clocks[], int index, int count){
if(is_all_set(clocks)){
ans = count;
return;
}
if(index > 9 || count > ans || count > 31){
return;
}
for(int i=0; i<4; i++){
solve(clocks, index+1, count+i);
click_switch(index, clocks);
}
}
int main()
{
int itr;
int nCount; /* 문제의 테스트 케이스 */
int clocks[16];
scanf("%d", &nCount); /* 테스트 케이스 입력 */
for(itr=0; itr<nCount; itr++)
{
printf("#testcase%d\n",itr+1);
/*
2
12 6 6 6 6 6 12 12 12 12 12 12 12 12 12 12
12 9 3 12 6 6 9 3 12 9 12 9 12 12 6 6
*/
for(int i=0; i<16; i++){
scanf("%d", &clocks[i]);
}
is_end = false;
ans = 1000;
int counts[16] ={};
solve(clocks, 0, 0);
if(ans == 1000){
ans = -1;
}
printf("%d\n", ans);
/*
알고리즘이 들어가는 부분
*/
}
return 0; /* 반드시 return 0으로 해주셔야합니다. */
}