Skip to content

Commit 19bfac1

Browse files
committed
9/7
1 parent ad434fa commit 19bfac1

File tree

6 files changed

+158
-0
lines changed

6 files changed

+158
-0
lines changed

CLOCKSYNC.cpp

+115
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
#include <iostream>
2+
#include <algorithm>
3+
4+
using namespace std;
5+
6+
int arr[16][10] = { 0, };
7+
int stat[16];
8+
void init();
9+
10+
bool check12(){
11+
for(int idx = 0; idx < 16; idx++){
12+
if (stat[idx] % 4 != 0){
13+
return false;
14+
}
15+
}
16+
return true;
17+
}
18+
19+
int prob(int switchIdx, int pushCount);
20+
21+
int main(void){
22+
int C;
23+
cin >> C;
24+
init();
25+
for(;C--;){
26+
for(int idx = 0; idx < 16; idx++){
27+
int time;
28+
cin >> time;
29+
stat[idx] = time / 3;
30+
}
31+
int value = prob(0, 0);
32+
cout << ((value == 999999) ? -1 : value) << endl;
33+
}
34+
}
35+
36+
int prob(int switchIdx, int pushCount){
37+
if (check12()){
38+
return pushCount;
39+
}
40+
else if (switchIdx == 10){
41+
//fail.
42+
return 999999;
43+
}
44+
int minRet = 999999;
45+
for(int push = 0; push < 4; push++){
46+
minRet = min(minRet, prob(switchIdx + 1, pushCount + push));
47+
for(int clockIdx = 0; clockIdx < 16; clockIdx++){
48+
if (arr[clockIdx][switchIdx] == 1){
49+
stat[clockIdx]++;
50+
}
51+
}
52+
}
53+
return minRet;
54+
}
55+
56+
void init() {
57+
arr[0][0] = 1;
58+
arr[0][3] = 1;
59+
arr[0][5] = 1;
60+
61+
arr[1][0] = 1;
62+
arr[1][8] = 1;
63+
64+
arr[2][0] = 1;
65+
arr[2][5] = 1;
66+
arr[2][8] = 1;
67+
68+
arr[3][1] = 1;
69+
arr[3][6] = 1;
70+
arr[3][8] = 1;
71+
arr[3][9] = 1;
72+
73+
arr[4][2] = 1;
74+
arr[4][3] = 1;
75+
arr[4][7] = 1;
76+
arr[4][8] = 1;
77+
arr[4][9] = 1;
78+
79+
arr[5][3] = 1;
80+
arr[5][7] = 1;
81+
arr[5][8] = 1;
82+
arr[5][9] = 1;
83+
84+
arr[6][3] = 1;
85+
arr[6][4] = 1;
86+
87+
arr[7][1] = 1;
88+
arr[7][3] = 1;
89+
arr[7][4] = 1;
90+
arr[7][7] = 1;
91+
92+
arr[8][4] = 1;
93+
94+
arr[9][1] = 1;
95+
arr[9][9] = 1;
96+
97+
arr[10][2] = 1;
98+
arr[10][4] = 1;
99+
100+
arr[11][1] = 1;
101+
102+
arr[12][4] = 1;
103+
104+
arr[13][9] = 1;
105+
106+
arr[14][2] = 1;
107+
arr[14][5] = 1;
108+
arr[14][6] = 1;
109+
arr[14][7] = 1;
110+
111+
arr[15][2] = 1;
112+
arr[15][5] = 1;
113+
arr[15][6] = 1;
114+
arr[15][7] = 1;
115+
}

CLOCKSYNC.exe

936 KB
Binary file not shown.

CLOCKSYNC.o

3.46 KB
Binary file not shown.

QUADTREE.cpp

+43
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
#include <iostream>
2+
3+
using namespace std;
4+
5+
string data;
6+
7+
string prob(string data);
8+
9+
int main(void){
10+
int C;
11+
cin >> C;
12+
for(;C--;){
13+
cin >> data;
14+
cout << prob(data) << endl;
15+
}
16+
return 0;
17+
}
18+
19+
string prob(string data){
20+
if (data.length() == 1){
21+
return data;
22+
}
23+
string quads[4];
24+
int offset = 1;
25+
for (int quadIdx = 0; quadIdx < 4; quadIdx++){
26+
int quadLen = 1;
27+
int counter = 1;
28+
for(int pos = offset; pos < data.length(); pos++){
29+
if (data[pos] == 'x'){
30+
counter += 4;
31+
quadLen += 4;
32+
}
33+
counter--;
34+
if (counter == 0){
35+
break;
36+
}
37+
}
38+
quads[quadIdx] = data.substr(offset, quadLen);
39+
offset += quadLen;
40+
}
41+
42+
return "x" + prob(quads[2]) + prob(quads[3]) + prob(quads[0]) + prob(quads[1]);
43+
}

QUADTREE.exe

937 KB
Binary file not shown.

QUADTREE.o

6.6 KB
Binary file not shown.

0 commit comments

Comments
 (0)