94
84
51
76
79
143
139
72
144
136
81
152
113
134
99
52
155
99
49
82
56
122
113
<773 bytes omitted>
系统信息
Killed: Segmentation fault
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#46107 | #1153. wch和zxh的游♂戏 | Runtime Error | 0 | 36 ms | 412 K | C++ / 1.4 K | 233nihao | 2020-08-17 11:47:49 |
#include <bits/stdc++.h>
using namespace std;
int a[4][4];
int temps[10000];
int coun = 0;
int lll;
int left(int x2) {
int xx = x2 % 3;
int yy = x2 / 3;
int temp = a[xx][yy];
a[xx][yy] = a[xx + 1][yy];
a[xx + 1][yy] = a[xx + 1][yy + 1];
a[xx + 1][yy + 1] = a[xx][yy + 1];
a[xx][yy + 1] = temp;
int u = (a[xx][yy] + a[xx + 1][yy] + a[xx][yy + 1] + a[xx + 1][yy + 1]);
return u;
}
int right(int x) {
int xx = x % 3;
int yy = x / 3;
int temp = a[xx][yy];
a[xx][yy] = a[xx][yy + 1];
a[xx][yy + 1] = a[xx + 1][yy + 1];
a[xx + 1][yy + 1] = a[xx + 1][yy];
a[xx + 1][yy] = temp;
return (a[xx][yy] + a[xx + 1][yy] + a[xx][yy + 1] + a[xx + 1][yy + 1]);
}
int dfs(int x, int m, int count) {
int temp = 0;
temp = count;
if (m == 0) {
temps[coun] = temp;
coun++;
return temp;
} else
int temp = 0;
for (int i = 0; i < 9; i++) {
temp += left(i);
dfs(i, m - 1, temp);
temp -= right(i);
}
}
int select(int m) {
if (m < 0) {
return temps[0];
}
for (int p = 0; p < pow(9, 2 * m - 1); p++) {
for (int i = 0; i < 9; i++) {
int a = temps[p];
int b = temps[p * 9 + i];
temps[p] = a < b ? a : b;
}
}
for (int p = 0; p < pow(9, 2 * m - 2); p++) {
for (int i = 0; i < 9; i++) {
int a = temps[p];
int b = temps[p * 9 + i];
temps[p] = a > b ? a : b;
}
}
return select(m - 2);
}
int main() {
int n, lll;
cin >> n;
while (n--) {
cin >> lll;
coun = 0;
for (int i = 0; i < 4; i++) {
for (int j = 0; j < 4; j++) {
cin >> a[i][j];
}
}
dfs(0, 2 * lll, 0);
cout << select(lll) << endl;
}
}
94
84
51
76
79
143
139
72
144
136
81
152
113
134
99
52
155
99
49
82
56
122
113
<773 bytes omitted>
系统信息
Killed: Segmentation fault
94
97
108
68
81
103
42
89
140
135
104
113
90
46
132
110
114
85
150
87
39
33
50
<790 bytes omitted>
系统信息
Killed: Segmentation fault
116
132
102
42
86
46
155
86
92
83
48
98
62
45
147
45
147
128
97
44
148
69
74
<782 bytes omitted>
系统信息
Killed: Segmentation fault
131
146
126
57
110
139
42
146
41
123
46
38
90
42
101
48
84
135
80
34
46
140
12
<784 bytes omitted>
系统信息
Killed: Segmentation fault
120
126
118
132
86
80
86
115
121
82
49
136
186
77
45
147
153
104
146
79
144
54
<789 bytes omitted>
系统信息
Killed: Segmentation fault
57
104
98
75
115
153
155
44
90
51
136
39
48
113
42
115
93
51
39
77
153
129
144
<771 bytes omitted>
系统信息
Killed: Segmentation fault
40
39
39
33
118
144
67
131
101
129
158
44
166
154
47
84
87
110
107
41
43
119
4
<769 bytes omitted>
系统信息
Killed: Segmentation fault
97
46
129
75
131
111
96
158
82
35
119
47
86
67
70
126
49
103
165
46
37
90
43
<771 bytes omitted>
系统信息
Killed: Segmentation fault
91
94
77
127
82
113
97
38
45
41
111
45
91
82
45
35
84
92
88
115
119
77
121
16
<767 bytes omitted>
系统信息
Killed: Segmentation fault