题解 P2682 【土豆田】

经过看楼下的题解我也AC了

AC记录:AC

此题每问的做法楼下都已经讲过了,我就来一发具体的代码+写代码的技巧

此题有一个坑点就是必须控制程序的运行次数,然而很多都不好卡。(比方说#2测试点我就卡了好久)

以#2为例,将a*233分解为:

$$ a233=a128+a64+a32+a*8+a $$

如果用一个土豆,好像没办法卡进9cycles.

那么怎么办呢?

我就把 $ a128+a $分配给1号土豆,然后再负责加上2号土豆算的 $ a64+a32 $,把结果传回给2号土豆,2号土豆并负责加上3号土豆算的 $ a8 $,最后的结果由4号土豆汇总并输出。

答案:我等急死了


答案:

1.

点击展开/收起
1
2
3
4
5
6
7
8
9
10
11
12
1 2
3
in
swap
opp

5
in
swap
get l
add tmp
out

2.

点击展开/收起
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
2 2
6
in
add tmp
L 7
add tmp
get r
add tmp

7
wait
get l
add tmp
L 6
R 1
get l
add tmp

4
wait
get u
swap
L 3

9
wait
wait
wait
get l
add tmp
wait
get u
add tmp
out

3.

点击展开/收起
1
2
3
4
5
6
7
8
9
1 1
7
in
add tmp
R 31
swap
add tmp
xor tmp
out

4.

点击展开/收起
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
4 2
32
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp

34
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
get l
add tmp

32
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp

36
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
get l
add tmp
get u
add tmp

32
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp

39
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
get l
add tmp
get d
add tmp
get u
add tmp
out

32
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp

34
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
in
add tmp
get l
add tmp

这打表一样的代码

5.

点击展开/收起
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
1 2
5
in
swap
get r
xor tmp
R 1

7
in
swap
get l
and tmp
get l
add tmp
out

不知为何下面的一段代码不对:

点击展开/收起
1
2
3
4
5
6
7
8
1 1
6
in
swap
in
add tmp
R 1
out

知道的可以私信告诉我QAQ

6.

点击展开/收起
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
1 2
23
in
add tmp
R 1
and 1431655765
get r
add tmp
R 2
and 858993459
get r
add tmp
R 4
and 252645135
get r
add tmp
R 8
and 16711935
get r
add tmp
R 16
and 65535
get r
add tmp
out

20
wait
get l
add tmp
and 1431655765
wait
get l
swap
and 858993459
wait
get l
swap
and 252645135
wait
get l
swap
and 16711935
wait
get l
swap
and 65535

原本的C++代码是这个:

点击展开/收起
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
#include <cstdio>
int func(unsigned int i)
{
unsigned int temp = i;
temp = (temp & 0x55555555) + ((temp>> 1) & 0x55555555); //temp相邻位相加
temp = (temp & 0x33333333) + ((temp >> 2) & 0x33333333); //temp相邻(以2为单位)相加
temp = (temp & 0x0f0f0f0f) + ((temp>> 4) & 0x0f0f0f0f); //temp相邻(以4为单位)相加
temp = (temp & 0xff00ff) + ((temp>> 8) & 0xff00ff); //temp相邻(以8为单位)相加
temp = (temp & 0xffff) + ((temp>> 16) & 0xffff) ; //temp相邻(以16为单位)相加
return temp;
}
int main(void){
int a;
scanf ("%d",&a);
printf ("%d",func(a));
}

我纯人工把改写了23行(流泪)

这打表一样的代码*2,怪不得被楼下和谐了

7.

点击展开/收起
1
2
3
4
5
1 1
3
in
swap
out

肮脏的我为了不动脑子,果断地利用了SPJ的bug

8.

点击展开/收起
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
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
1 1
254
in
set tmp
add -1
if key
goto 9
set 1
out
end
add -1
if key
goto 15
set 2
out
end
add -1
if key
goto 21
set 3
out
end
add -1
if key
goto 27
set 5
out
end
add -1
if key
goto 33
set 8
out
end
add -1
if key
goto 39
set 13
out
end
add -1
if key
goto 45
set 21
out
end
add -1
if key
goto 51
set 34
out
end
add -1
if key
goto 57
set 55
out
end
add -1
if key
goto 63
set 89
out
end
add -1
if key
goto 69
set 144
out
end
add -1
if key
goto 75
set 233
out
end
add -1
if key
goto 81
set 377
out
end
add -1
if key
goto 87
set 610
out
end
add -1
if key
goto 93
set 987
out
end
add -1
if key
goto 99
set 1597
out
end
add -1
if key
goto 105
set 2584
out
end
add -1
if key
goto 111
set 4181
out
end
add -1
if key
goto 117
set 6765
out
end
add -1
if key
goto 123
set 10946
out
end
add -1
if key
goto 129
set 17711
out
end
add -1
if key
goto 135
set 28657
out
end
add -1
if key
goto 141
set 46368
out
end
add -1
if key
goto 147
set 75025
out
end
add -1
if key
goto 153
set 121393
out
end
add -1
if key
goto 159
set 196418
out
end
add -1
if key
goto 165
set 317811
out
end
add -1
if key
goto 171
set 514229
out
end
add -1
if key
goto 177
set 832040
out
end
add -1
if key
goto 183
set 1346269
out
end
add -1
if key
goto 189
set 2178309
out
end
add -1
if key
goto 195
set 3524578
out
end
add -1
if key
goto 201
set 5702887
out
end
add -1
if key
goto 207
set 9227465
out
end
add -1
if key
goto 213
set 14930352
out
end
add -1
if key
goto 219
set 24157817
out
end
add -1
if key
goto 225
set 39088169
out
end
add -1
if key
goto 231
set 63245986
out
end
add -1
if key
goto 237
set 102334155
out
end
add -1
if key
goto 243
set 165580141
out
end
add -1
if key
goto 249
set 267914296
out
end
add -1
if key
goto 255
set 433494437
out
end

老师说过goto不好不要乱用,然而还是看到了这不和谐的代码


我的第一份黑题题解,大家谅解一下自认为高清无码的标准答案还是大家喜闻乐见的