-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatom.xml
541 lines (283 loc) · 313 KB
/
atom.xml
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
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
<?xml version="1.0" encoding="utf-8"?>
<feed xmlns="http://www.w3.org/2005/Atom">
<title>Anoyer's Blog</title>
<link href="/atom.xml" rel="self"/>
<link href="https://anoyer.cn/"/>
<updated>2019-03-10T14:00:21.634Z</updated>
<id>https://anoyer.cn/</id>
<author>
<name>John Doe</name>
</author>
<generator uri="http://hexo.io/">Hexo</generator>
<entry>
<title>河南农大算法训练赛三月周赛-0310</title>
<link href="https://anoyer.cn/article/henau-0310.html"/>
<id>https://anoyer.cn/article/henau-0310.html</id>
<published>2019-03-10T13:46:19.000Z</published>
<updated>2019-03-10T14:00:21.634Z</updated>
<content type="html"><![CDATA[<h4 id="A-打理机房"><a href="#A-打理机房" class="headerlink" title="A - 打理机房"></a><a href="https://vjudge.net/contest/287051#problem/A" target="_blank" rel="noopener">A - 打理机房</a></h4><blockquote><p>题意:给一个字符串,如果大写数比小写数多,全部转化成大写,否则全部小写。</p><p>题解:遍历一遍字符串,用cnts和cntb记录大小写数量,最后对比调用strupr,strlwr</p></blockquote><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">char</span> s[<span class="number">120</span>];</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="built_in">cin</span>>>s;</span><br><span class="line"> <span class="keyword">int</span> cnts=<span class="number">0</span>,cntb=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;s[i];i++){</span><br><span class="line"> <span class="keyword">if</span>(s[i]>=<span class="string">'a'</span>&&s[i]<=<span class="string">'z'</span>)cnts++;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(s[i]>=<span class="string">'A'</span>&&s[i]<=<span class="string">'Z'</span>)cntb++;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(cntb>cnts)strupr(s);</span><br><span class="line"> <span class="keyword">else</span> strlwr(s);</span><br><span class="line"> <span class="built_in">cout</span><<s<<<span class="built_in">endl</span>;</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="B-Anoyer的生日礼物"><a href="#B-Anoyer的生日礼物" class="headerlink" title="B - Anoyer的生日礼物"></a><a href="https://vjudge.net/contest/287051#problem/B" target="_blank" rel="noopener">B - Anoyer的生日礼物</a></h4><blockquote><p>题意:给你一个整数,如果为负数允许你从倒数第一位或者倒数第二位删除一个数字,使值最大</p><p>题解:算出删倒一和倒二的值,对比下大写</p></blockquote><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">char</span> s[<span class="number">20</span>];</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="built_in">cin</span>>>s;</span><br><span class="line"> <span class="keyword">bool</span> flag=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">if</span>(s[<span class="number">0</span>]!=<span class="string">'-'</span>)<span class="built_in">cout</span><<s<<<span class="built_in">endl</span>;</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">int</span> a=atoi(s+<span class="number">1</span>);</span><br><span class="line"> <span class="keyword">int</span> b=a%<span class="number">10</span>+a/<span class="number">100</span>*<span class="number">10</span>,c=a/<span class="number">10</span>;</span><br><span class="line"> <span class="keyword">if</span>(b>c)<span class="built_in">cout</span><<c*<span class="number">-1</span><<<span class="built_in">endl</span>;</span><br><span class="line"> <span class="keyword">else</span> <span class="built_in">cout</span><<b*<span class="number">-1</span><<<span class="built_in">endl</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="C-郑州地铁新干线"><a href="#C-郑州地铁新干线" class="headerlink" title="C - 郑州地铁新干线"></a><a href="https://vjudge.net/contest/287051#problem/C" target="_blank" rel="noopener">C - 郑州地铁新干线</a></h4><blockquote><p>题意:给你一个环,已知环上相邻两点的距离,求a到b的最短路径</p><p>题解:一共就两种路径,从a顺时针或者逆时针。都求出来比大小就可以</p></blockquote><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">int</span> d[<span class="number">120</span>];</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> n;</span><br><span class="line"> <span class="built_in">cin</span>>>n;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<n;i++)<span class="built_in">cin</span>>>d[i];</span><br><span class="line"> <span class="keyword">int</span> a,b,lena=<span class="number">0</span>,lenb=<span class="number">0</span>;</span><br><span class="line"> <span class="built_in">cin</span>>>a>>b;</span><br><span class="line"> <span class="keyword">if</span>(a>b)swap(a,b);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=a<span class="number">-1</span>;;i++){</span><br><span class="line"> <span class="keyword">if</span>(i%n==b<span class="number">-1</span>)<span class="keyword">break</span>;</span><br><span class="line"> lena+=d[i%n];</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=b<span class="number">-1</span>;;i++){</span><br><span class="line"> <span class="keyword">if</span>(i%n==a<span class="number">-1</span>)<span class="keyword">break</span>;</span><br><span class="line"> lenb+=d[i%n];</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">cout</span><<min(lena,lenb)<<<span class="built_in">endl</span>;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="D-区间覆盖"><a href="#D-区间覆盖" class="headerlink" title="D - 区间覆盖"></a><a href="https://vjudge.net/contest/287051#problem/D" target="_blank" rel="noopener">D - 区间覆盖</a></h4><blockquote><p>题意:给你n个线段,问是否有一个的线段能覆盖其他线段,能输出线段位置,不能输出-1</p><p>题解:直接模拟求,如果定义最大区间[mina,maxb],如果发现一个线段包括了这个最大区间,则flag=位置,同时更换区间</p></blockquote><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">1e5</span>+<span class="number">7</span>;</span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">Node</span>{</span></span><br><span class="line"> <span class="keyword">int</span> a,b;</span><br><span class="line">}line[maxn];</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> n,a=<span class="number">0</span>,b=<span class="number">0</span>,mina,maxb,flag=<span class="number">1</span>;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&n);</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d"</span>,&a,&b); <span class="comment">//初始将第一组设成答案</span></span><br><span class="line"> mina=a,maxb=b;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<n;i++){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d"</span>,&a,&b);</span><br><span class="line"> <span class="keyword">if</span>(a<=mina&&b>=maxb){ <span class="comment">//如果能出现覆盖的线,flag记录位置,替换mina和maxb</span></span><br><span class="line"> flag=i+<span class="number">1</span>;</span><br><span class="line"> mina=a,maxb=b;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">if</span>(a<mina){ <span class="comment">//如果出现比mina小的替换mina</span></span><br><span class="line"> flag=<span class="number">-1</span>;</span><br><span class="line"> mina=a;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(b>maxb){ <span class="comment">//如果出现比minb大的替换minb</span></span><br><span class="line"> flag=<span class="number">-1</span>;</span><br><span class="line"> maxb=b;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">cout</span><<flag<<<span class="built_in">endl</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="E-电路阻抗"><a href="#E-电路阻抗" class="headerlink" title="E - 电路阻抗"></a><a href="https://vjudge.net/contest/287051#problem/E" target="_blank" rel="noopener">E - 电路阻抗</a></h4><blockquote><p>题意:给定电阻r0=1,通过并联串联,问最少需要多少个r0能组成a/b</p><p>题解:对a/b进行分解,等于d+c/b,因为d表示串联d个电阻,c/d表示并联了一个b/c的电子原件。对这个原件在进行分解,一直分解到c能整除b</p></blockquote><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> ll a,b,cnt=<span class="number">0</span>;</span><br><span class="line"> <span class="built_in">cin</span>>>a>>b;</span><br><span class="line"> <span class="keyword">while</span>(b){</span><br><span class="line"> cnt+=a/b;</span><br><span class="line"> a=a%b;</span><br><span class="line"> swap(a,b);</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">cout</span><<cnt<<<span class="built_in">endl</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="G-XX输入法的的纠错算法"><a href="#G-XX输入法的的纠错算法" class="headerlink" title="G - XX输入法的的纠错算法"></a><a href="https://vjudge.net/contest/287051#problem/G" target="_blank" rel="noopener">G - XX输入法的的纠错算法</a></h4><blockquote><p>题意:单词需要校对,把错误的改成正确的,错误单词的标准是:<br> 1.有三个连续相同的字母,如www;<br> 2.有多对有两个连续相同的字母,如aamm</p><p>题解:用s2存当前去错后的串,看看压入s1[i]到s2中是否会成为一个错误单词,如果会就continue,否则压入</p></blockquote><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">2e5</span>+<span class="number">7</span>;</span><br><span class="line"><span class="keyword">char</span> s1[maxn],s2[maxn];</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%s"</span>,s1);</span><br><span class="line"> <span class="keyword">int</span> len=<span class="built_in">strlen</span>(s1);</span><br><span class="line"> <span class="keyword">int</span> top=<span class="number">0</span>;</span><br><span class="line"> s2[top++]=s1[<span class="number">0</span>];</span><br><span class="line"> s2[top++]=s1[<span class="number">1</span>];</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">2</span>;i<len;i++){</span><br><span class="line"> <span class="keyword">if</span>(s1[i]==s2[top<span class="number">-1</span>]&&s2[top<span class="number">-1</span>]==s2[top<span class="number">-2</span>])<span class="keyword">continue</span>; <span class="comment">//3个相等</span></span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(s1[i]==s2[top<span class="number">-1</span>]&&s2[top<span class="number">-2</span>]==s2[top<span class="number">-3</span>])<span class="keyword">continue</span>;</span><br><span class="line"> s2[top++]=s1[i];</span><br><span class="line"> }</span><br><span class="line"> s2[top++]=<span class="string">'\0'</span>;</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%s\n"</span>,s2);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="H-简单的构造"><a href="#H-简单的构造" class="headerlink" title="H - 简单的构造"></a><a href="https://vjudge.net/contest/287051#problem/H" target="_blank" rel="noopener">H - 简单的构造</a></h4><blockquote><p>题意:给两个数a和b,可以打乱a每位数的顺序组成一个新的数c,求满足c<=b的最大,保证结果一定存在。</p><p>题解:如果a的长度小于b,则直接输出a升序后的逆序;如果lena==lenb,遍历b,从0号位开始尽可能的让a[i]==b[i],如果发现没有a中已经没有b[i]数字<br>则挑一个比b[i]小的最大的数(如果发现找不到小的就返回去查),放进去。然后剩余的数字就可以从大到小放</p></blockquote><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="built_in">string</span> a,b,c;</span><br><span class="line"><span class="keyword">int</span> numa[<span class="number">10</span>];</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="built_in">cin</span>>>a>>b;</span><br><span class="line"> <span class="keyword">int</span> lena=a.size(),lenb=b.size();</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<lena;i++){</span><br><span class="line"> numa[a[i]-<span class="string">'0'</span>]++;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(lena<lenb){</span><br><span class="line"> sort(a.begin(),a.end());</span><br><span class="line"> reverse(a.begin(),a.end());</span><br><span class="line"> <span class="built_in">cout</span><<a<<<span class="built_in">endl</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> c=<span class="string">""</span>;</span><br><span class="line"> <span class="keyword">bool</span> flag=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<lenb;i++){</span><br><span class="line"> <span class="keyword">if</span>(numa[b[i]-<span class="string">'0'</span>]){</span><br><span class="line"> c+=b[i];</span><br><span class="line"> numa[b[i]-<span class="string">'0'</span>]--;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">bool</span> th=<span class="number">1</span>; <span class="comment">//标记是否替换</span></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=b[i]-<span class="string">'0'</span>;j>=<span class="number">0</span>;j--){</span><br><span class="line"> <span class="keyword">if</span>(numa[j]){</span><br><span class="line"> c+=j+<span class="string">'0'</span>;</span><br><span class="line"> numa[j]--;</span><br><span class="line"> flag=<span class="number">1</span>;</span><br><span class="line"> th=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">while</span>(th){ <span class="comment">//没有替换前面一位换个小的</span></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=b[i<span class="number">-1</span>]-<span class="string">'0'</span><span class="number">-1</span>;j>=<span class="number">0</span>;j--){</span><br><span class="line"> <span class="keyword">if</span>(numa[j]){</span><br><span class="line"> c[i<span class="number">-1</span>]=j+<span class="string">'0'</span>;</span><br><span class="line"> numa[j]--;</span><br><span class="line"> numa[b[i<span class="number">-1</span>]-<span class="string">'0'</span>]++;</span><br><span class="line"> flag=<span class="number">1</span>;</span><br><span class="line"> th=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(th){</span><br><span class="line"> c.erase(c.end() - <span class="number">1</span>); <span class="comment">//删除最后一个字符</span></span><br><span class="line"> numa[b[i<span class="number">-1</span>]-<span class="string">'0'</span>]++;</span><br><span class="line"> i-=<span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(flag)<span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">cout</span><<c;</span><br><span class="line"> <span class="keyword">if</span>(flag){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">9</span>;i>=<span class="number">0</span>;i--){</span><br><span class="line"> <span class="keyword">while</span>(numa[i]--){</span><br><span class="line"> <span class="built_in">cout</span><<i;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">cout</span><<<span class="built_in">endl</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h4 id="A-打理机房"><a href="#A-打理机房" class="headerlink" title="A - 打理机房"></a><a href="https://vjudge.net/contest/287051#problem/A" target="_bla
</summary>
<category term="题解" scheme="https://anoyer.cn/categories/%E9%A2%98%E8%A7%A3/"/>
<category term="河南农业大学训练赛题解" scheme="https://anoyer.cn/tags/%E6%B2%B3%E5%8D%97%E5%86%9C%E4%B8%9A%E5%A4%A7%E5%AD%A6%E8%AE%AD%E7%BB%83%E8%B5%9B%E9%A2%98%E8%A7%A3/"/>
</entry>
<entry>
<title>ZZULI-2019年3月份月赛(个人赛)EF题解</title>
<link href="https://anoyer.cn/article/zzuli-302.html"/>
<id>https://anoyer.cn/article/zzuli-302.html</id>
<published>2019-03-03T11:36:14.000Z</published>
<updated>2019-03-03T11:59:06.172Z</updated>
<content type="html"><![CDATA[<h4 id="问题-E-小P的字母子串"><a href="#问题-E-小P的字母子串" class="headerlink" title="问题 E: 小P的字母子串"></a><a href="http://acm.zzuli.edu.cn/problem.php?cid=1361&pid=4" target="_blank" rel="noopener">问题 E: 小P的字母子串</a></h4><blockquote><p>题意:给一段01串从任意位置进行截取,问最多能截取出多少个7位串对应字母的ASCLL值</p><p>题解:利用map将所有字母的7位ASCALL值存起来,然后对字符串进行暴力7位一截取。看看截取出来的串是否是字母的ASCALL值,如果是则位置i+6(因为有for里i++,会再加1),ans++。</p><font color="Blue" size="5" face="宋体">对于字母的ASCALL,可以写个10进制转2进制程序跑一遍,输出到文件。或者手动转化’a’,’A’的二进制然后往后推25</font></blockquote><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ll long long int</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> max_n 10050 <span class="comment">//串长度</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> max_tot 100050 <span class="comment">//节点数</span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> met(a) memset(a,0,sizeof(a))</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> fup(i,a,n,b) for(int i=a;i<n;i+=b)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> fow(j,a,n,b) for(int j=a;j>0;j-=b)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> MOD(x) (x)%mod</span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn = <span class="number">1e4</span> + <span class="number">7</span>;</span><br><span class="line"><span class="built_in">string</span> s;</span><br><span class="line"><span class="built_in">string</span> zm[<span class="number">60</span>]={<span class="string">"1000001"</span>,<span class="string">"1000010"</span>,<span class="string">"1000011"</span>,<span class="string">"1000100"</span>,<span class="string">"1000101"</span>,<span class="string">"1000110"</span>,<span class="string">"1000111"</span>,<span class="string">"1001000"</span>,<span class="string">"1001001"</span>,<span class="string">"1001010"</span>,<span class="string">"1001011"</span>,<span class="string">"1001100"</span>,<span class="string">"1001101"</span>,<span class="string">"1001110"</span>,<span class="string">"1001111"</span>,<span class="string">"1010000"</span>,<span class="string">"1010001"</span>,<span class="string">"1010010"</span>,<span class="string">"1010011"</span>,<span class="string">"1010100"</span>,<span class="string">"1010101"</span>,<span class="string">"1010110"</span>,<span class="string">"1010111"</span>,<span class="string">"1011000"</span>,<span class="string">"1011001"</span>,<span class="string">"1011010"</span>,<span class="string">"1100001"</span>,<span class="string">"1100010"</span>,<span class="string">"1100011"</span>,<span class="string">"1100100"</span>,<span class="string">"1100101"</span>,<span class="string">"1100110"</span>,<span class="string">"1100111"</span>,<span class="string">"1101000"</span>,<span class="string">"1101001"</span>,<span class="string">"1101010"</span>,<span class="string">"1101011"</span>,<span class="string">"1101100"</span>,<span class="string">"1101101"</span>,<span class="string">"1101110"</span>,<span class="string">"1101111"</span>,<span class="string">"1110000"</span>,<span class="string">"1110001"</span>,<span class="string">"1110010"</span>,<span class="string">"1110011"</span>,<span class="string">"1110100"</span>,<span class="string">"1110101"</span>,<span class="string">"1110110"</span>,<span class="string">"1110111"</span>,<span class="string">"1111000"</span>,<span class="string">"1111001"</span>,<span class="string">"1111010"</span>};</span><br><span class="line"><span class="built_in">map</span><<span class="built_in">string</span>,<span class="keyword">int</span>>mp;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">(<span class="keyword">int</span> argc, <span class="keyword">char</span> *argv[])</span> </span>{</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<<span class="number">52</span>;i++){</span><br><span class="line"> mp[zm[i]]=<span class="number">1</span>;<span class="comment">//把所有字母的ASCALL值扔进map</span></span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">while</span>(<span class="built_in">cin</span>>>s){</span><br><span class="line"> <span class="keyword">int</span> ans=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">int</span> len=s.size();</span><br><span class="line"> <span class="built_in">string</span> sub;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i+<span class="number">6</span><len;i++){</span><br><span class="line"> <span class="keyword">if</span>(s[i]==<span class="number">0</span>)<span class="keyword">continue</span>;</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> sub=s.substr(i,<span class="number">7</span>);<span class="comment">//截取7位子串</span></span><br><span class="line"> <span class="keyword">if</span>(mp[sub])ans++,i+=<span class="number">6</span>;<span class="comment">//判断是不是个字母</span></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">cout</span><<ans<<<span class="built_in">endl</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">//cout<<s<<endl;</span></span><br><span class="line"> </span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h4 id="问题-F-小P的秘籍"><a href="#问题-F-小P的秘籍" class="headerlink" title="问题 F: 小P的秘籍"></a><a href="http://acm.zzuli.edu.cn/problem.php?cid=1361&pid=5" target="_blank" rel="noopener">问题 F: 小P的秘籍</a></h4><blockquote><p>题意:给一个长度为n的AK串,求一个长度为len的子串满足该子串的所有前缀和后缀中K的数量不小于A,求最大len</p><p>题解:数据水了,用的尺取法。题目要求从前往后和从后往前都要满足K的数量大于等于A的数量。先用尺取法来确定从前往后满足的区间,然后内部从后往前判断是否成立,成立了就更新答案</p></blockquote><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"> </span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"> </span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> n;</span><br><span class="line"> <span class="built_in">cin</span>>>n;</span><br><span class="line"> <span class="built_in">string</span> str;</span><br><span class="line"> <span class="built_in">cin</span>>>str;</span><br><span class="line"> <span class="keyword">int</span> i=<span class="number">0</span>,j=<span class="number">0</span>;<span class="comment">//[i,j]</span></span><br><span class="line"> <span class="keyword">int</span> a=<span class="number">0</span>,k=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">int</span> ans=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">while</span>(<span class="number">1</span>){</span><br><span class="line"> <span class="keyword">while</span>(j<str.size()&&k>=a){</span><br><span class="line"> <span class="keyword">if</span>(str[j]==<span class="string">'A'</span>)a++;</span><br><span class="line"> <span class="keyword">if</span>(str[j]==<span class="string">'K'</span>)k++;</span><br><span class="line"> j++;</span><br><span class="line"> <span class="keyword">if</span>(k>=a){</span><br><span class="line"> <span class="keyword">int</span> cnt=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> r=j<span class="number">-1</span>;r>=i;r--){</span><br><span class="line"> <span class="keyword">if</span>(str[r]==<span class="string">'A'</span>)cnt--;</span><br><span class="line"> <span class="keyword">if</span>(str[r]==<span class="string">'K'</span>)cnt++;</span><br><span class="line"> <span class="keyword">if</span>(cnt<<span class="number">0</span>)<span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(cnt>=<span class="number">0</span>)ans=max(ans,j-i);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(k>=a)<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">while</span>(i<j && k<a){</span><br><span class="line"> <span class="keyword">if</span>(str[i]==<span class="string">'A'</span>)a--;</span><br><span class="line"> <span class="keyword">if</span>(str[i]==<span class="string">'K'</span>)k--;</span><br><span class="line"> i++;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">cout</span><<ans<<<span class="built_in">endl</span>;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h4 id="问题-E-小P的字母子串"><a href="#问题-E-小P的字母子串" class="headerlink" title="问题 E: 小P的字母子串"></a><a href="http://acm.zzuli.edu.cn/problem.php?cid=
</summary>
<category term="题解" scheme="https://anoyer.cn/categories/%E9%A2%98%E8%A7%A3/"/>
<category term="河南农业大学训练赛题解" scheme="https://anoyer.cn/tags/%E6%B2%B3%E5%8D%97%E5%86%9C%E4%B8%9A%E5%A4%A7%E5%AD%A6%E8%AE%AD%E7%BB%83%E8%B5%9B%E9%A2%98%E8%A7%A3/"/>
</entry>
<entry>
<title>UVA - 11624 - Fire!(BFS逃生问题)</title>
<link href="https://anoyer.cn/article/UVA-11624-Fire.html"/>
<id>https://anoyer.cn/article/UVA-11624-Fire.html</id>
<published>2019-02-25T09:40:34.000Z</published>
<updated>2019-02-25T09:50:13.223Z</updated>
<content type="html"><![CDATA[<h4 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="https://vjudge.net/problem/28833/origin" target="_blank" rel="noopener">题目链接</a></h4><h4 id="题意:"><a href="#题意:" class="headerlink" title="题意:"></a>题意:</h4><blockquote><p>在迷宫内,J表示人,F表示火,火可能不止一处,但是人只有一个,火会向上下左右蔓延,<br>蔓延速度和人移动速度一至(每次一格,但是可以同时向四个方向)问是否可以成功逃出迷宫,<br>不能输出IMPOSSIBLE,能的画话输出最短路径。</p></blockquote><h4 id="题解:"><a href="#题解:" class="headerlink" title="题解:"></a>题解:</h4><blockquote><p>每步先让火走–然后人走其他的路–就可以保证人不会被火烧了<br>先将火入队列最后将人入队列,走的时候判断下是人还是火,如果是人的话看看是否无路可走<br>注:也可以跑两次BFS,先跑火,再跑人,看人到当前格时间是否小于火的</p></blockquote><h4 id="AC代码:"><a href="#AC代码:" class="headerlink" title="AC代码:"></a>AC代码:</h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><cstdio></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><queue></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><cstring></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><algorithm></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">char</span> ma[<span class="number">1010</span>][<span class="number">1010</span>];</span><br><span class="line"><span class="keyword">int</span> n,m,rx,ry,fx,fy;</span><br><span class="line"><span class="keyword">int</span> xx[<span class="number">4</span>]={<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">-1</span>};</span><br><span class="line"><span class="keyword">int</span> yy[<span class="number">4</span>]={<span class="number">1</span>,<span class="number">-1</span>,<span class="number">0</span>,<span class="number">0</span>};</span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">node</span>{</span></span><br><span class="line"><span class="keyword">int</span> x,y,step;</span><br><span class="line"><span class="keyword">bool</span> fafe;</span><br><span class="line">}now,qian,ff;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">bfs</span><span class="params">()</span></span>{</span><br><span class="line"><span class="built_in">queue</span> <node> que;</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i=<span class="number">0</span>;i<n;i++)</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> j=<span class="number">0</span>;j<m;j++){</span><br><span class="line"><span class="keyword">if</span> (ma[i][j]==<span class="string">'F'</span>){</span><br><span class="line">now.x=i;now.y=j;now.step=<span class="number">0</span>;</span><br><span class="line">now.fafe=<span class="literal">true</span>;</span><br><span class="line">que.push(now);</span><br><span class="line">ma[i][j]=<span class="string">'#'</span>;</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line">now.x=rx;now.y=ry;now.step=<span class="number">0</span>;now.fafe=<span class="literal">false</span>;</span><br><span class="line">que.push(now);</span><br><span class="line"><span class="keyword">while</span> (!que.empty()){</span><br><span class="line">now=que.front();</span><br><span class="line">que.pop();</span><br><span class="line"><span class="keyword">if</span> (now.fafe){</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i=<span class="number">0</span>;i<<span class="number">4</span>;i++){</span><br><span class="line"><span class="keyword">int</span> kx=now.x+xx[i];</span><br><span class="line"><span class="keyword">int</span> ky=now.y+yy[i];</span><br><span class="line"><span class="keyword">if</span> (kx<<span class="number">0</span>||ky<<span class="number">0</span>||kx==n||ky==m||ma[kx][ky]==<span class="string">'#'</span>) <span class="keyword">continue</span>;</span><br><span class="line">{</span><br><span class="line">ma[kx][ky]=<span class="string">'#'</span>;</span><br><span class="line">qian.x=kx;qian.y=ky;</span><br><span class="line">qian.step=now.step+<span class="number">1</span>;</span><br><span class="line">qian.fafe=<span class="literal">true</span>;</span><br><span class="line">que.push(qian);</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"><span class="keyword">else</span>{</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i=<span class="number">0</span>;i<<span class="number">4</span>;i++){</span><br><span class="line"><span class="keyword">int</span> kx=now.x+xx[i];</span><br><span class="line"><span class="keyword">int</span> ky=now.y+yy[i];</span><br><span class="line"><span class="keyword">if</span> (kx<<span class="number">0</span>||ky<<span class="number">0</span>||kx==n||ky==m){</span><br><span class="line"><span class="keyword">return</span> now.step+<span class="number">1</span>;</span><br><span class="line">}</span><br><span class="line"><span class="keyword">if</span> (ma[kx][ky]!=<span class="string">'#'</span>){</span><br><span class="line">ma[kx][ky]=<span class="string">'#'</span>;</span><br><span class="line">qian.x=kx;qian.y=ky;</span><br><span class="line">qian.step=now.step+<span class="number">1</span>;</span><br><span class="line">qian.fafe=<span class="literal">false</span>;</span><br><span class="line">que.push(qian);</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"><span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"><span class="keyword">int</span> t;<span class="built_in">scanf</span>(<span class="string">"%d"</span>,&t);</span><br><span class="line"><span class="keyword">while</span> (t--){</span><br><span class="line"><span class="built_in">scanf</span>(<span class="string">"%d%d"</span>,&n,&m);</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i=<span class="number">0</span>;i<n;i++){</span><br><span class="line"><span class="built_in">scanf</span>(<span class="string">"%s"</span>,ma[i]);</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> j=<span class="number">0</span>;j<m;j++){</span><br><span class="line"><span class="keyword">if</span> (ma[i][j]==<span class="string">'J'</span>){</span><br><span class="line">rx=i;ry=j;</span><br><span class="line">ma[i][j]=<span class="string">'#'</span>;</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"><span class="keyword">int</span> ans=bfs();</span><br><span class="line"><span class="keyword">if</span> (ans)</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"%d\n"</span>,ans);</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"IMPOSSIBLE\n"</span>);</span><br><span class="line">}</span><br><span class="line"><span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h4 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="https://vjudge.net/problem/28833/origin" target="_blank" rel="noo
</summary>
<category term="题解" scheme="https://anoyer.cn/categories/%E9%A2%98%E8%A7%A3/"/>
<category term="BFS" scheme="https://anoyer.cn/tags/BFS/"/>
<category term="UVA" scheme="https://anoyer.cn/tags/UVA/"/>
</entry>
<entry>
<title>POJ - 3984 - 迷宫问题(路径记录)</title>
<link href="https://anoyer.cn/article/POJ-3984.html"/>
<id>https://anoyer.cn/article/POJ-3984.html</id>
<published>2019-02-25T09:36:16.000Z</published>
<updated>2019-02-25T09:49:54.260Z</updated>
<content type="html"><![CDATA[<h4 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://poj.org/problem?id=3984" target="_blank" rel="noopener">题目链接</a></h4><h4 id="题意:"><a href="#题意:" class="headerlink" title="题意:"></a>题意:</h4><blockquote><p>给你一个5*5的迷宫,0代表通路,1代表墙,找到从迷宫左上角到达右下角的最短路径,并输出路径。</p></blockquote><h4 id="题解:"><a href="#题解:" class="headerlink" title="题解:"></a>题解:</h4><blockquote><p>先进行一遍BFS,得到vis数组,表示到该位置最少需要多少时间,然后从(4,4)位置倒着查路径,<br>查到符合的就直接break,防止重复</p></blockquote><h4 id="AC代码:"><a href="#AC代码:" class="headerlink" title="AC代码:"></a>AC代码:</h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><string.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><algorithm></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><iostream></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><queue></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stack></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">7</span>;</span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">node</span>{</span></span><br><span class="line"> <span class="keyword">int</span> x,y;</span><br><span class="line"> node(<span class="keyword">int</span> i=<span class="number">0</span>,<span class="keyword">int</span> j=<span class="number">0</span>){x=i,y=j;};</span><br><span class="line">};</span><br><span class="line"><span class="keyword">int</span> mp[maxn][maxn];</span><br><span class="line"><span class="keyword">int</span> vis[maxn][maxn];</span><br><span class="line"><span class="keyword">int</span> dis[<span class="number">4</span>][<span class="number">2</span>]={<span class="number">1</span>,<span class="number">0</span>,<span class="number">-1</span>,<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>,<span class="number">-1</span>};</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">bfs</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="built_in">queue</span><node>dq;</span><br><span class="line"> node now(0,0),nex;</span><br><span class="line"> dq.push(now);</span><br><span class="line"> vis[<span class="number">0</span>][<span class="number">0</span>]=<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">while</span>(!dq.empty()){</span><br><span class="line"> now=dq.front();</span><br><span class="line"> dq.pop();</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<<span class="number">4</span>;i++){</span><br><span class="line"> nex.x=now.x+dis[i][<span class="number">0</span>];</span><br><span class="line"> nex.y=now.y+dis[i][<span class="number">1</span>];</span><br><span class="line"> <span class="keyword">if</span>(nex.x>=<span class="number">0</span>&&nex.x<<span class="number">5</span>&&nex.y>=<span class="number">0</span>&&nex.y<<span class="number">5</span>&&mp[nex.x][nex.y]==<span class="number">0</span>&&vis[nex.x][nex.y]==<span class="number">0</span>){</span><br><span class="line"> dq.push(nex);</span><br><span class="line"> vis[nex.x][nex.y]=vis[now.x][now.y]+<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(nex.x==<span class="number">4</span>&&nex.y==<span class="number">4</span>)<span class="keyword">return</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="built_in">stack</span><node>ds;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<<span class="number">5</span>;i++)</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j<<span class="number">5</span>;j++)<span class="built_in">scanf</span>(<span class="string">"%d"</span>,&mp[i][j]);</span><br><span class="line"> bfs();</span><br><span class="line"> node nw(4,4),ne;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> ans=vis[<span class="number">4</span>][<span class="number">4</span>];</span><br><span class="line"> ds.push(nw);</span><br><span class="line"> <span class="keyword">while</span>(<span class="literal">true</span>){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<<span class="number">5</span>;i++){</span><br><span class="line"> ne.x=nw.x+dis[i][<span class="number">0</span>];</span><br><span class="line"> ne.y=nw.y+dis[i][<span class="number">1</span>];</span><br><span class="line"> <span class="keyword">if</span>(ne.x>=<span class="number">0</span>&&ne.x<<span class="number">5</span>&&ne.y>=<span class="number">0</span>&&ne.y<<span class="number">5</span>&&vis[ne.x][ne.y]==ans<span class="number">-1</span>){</span><br><span class="line"> nw=ne;</span><br><span class="line"> ans=ans<span class="number">-1</span>;</span><br><span class="line"> ds.push(nw);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(nw.x==<span class="number">0</span>&&nw.y==<span class="number">0</span>)<span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">while</span>(!ds.empty()){</span><br><span class="line"> nw=ds.top();</span><br><span class="line"> ds.pop();</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"(%d, %d)\n"</span>,nw.x,nw.y);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h4 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://poj.org/problem?id=3984" target="_blank" rel="noopener">题目
</summary>
<category term="题解" scheme="https://anoyer.cn/categories/%E9%A2%98%E8%A7%A3/"/>
<category term="BFS" scheme="https://anoyer.cn/tags/BFS/"/>
<category term="POJ" scheme="https://anoyer.cn/tags/POJ/"/>
</entry>
<entry>
<title>POJ - 3278 - Catch That Cow(裸BFS)</title>
<link href="https://anoyer.cn/article/POJ-3278-Catch-That-Cow.html"/>
<id>https://anoyer.cn/article/POJ-3278-Catch-That-Cow.html</id>
<published>2019-02-25T09:29:05.000Z</published>
<updated>2019-02-25T09:35:30.552Z</updated>
<content type="html"><![CDATA[<h4 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://poj.org/problem?id=3278" target="_blank" rel="noopener">题目链接</a></h4><h4 id="题意:"><a href="#题意:" class="headerlink" title="题意:"></a>题意:</h4><blockquote><p>给定两个整数n和k,通过 n+1或n-1 或n*2 这3种操作,使得n==k,输出最少的操作次数</p></blockquote><h4 id="题解:"><a href="#题解:" class="headerlink" title="题解:"></a>题解:</h4><blockquote><p>简单的对每个节点进行三个方向(三种走法)的BFS</p></blockquote><h4 id="AC代码:"><a href="#AC代码:" class="headerlink" title="AC代码:"></a>AC代码:</h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><string.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><queue></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><algorithm></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">100005</span>;</span><br><span class="line"><span class="keyword">int</span> vis[maxn];</span><br><span class="line"><span class="keyword">int</span> n,k;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">bfs</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="built_in">queue</span><<span class="keyword">int</span>>dq;</span><br><span class="line"> dq.push(n);</span><br><span class="line"> vis[n]=<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">while</span>(!dq.empty()){</span><br><span class="line"> <span class="keyword">int</span> x=dq.front();</span><br><span class="line"> dq.pop();</span><br><span class="line"> <span class="keyword">if</span>(x+<span class="number">1</span>>=<span class="number">0</span>&&x+<span class="number">1</span><maxn&&vis[x+<span class="number">1</span>]==<span class="number">0</span>){</span><br><span class="line"> dq.push(x+<span class="number">1</span>);</span><br><span class="line"> vis[x+<span class="number">1</span>]=vis[x]+<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(x+<span class="number">1</span>==k)<span class="keyword">return</span> vis[x+<span class="number">1</span>];</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(x<span class="number">-1</span>>=<span class="number">0</span>&&x<span class="number">-1</span><maxn&&vis[x<span class="number">-1</span>]==<span class="number">0</span>){</span><br><span class="line"> dq.push(x<span class="number">-1</span>);</span><br><span class="line"> vis[x<span class="number">-1</span>]=vis[x]+<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(x<span class="number">-1</span>==k)<span class="keyword">return</span> vis[x<span class="number">-1</span>];</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(<span class="number">2</span>*x>=<span class="number">0</span>&&<span class="number">2</span>*x<maxn&&vis[<span class="number">2</span>*x]==<span class="number">0</span>){</span><br><span class="line"> dq.push(<span class="number">2</span>*x);</span><br><span class="line"> vis[<span class="number">2</span>*x]=vis[x]+<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(<span class="number">2</span>*x==k)<span class="keyword">return</span> vis[<span class="number">2</span>*x];</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d"</span>,&n,&k);</span><br><span class="line"> <span class="keyword">if</span>(n>=k){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d\n"</span>,n-k);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">int</span> ans=bfs();</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d\n"</span>,ans<span class="number">-1</span>);</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h4 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://poj.org/problem?id=3278" target="_blank" rel="noopener">题目
</summary>
<category term="题解" scheme="https://anoyer.cn/categories/%E9%A2%98%E8%A7%A3/"/>
<category term="BFS" scheme="https://anoyer.cn/tags/BFS/"/>
<category term="POJ" scheme="https://anoyer.cn/tags/POJ/"/>
</entry>
<entry>
<title>POJ - 3126 - Prime Path(BFS枚举)</title>
<link href="https://anoyer.cn/article/POJ-3126-Prime-Path.html"/>
<id>https://anoyer.cn/article/POJ-3126-Prime-Path.html</id>
<published>2019-02-25T09:24:31.000Z</published>
<updated>2019-02-25T09:28:46.369Z</updated>
<content type="html"><![CDATA[<h3 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://poj.org/problem?id=3126" target="_blank" rel="noopener">题目链接</a></h3><h4 id="题意:"><a href="#题意:" class="headerlink" title="题意:"></a>题意:</h4><blockquote><p>给出两个四位数的素数a,b,求从a变到b最少要花几步?每一步只能将a中的一位改变,且改变后的数也要是素数。</p></blockquote><h4 id="题解:"><a href="#题解:" class="headerlink" title="题解:"></a>题解:</h4><blockquote><p>BFS枚举个位,十位,百位,千位变换的数,用素数表判断变换后是否为一个素数</p></blockquote><h4 id="AC代码:"><a href="#AC代码:" class="headerlink" title="AC代码:"></a>AC代码:</h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><string.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><queue></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><algorithm></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">1e4</span>+<span class="number">5</span>;</span><br><span class="line"><span class="keyword">bool</span> prime[maxn];</span><br><span class="line"><span class="keyword">int</span> vis[maxn];</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Prime</span><span class="params">()</span></span>{</span><br><span class="line"> prime[<span class="number">0</span>]=prime[<span class="number">1</span>]=<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">2</span>;i<maxn;i++){</span><br><span class="line"> <span class="keyword">if</span>(!prime[i])</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">2</span>;j*i<maxn;j++)prime[i*j]=<span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="keyword">int</span> n,m;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">bfs</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> ans=<span class="number">0</span>;</span><br><span class="line"> <span class="built_in">queue</span><<span class="keyword">int</span>>dq;</span><br><span class="line"> dq.push(n);</span><br><span class="line"> vis[n]=<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(n==m)<span class="keyword">return</span> vis[n];</span><br><span class="line"> <span class="keyword">while</span>(!dq.empty()){</span><br><span class="line"> <span class="keyword">int</span> x=dq.front();</span><br><span class="line"> dq.pop();</span><br><span class="line"> <span class="keyword">if</span>(x==m)<span class="keyword">return</span> vis[x];</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<<span class="number">10</span>;i+=<span class="number">2</span>){ <span class="comment">//个位</span></span><br><span class="line"> <span class="keyword">int</span> xx=x-x%<span class="number">10</span>+i;</span><br><span class="line"> <span class="keyword">if</span>(!prime[xx]&&vis[xx]==<span class="number">0</span>){</span><br><span class="line"> dq.push(xx);</span><br><span class="line"> vis[xx]=vis[x]+<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(xx==m)<span class="keyword">return</span> vis[xx];</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<<span class="number">10</span>;i++){ <span class="comment">//十位</span></span><br><span class="line"> <span class="keyword">int</span> xx=x-(x%<span class="number">100</span>-x%<span class="number">10</span>)+i*<span class="number">10</span>;</span><br><span class="line"> <span class="keyword">if</span>(!prime[xx]&&vis[xx]==<span class="number">0</span>){</span><br><span class="line"> dq.push(xx);</span><br><span class="line"> vis[xx]=vis[x]+<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(xx==m)<span class="keyword">return</span> vis[xx];</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<<span class="number">10</span>;i++){ <span class="comment">//百位</span></span><br><span class="line"> <span class="keyword">int</span> xx=x-(x%<span class="number">1000</span>-x%<span class="number">100</span>)+i*<span class="number">100</span>;</span><br><span class="line"> <span class="keyword">if</span>(!prime[xx]&&vis[xx]==<span class="number">0</span>){</span><br><span class="line"> dq.push(xx);</span><br><span class="line"> vis[xx]=vis[x]+<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(xx==m)<span class="keyword">return</span> vis[xx];</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<<span class="number">10</span>;i++){ <span class="comment">//千位</span></span><br><span class="line"> <span class="keyword">int</span> xx=x-(x%<span class="number">10000</span>-x%<span class="number">1000</span>)+i*<span class="number">1000</span>;</span><br><span class="line"> <span class="keyword">if</span>(!prime[xx]&&vis[xx]==<span class="number">0</span>){</span><br><span class="line"> dq.push(xx);</span><br><span class="line"> vis[xx]=vis[x]+<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(xx==m)<span class="keyword">return</span> vis[xx];</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> Prime();</span><br><span class="line"> <span class="keyword">int</span> t;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&t);</span><br><span class="line"> <span class="keyword">while</span>(t--){</span><br><span class="line"> <span class="built_in">memset</span>(vis,<span class="number">0</span>,<span class="keyword">sizeof</span>(vis));</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d"</span>,&n,&m);</span><br><span class="line"> <span class="keyword">int</span> ans=bfs();</span><br><span class="line"> <span class="keyword">if</span>(ans==<span class="number">-1</span>)<span class="built_in">printf</span>(<span class="string">"Impossible\n"</span>);</span><br><span class="line"> <span class="keyword">else</span> <span class="built_in">printf</span>(<span class="string">"%d\n"</span>,ans<span class="number">-1</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h3 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://poj.org/problem?id=3126" target="_blank" rel="noopener">题目
</summary>
<category term="题解" scheme="https://anoyer.cn/categories/%E9%A2%98%E8%A7%A3/"/>
<category term="BFS" scheme="https://anoyer.cn/tags/BFS/"/>
<category term="POJ" scheme="https://anoyer.cn/tags/POJ/"/>
</entry>
<entry>
<title>POJ - 3087 - Shuffle'm Up(模拟)</title>
<link href="https://anoyer.cn/article/POJ-3087-Shuffle-m-Up.html"/>
<id>https://anoyer.cn/article/POJ-3087-Shuffle-m-Up.html</id>
<published>2019-02-25T09:18:44.000Z</published>
<updated>2019-02-25T09:49:13.488Z</updated>
<content type="html"><![CDATA[<h3 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://poj.org/problem?id=3087" target="_blank" rel="noopener">题目链接</a></h3><h4 id="题意:"><a href="#题意:" class="headerlink" title="题意:"></a>题意:</h4><blockquote><p>已知两堆牌s1和s2的初始状态, 其牌数均为c,按给定规则能将他们相互交叉组合成一堆牌s12,<br>再将s12的最底下的c块牌归为s1,最顶的c块牌归为s2,依此循环下去。<br>现在输入s1和s2的初始状态 以及 预想的最终状态s12</p><p>问s1 s2经过多少次洗牌之后,最终能达到状态s12,若永远不可能相同,则输出”-1”。</p></blockquote><h4 id="题解:"><a href="#题解:" class="headerlink" title="题解:"></a>题解:</h4><blockquote><p>虽然归类于kuangbin搜索专题,但个人感觉模拟更好做,直接用map判重,进行模拟就可以。<br>如果出现了一个出现过的非目标串,则输出-1,因为此时操作是一个环无法到达目标串</p></blockquote><h4 id="AC代码:"><a href="#AC代码:" class="headerlink" title="AC代码:"></a>AC代码:</h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><string.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><algorithm></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><map></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><iostream></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">120</span>;</span><br><span class="line"><span class="built_in">string</span> s1,s2,s,s12;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> t,n,tt=<span class="number">1</span>;</span><br><span class="line"> <span class="built_in">cin</span>>>t;</span><br><span class="line"> <span class="keyword">while</span>(tt<=t){</span><br><span class="line"> <span class="built_in">cin</span>>>n;</span><br><span class="line"> <span class="built_in">cin</span>>>s1>>s2>>s;</span><br><span class="line"> <span class="built_in">map</span><<span class="built_in">string</span>,<span class="keyword">bool</span>>vis;</span><br><span class="line"> vis[s]=<span class="number">1</span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> cnt=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">while</span>(<span class="number">1</span>){</span><br><span class="line"> s12=<span class="string">""</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<n;i++){</span><br><span class="line"> s12+=s2[i];</span><br><span class="line"> s12+=s1[i];</span><br><span class="line"> }</span><br><span class="line"> s12+=<span class="string">"\0"</span>;</span><br><span class="line"> cnt++;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span>(s12==s){</span><br><span class="line"> <span class="built_in">cout</span><<tt<<<span class="string">" "</span><<cnt<<<span class="built_in">endl</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(vis[s12]){</span><br><span class="line"> <span class="built_in">cout</span><<tt<<<span class="string">" "</span><<<span class="number">-1</span><<<span class="built_in">endl</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> vis[s12]=<span class="number">1</span>;</span><br><span class="line"> s1=<span class="string">""</span>;</span><br><span class="line"> s2=<span class="string">""</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<n;i++){</span><br><span class="line"> s1+=s12[i];</span><br><span class="line"> s2+=s12[i+n];</span><br><span class="line"> }</span><br><span class="line"> s1+=<span class="string">"\0"</span>;</span><br><span class="line"> s2+=<span class="string">"\0"</span>;</span><br><span class="line"> }</span><br><span class="line"> tt++;</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h3 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://poj.org/problem?id=3087" target="_blank" rel="noopener">题目
</summary>
<category term="题解" scheme="https://anoyer.cn/categories/%E9%A2%98%E8%A7%A3/"/>
<category term="POJ" scheme="https://anoyer.cn/tags/POJ/"/>
<category term="模拟题" scheme="https://anoyer.cn/tags/%E6%A8%A1%E6%8B%9F%E9%A2%98/"/>
</entry>
<entry>
<title>POJ - 2251 - Dungeon Master(分层BFS)</title>
<link href="https://anoyer.cn/article/POJ-2251-Dungeon-Master.html"/>
<id>https://anoyer.cn/article/POJ-2251-Dungeon-Master.html</id>
<published>2019-02-25T09:14:37.000Z</published>
<updated>2019-02-25T09:18:18.668Z</updated>
<content type="html"><![CDATA[<h3 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://poj.org/problem?id=2251" target="_blank" rel="noopener">题目链接</a></h3><h4 id="题意:"><a href="#题意:" class="headerlink" title="题意:"></a>题意:</h4><blockquote><p>给一个三维图,可以前后左右上下6种走法,走一步1分钟,求最少时间(其实就是最短路)</p></blockquote><h4 id="题解:"><a href="#题解:" class="headerlink" title="题解:"></a>题解:</h4><blockquote><p>最短路Bfs,和二维的基本一样,就是原来4个方向,现在6个方向,原来数组是二维,现在是三维,也相当于模板题了。</p></blockquote><h4 id="AC代码:"><a href="#AC代码:" class="headerlink" title="AC代码:"></a>AC代码:</h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><cstring></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><queue></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><algorithm></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">50</span>;</span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">node</span>{</span></span><br><span class="line"> <span class="keyword">int</span> x,y,z;</span><br><span class="line"> node(<span class="keyword">int</span> xx=<span class="number">0</span>,<span class="keyword">int</span> yy=<span class="number">0</span>,<span class="keyword">int</span> zz=<span class="number">0</span>){x=xx,y=yy,z=zz;};</span><br><span class="line">};</span><br><span class="line"><span class="keyword">char</span> mp[maxn][maxn][maxn];</span><br><span class="line"><span class="keyword">int</span> vis[maxn][maxn][maxn];</span><br><span class="line"><span class="keyword">int</span> mov[<span class="number">6</span>][<span class="number">3</span>]={{<span class="number">1</span>,<span class="number">0</span>,<span class="number">0</span>},{<span class="number">-1</span>,<span class="number">0</span>,<span class="number">0</span>},{<span class="number">0</span>,<span class="number">1</span>,<span class="number">0</span>},{<span class="number">0</span>,<span class="number">-1</span>,<span class="number">0</span>},{<span class="number">0</span>,<span class="number">0</span>,<span class="number">1</span>},{<span class="number">0</span>,<span class="number">0</span>,<span class="number">-1</span>}};</span><br><span class="line"><span class="keyword">int</span> l,n,m;</span><br><span class="line"><span class="keyword">int</span> sx,sy,sz,ex,ey,ez;</span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">check</span><span class="params">(node a)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(a.z<l&&a.z>=<span class="number">0</span>&&a.x<n&&a.x>=<span class="number">0</span>&&a.y<m&&a.y>=<span class="number">0</span>)<span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">bfs</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="built_in">queue</span><node> dq;</span><br><span class="line"> node now(sx,sy,sz),next;</span><br><span class="line"> dq.push(now);</span><br><span class="line"> vis[sz][sx][sy]=<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">while</span>(!dq.empty()){</span><br><span class="line"> now=dq.front();</span><br><span class="line"> dq.pop();</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<<span class="number">6</span>;i++){</span><br><span class="line"> next.z=now.z+mov[i][<span class="number">0</span>];</span><br><span class="line"> next.x=now.x+mov[i][<span class="number">1</span>];</span><br><span class="line"> next.y=now.y+mov[i][<span class="number">2</span>];</span><br><span class="line"> <span class="keyword">if</span>(check(next)&&vis[next.z][next.x][next.y]==<span class="number">0</span>&&mp[next.z][next.x][next.y]!=<span class="string">'#'</span>){</span><br><span class="line"> dq.push(next);</span><br><span class="line"> vis[next.z][next.x][next.y]=vis[now.z][now.x][now.y]+<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(mp[next.z][next.x][next.y]==<span class="string">'E'</span>)<span class="keyword">return</span> vis[next.z][next.x][next.y];</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">while</span>(<span class="built_in">scanf</span>(<span class="string">"%d%d%d"</span>,&l,&n,&m)){</span><br><span class="line"> <span class="keyword">if</span>(!n&&!m&&!l)<span class="keyword">break</span>;</span><br><span class="line"> getchar();</span><br><span class="line"> <span class="built_in">memset</span>(mp,<span class="number">0</span>,<span class="keyword">sizeof</span>(mp));</span><br><span class="line"> <span class="built_in">memset</span>(vis,<span class="number">0</span>,<span class="keyword">sizeof</span>(vis));</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<l;i++){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j<n;j++){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> k=<span class="number">0</span>;k<m;k++){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%c"</span>,&mp[i][j][k]);</span><br><span class="line"> <span class="keyword">if</span>(mp[i][j][k]==<span class="string">'S'</span>)sx=j,sy=k,sz=i;</span><br><span class="line"> <span class="keyword">if</span>(mp[i][j][k]==<span class="string">'E'</span>)ex=j,ey=k,ez=i;</span><br><span class="line"> }</span><br><span class="line"> getchar();</span><br><span class="line"> }</span><br><span class="line"> getchar(); <span class="comment">//吃换行</span></span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">int</span> ans=bfs();</span><br><span class="line"> <span class="keyword">if</span>(ans==<span class="number">-1</span>)<span class="built_in">printf</span>(<span class="string">"Trapped!\n"</span>);</span><br><span class="line"> <span class="keyword">else</span> <span class="built_in">printf</span>(<span class="string">"Escaped in %d minute(s).\n"</span>,ans<span class="number">-1</span>);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h3 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://poj.org/problem?id=2251" target="_blank" rel="noopener">题目
</summary>
<category term="题解" scheme="https://anoyer.cn/categories/%E9%A2%98%E8%A7%A3/"/>
<category term="BFS" scheme="https://anoyer.cn/tags/BFS/"/>
<category term="POJ" scheme="https://anoyer.cn/tags/POJ/"/>
</entry>
<entry>
<title>POJ - 1426 - Find The Multiple(双入口DFS)</title>
<link href="https://anoyer.cn/article/POJ-1426-Find-The-Multiple.html"/>
<id>https://anoyer.cn/article/POJ-1426-Find-The-Multiple.html</id>
<published>2019-02-25T09:09:40.000Z</published>
<updated>2019-02-25T09:14:03.440Z</updated>
<content type="html"><![CDATA[<h3 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://poj.org/problem?id=1426" target="_blank" rel="noopener">题目链接</a></h3><h4 id="题意:"><a href="#题意:" class="headerlink" title="题意:"></a>题意:</h4><blockquote><p>给一个数n,让你找出一个只有1,0,组成的十进制数,要求是找到的数可以被n整除</p></blockquote><h4 id="题解:"><a href="#题解:" class="headerlink" title="题解:"></a>题解:</h4><blockquote><p>用DFS是搜索 当前位数字 (除最高位固定为1),因为每一位都只有0或1两种选择</p></blockquote><h4 id="AC代码:"><a href="#AC代码:" class="headerlink" title="AC代码:"></a>AC代码:</h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><string.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><iostream></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><algorithm></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">230</span>;</span><br><span class="line"><span class="keyword">int</span> n;</span><br><span class="line"><span class="keyword">bool</span> found;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">dfs</span><span class="params">(ll ans,<span class="keyword">int</span> k)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(found)<span class="keyword">return</span>;</span><br><span class="line"> <span class="keyword">if</span>(ans%n==<span class="number">0</span>){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%llu\n"</span>,ans);</span><br><span class="line"> found=<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(k==<span class="number">19</span>)<span class="keyword">return</span>;</span><br><span class="line"> dfs(ans*<span class="number">10</span>,k+<span class="number">1</span>);</span><br><span class="line"> dfs(ans*<span class="number">10</span>+<span class="number">1</span>,k+<span class="number">1</span>);</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">while</span>(<span class="built_in">scanf</span>(<span class="string">"%d"</span>,&n)&&n){</span><br><span class="line"> found=<span class="number">0</span>;</span><br><span class="line"> dfs(<span class="number">1</span>,<span class="number">0</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h3 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://poj.org/problem?id=1426" target="_blank" rel="noopener">题目
</summary>
<category term="题解" scheme="https://anoyer.cn/categories/%E9%A2%98%E8%A7%A3/"/>
<category term="BFS" scheme="https://anoyer.cn/tags/BFS/"/>
<category term="POJ" scheme="https://anoyer.cn/tags/POJ/"/>
</entry>
<entry>
<title>POJ - 1321 - 棋盘问题(裸DFS)</title>
<link href="https://anoyer.cn/article/POJ-1321.html"/>
<id>https://anoyer.cn/article/POJ-1321.html</id>
<published>2019-02-25T09:05:17.000Z</published>
<updated>2019-02-25T09:09:16.835Z</updated>
<content type="html"><![CDATA[<h3 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://poj.org/problem?id=1321" target="_blank" rel="noopener">题目链接</a></h3><h4 id="题意:"><a href="#题意:" class="headerlink" title="题意:"></a>题意:</h4><blockquote><p>给你一个棋盘,问在这个棋盘上放K个棋子,有多少种放法(每行每列只能有一个棋子)</p></blockquote><h4 id="题解:"><a href="#题解:" class="headerlink" title="题解:"></a>题解:</h4><blockquote><p>对棋盘DFS搜索,每满足一种就ans++,基本是裸的</p></blockquote><h4 id="AC代码:"><a href="#AC代码:" class="headerlink" title="AC代码:"></a>AC代码:</h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><string.h></span></span></span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">17</span>;</span><br><span class="line"><span class="keyword">char</span> mp[maxn][maxn];</span><br><span class="line"><span class="keyword">bool</span> vis[maxn];</span><br><span class="line">ll ans=<span class="number">0</span>;</span><br><span class="line"><span class="keyword">int</span> k,n;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">dfs</span><span class="params">(<span class="keyword">int</span> x,<span class="keyword">int</span> y)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(y>=k){</span><br><span class="line"> ans++;</span><br><span class="line"> <span class="keyword">return</span> ;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=x;i<n;i++){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j<n;j++){</span><br><span class="line"> <span class="keyword">if</span>(vis[j]==<span class="number">0</span>&&mp[i][j]==<span class="string">'#'</span>){</span><br><span class="line"> vis[j]=<span class="number">1</span>;</span><br><span class="line"> dfs(i+<span class="number">1</span>,y+<span class="number">1</span>);</span><br><span class="line"> vis[j]=<span class="number">0</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">while</span>(<span class="built_in">scanf</span>(<span class="string">"%d%d"</span>,&n,&k)){</span><br><span class="line"> <span class="keyword">if</span>(n==<span class="number">-1</span>&&k==<span class="number">-1</span>)<span class="keyword">break</span>;</span><br><span class="line"> <span class="built_in">memset</span>(mp,<span class="number">0</span>,<span class="keyword">sizeof</span>(mp));</span><br><span class="line"> <span class="built_in">memset</span>(vis,<span class="number">0</span>,<span class="keyword">sizeof</span>(vis));</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<n;i++)<span class="built_in">scanf</span>(<span class="string">"%s"</span>,mp[i]);</span><br><span class="line"> ans=<span class="number">0</span>;</span><br><span class="line"> dfs(<span class="number">0</span>,<span class="number">0</span>);</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%lld\n"</span>,ans);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h3 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://poj.org/problem?id=1321" target="_blank" rel="noopener">题目
</summary>
<category term="题解" scheme="https://anoyer.cn/categories/%E9%A2%98%E8%A7%A3/"/>
<category term="DFS" scheme="https://anoyer.cn/tags/DFS/"/>
<category term="POJ" scheme="https://anoyer.cn/tags/POJ/"/>
</entry>
<entry>
<title>HDU - 2612 - Find a way(BFS+打表)</title>
<link href="https://anoyer.cn/article/HDU-2612-Find-a-way.html"/>
<id>https://anoyer.cn/article/HDU-2612-Find-a-way.html</id>
<published>2019-02-25T09:00:10.000Z</published>
<updated>2019-02-25T09:04:58.080Z</updated>
<content type="html"><![CDATA[<h3 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://acm.hdu.edu.cn/showproblem.php?pid=2612" target="_blank" rel="noopener">题目链接</a></h3><h4 id="题意:"><a href="#题意:" class="headerlink" title="题意:"></a>题意:</h4><blockquote><p>求2个点到KFC的距离之和,使其最小</p></blockquote><h4 id="题解:"><a href="#题解:" class="headerlink" title="题解:"></a>题解:</h4><blockquote><p>可用2次BFS,分别求出2个点到各个KFC的最短距离,然后找出和最小的即可</p></blockquote><h4 id="AC代码:"><a href="#AC代码:" class="headerlink" title="AC代码:"></a>AC代码:</h4><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br></pre></td><td class="code"><pre><span class="line">#include<stdio.h></span><br><span class="line">#include<string.h></span><br><span class="line">#include<iostream></span><br><span class="line">#include<queue></span><br><span class="line">#define inf 0xffffff</span><br><span class="line">using namespace std;</span><br><span class="line">const int N=210;</span><br><span class="line">int m,n,mark[N][N],dis[N][N][2],dir[4][2]={1,0, 0,1, -1,0, 0,-1},flag;</span><br><span class="line">char s[N][N];</span><br><span class="line">struct node{</span><br><span class="line"> int x,y,step;</span><br><span class="line">};</span><br><span class="line">bool judge(int x,int y){</span><br><span class="line"> if(x>=0 && x<m && y>=0 && y<n && s[x][y]!='#' && mark[x][y]==0)</span><br><span class="line"> return 1;</span><br><span class="line"> return 0;</span><br><span class="line">}</span><br><span class="line">void bfs(int x,int y){</span><br><span class="line"> int k;</span><br><span class="line"> queue<node>q;</span><br><span class="line"> node cur,next;</span><br><span class="line"> cur.x=x;cur.y=y;cur.step=0;</span><br><span class="line"> mark[x][y]=1;</span><br><span class="line"> q.push(cur);</span><br><span class="line"> while(!q.empty()){</span><br><span class="line"> cur=q.front();</span><br><span class="line"> q.pop();</span><br><span class="line"> next.step=cur.step+1;</span><br><span class="line"> for(k=0;k<4;k++){</span><br><span class="line"> next.x=x=cur.x+dir[k][0];</span><br><span class="line"> next.y=y=cur.y+dir[k][1];</span><br><span class="line"> if(judge(x,y)){</span><br><span class="line"> mark[x][y]=1;</span><br><span class="line"> if(s[x][y]=='@')dis[x][y][flag]=next.step;</span><br><span class="line"> q.push(next);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line">int main(){</span><br><span class="line"> int i,j,min;</span><br><span class="line"> while(scanf("%d %d",&m,&n)!=-1){</span><br><span class="line"> min=inf;</span><br><span class="line"> for(i=0;i<m;i++)</span><br><span class="line"> for(j=0;j<n;j++)</span><br><span class="line"> dis[i][j][0]=dis[i][j][1]=inf;</span><br><span class="line"></span><br><span class="line"> for(i=0;i<m;i++)scanf("%s",s[i]);</span><br><span class="line"> for(i=0;i<m;i++)</span><br><span class="line"> for(j=0;j<n;j++){</span><br><span class="line"> if(s[i][j]=='Y'){</span><br><span class="line"> flag=0;</span><br><span class="line"> memset(mark,0,sizeof(mark));</span><br><span class="line"> bfs(i,j);</span><br><span class="line"> }</span><br><span class="line"> else if(s[i][j]=='M'){</span><br><span class="line"> flag=1;</span><br><span class="line"> memset(mark,0,sizeof(mark));</span><br><span class="line"> bfs(i,j);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> for(i=0;i<m;i++)</span><br><span class="line"> for(j=0;j<n;j++)</span><br><span class="line"> if(s[i][j]=='@' && min>dis[i][j][0]+dis[i][j][1])</span><br><span class="line"> min=dis[i][j][0]+dis[i][j][1];</span><br><span class="line"> printf("%d\n",min*11);</span><br><span class="line"> }</span><br><span class="line"> return 0;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h3 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://acm.hdu.edu.cn/showproblem.php?pid=2612" target="_blank" r
</summary>
<category term="题解" scheme="https://anoyer.cn/categories/%E9%A2%98%E8%A7%A3/"/>
<category term="HDU" scheme="https://anoyer.cn/tags/HDU/"/>
<category term="BFS" scheme="https://anoyer.cn/tags/BFS/"/>
</entry>
<entry>
<title>HDU - 1241 - Oil Deposits(DFS联通块)</title>
<link href="https://anoyer.cn/article/HDU-1241-Oil-Deposits.html"/>
<id>https://anoyer.cn/article/HDU-1241-Oil-Deposits.html</id>
<published>2019-02-25T08:53:51.000Z</published>
<updated>2019-02-25T08:59:30.539Z</updated>
<content type="html"><![CDATA[<h3 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://acm.hdu.edu.cn/showproblem.php?pid=1241" target="_blank" rel="noopener">题目链接</a></h3><h4 id="题意:"><a href="#题意:" class="headerlink" title="题意:"></a>题意:</h4><blockquote><p>就是给你一个地图,找出所有不相连(八个方向)的@组合有多少个</p></blockquote><h4 id="题解:"><a href="#题解:" class="headerlink" title="题解:"></a>题解:</h4><blockquote><p>经典的DFS求联通块的题,和紫书上求油田一样,枚举每一个点进行DFS搜联通的@</p></blockquote><h4 id="AC代码:"><a href="#AC代码:" class="headerlink" title="AC代码:"></a>AC代码:</h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">105</span>;</span><br><span class="line"><span class="keyword">char</span> mat[maxn][maxn];</span><br><span class="line"><span class="keyword">int</span> dir[<span class="number">8</span>][<span class="number">2</span>]={{<span class="number">1</span>,<span class="number">0</span>},{<span class="number">-1</span>,<span class="number">0</span>},{<span class="number">0</span>,<span class="number">1</span>},{<span class="number">0</span>,<span class="number">-1</span>},{<span class="number">1</span>,<span class="number">1</span>},{<span class="number">-1</span>,<span class="number">1</span>},{<span class="number">1</span>,<span class="number">-1</span>},{<span class="number">-1</span>,<span class="number">-1</span>}};</span><br><span class="line"><span class="keyword">int</span> m,n;</span><br><span class="line"><span class="keyword">int</span> sum;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">Dfs</span><span class="params">(<span class="keyword">int</span> x,<span class="keyword">int</span> y)</span></span>{</span><br><span class="line"> <span class="keyword">int</span> tx;</span><br><span class="line"> <span class="keyword">int</span> ty;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<<span class="number">8</span>;i++){</span><br><span class="line"> tx=x+dir[i][<span class="number">0</span>];</span><br><span class="line"> ty=y+dir[i][<span class="number">1</span>];</span><br><span class="line"> <span class="keyword">if</span>(<span class="number">1</span><=tx&&tx<=m&&<span class="number">1</span><=ty&&ty<=n){<span class="comment">//注意!对于二维数组来说,x行y列,意味着x是纵向坐标,y是横向坐标</span></span><br><span class="line"> <span class="keyword">if</span>(mat[tx][ty]==<span class="string">'@'</span>){</span><br><span class="line"> mat[tx][ty]=<span class="string">'*'</span>;</span><br><span class="line"> Dfs(tx,ty);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">while</span>(<span class="built_in">scanf</span>(<span class="string">"%d%d"</span>,&m,&n)){</span><br><span class="line"> <span class="keyword">if</span>(m==<span class="number">0</span>&&n==<span class="number">0</span>){</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">//memset(mat,0,sizeof(mat));</span></span><br><span class="line"> sum=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=m;i++){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j<=n;j++){</span><br><span class="line"> <span class="comment">//scanf("%s",mat[i]+1);</span></span><br><span class="line"> <span class="built_in">cin</span>>>mat[i][j];</span><br><span class="line"> <span class="comment">//scanf("%c",&mat[i][j]);</span></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=m;i++){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j<=n;j++){</span><br><span class="line"> <span class="keyword">if</span>(mat[i][j]==<span class="string">'@'</span>){</span><br><span class="line"> sum++;</span><br><span class="line"> mat[i][j]=<span class="string">'*'</span>;</span><br><span class="line"> Dfs(i,j); <span class="comment">//深搜,消除同一连通块的所有油田标记</span></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">cout</span><<sum<<<span class="built_in">endl</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h3 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://acm.hdu.edu.cn/showproblem.php?pid=1241" target="_blank" r
</summary>
<category term="题解" scheme="https://anoyer.cn/categories/%E9%A2%98%E8%A7%A3/"/>
<category term="HDU" scheme="https://anoyer.cn/tags/HDU/"/>
<category term="DFS" scheme="https://anoyer.cn/tags/DFS/"/>
</entry>
<entry>
<title>FZU - 2150 - Fire Game(双端BFS)</title>
<link href="https://anoyer.cn/article/FZU-2150-Fire-Game.html"/>
<id>https://anoyer.cn/article/FZU-2150-Fire-Game.html</id>
<published>2019-02-25T08:45:53.000Z</published>
<updated>2019-02-25T09:49:22.535Z</updated>
<content type="html"><![CDATA[<h3 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://acm.fzu.edu.cn/problem.php?pid=2150" target="_blank" rel="noopener">题目链接</a></h3><h4 id="题意:"><a href="#题意:" class="headerlink" title="题意:"></a>题意:</h4><blockquote><p>给你块地,有空地,也有草堆,让你选两个草堆进行点火,燃烧的草堆会引燃上下左右的相邻草堆,<br>每一次引燃花费1s时间,问你最少花多长时间把草堆都点着,如果做不到输出-1.</p></blockquote><h4 id="题解:"><a href="#题解:" class="headerlink" title="题解:"></a>题解:</h4><blockquote><p>枚举图中所有草地,找到任意两块不一样的草地,然后bfs求出烧掉所有草的最短时间,<br>可以将两个初始状态都push进队列,这样就可以模拟两堆草同时燃烧的情况,<br>在bfs的过程中要判断是否烧完(即所有的草堆的点都要被访问过),如果烧完,就立即返回这点的距离,<br>就是以该状态枚举时,的最远距离,让后输出最远距离中最小的就是最终结果。</p></blockquote><h4 id="AC代码:"><a href="#AC代码:" class="headerlink" title="AC代码:"></a>AC代码:</h4><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><string.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><algorithm></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><queue></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><vector></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn = <span class="number">20</span>;</span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">node</span>{</span></span><br><span class="line"><span class="keyword">int</span> x, y;</span><br><span class="line">node(<span class="keyword">int</span> i = <span class="number">0</span>, <span class="keyword">int</span> j = <span class="number">0</span>){ x = i, y = j; };</span><br><span class="line">};</span><br><span class="line"><span class="keyword">char</span> mp[maxn][maxn];</span><br><span class="line"><span class="keyword">int</span> vis[maxn][maxn];</span><br><span class="line"><span class="keyword">int</span> n, m;</span><br><span class="line"><span class="keyword">int</span> _size;</span><br><span class="line"><span class="keyword">int</span> dis[<span class="number">4</span>][<span class="number">2</span>] = { <span class="number">1</span>, <span class="number">0</span>, <span class="number">-1</span>, <span class="number">0</span>, <span class="number">0</span>, <span class="number">1</span>, <span class="number">0</span>, <span class="number">-1</span> };</span><br><span class="line"><span class="built_in">vector</span><node>cp;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">bfs</span><span class="params">(node a, node b)</span></span>{</span><br><span class="line"><span class="built_in">memset</span>(vis, <span class="number">0</span>, <span class="keyword">sizeof</span>(vis));</span><br><span class="line"><span class="built_in">queue</span><node>dq;</span><br><span class="line">dq.push(a);</span><br><span class="line">dq.push(b);</span><br><span class="line">vis[a.x][a.y] = vis[b.x][b.y] = <span class="number">1</span>;</span><br><span class="line"><span class="keyword">int</span> ans = <span class="number">1</span>; <span class="comment">//能达到的最大时间</span></span><br><span class="line">node na, nb;</span><br><span class="line"><span class="keyword">while</span> (!dq.empty()){</span><br><span class="line">a = dq.front(), dq.pop();</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i<<span class="number">4</span>; i++){</span><br><span class="line">na.x = a.x + dis[i][<span class="number">0</span>];</span><br><span class="line">na.y = a.y + dis[i][<span class="number">1</span>];</span><br><span class="line"><span class="keyword">if</span> (na.x >= <span class="number">0</span> && na.x<n&&na.y >= <span class="number">0</span> && na.y<m&&mp[na.x][na.y] == <span class="string">'#'</span>&&vis[na.x][na.y] == <span class="number">0</span>)</span><br><span class="line">dq.push(na), vis[na.x][na.y] = vis[a.x][a.y] + <span class="number">1</span>, ans = max(ans, vis[na.x][na.y]);</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i<_size; i++){ <span class="comment">//遍历所有草堆看看是否全部都已经被火覆盖</span></span><br><span class="line"><span class="keyword">if</span> (vis[cp[i].x][cp[i].y] == <span class="number">0</span>)<span class="keyword">return</span> <span class="number">-1</span>;</span><br><span class="line">}</span><br><span class="line"><span class="keyword">return</span> ans;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"><span class="keyword">int</span> t, tt = <span class="number">1</span>;</span><br><span class="line"><span class="built_in">scanf</span>(<span class="string">"%d"</span>, &t);</span><br><span class="line">node xx;</span><br><span class="line"><span class="keyword">while</span> (tt <= t){</span><br><span class="line">cp.clear();</span><br><span class="line"><span class="built_in">scanf</span>(<span class="string">"%d%d"</span>, &n, &m);</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i<n; i++){</span><br><span class="line">getchar();</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> j = <span class="number">0</span>; j<m; j++){</span><br><span class="line"><span class="built_in">scanf</span>(<span class="string">"%c"</span>, &mp[i][j]);</span><br><span class="line">xx.x=i,xx.y=j;</span><br><span class="line"><span class="keyword">if</span> (mp[i][j] == <span class="string">'#'</span>)cp.push_back(xx); <span class="comment">//存入#节点坐标,便于枚举火堆</span></span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> ans = <span class="number">99999999</span>;</span><br><span class="line">_size = cp.size();</span><br><span class="line"><span class="keyword">if</span>(_size==<span class="number">1</span>)ans=<span class="number">1</span>;</span><br><span class="line"><span class="comment">//for(int i=0;i<_size;i++)cout<<cp[i].x<<" "<<cp[i].y<<endl;</span></span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">0</span>; i<_size; i++){</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> j = i + <span class="number">1</span>; j<_size; j++){</span><br><span class="line"><span class="keyword">int</span> tmp = bfs(cp[i], cp[j]); <span class="comment">//枚举火堆跑bfs</span></span><br><span class="line"> <span class="keyword">if</span>(tmp==<span class="number">-1</span>)<span class="keyword">continue</span>;</span><br><span class="line"> ans=min(tmp,ans);</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"><span class="keyword">if</span>(ans==<span class="number">99999999</span>)<span class="built_in">printf</span>(<span class="string">"Case %d: -1\n"</span>, tt++);</span><br><span class="line"><span class="keyword">else</span> <span class="built_in">printf</span>(<span class="string">"Case %d: %d\n"</span>, tt++, ans<span class="number">-1</span>);</span><br><span class="line">}</span><br><span class="line"><span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h3 id="题目链接"><a href="#题目链接" class="headerlink" title="题目链接"></a><a href="http://acm.fzu.edu.cn/problem.php?pid=2150" target="_blank" rel="
</summary>
<category term="题解" scheme="https://anoyer.cn/categories/%E9%A2%98%E8%A7%A3/"/>
<category term="BFS" scheme="https://anoyer.cn/tags/BFS/"/>
<category term="FZU" scheme="https://anoyer.cn/tags/FZU/"/>
</entry>
<entry>
<title>2019 Wannafly Camp day8</title>
<link href="https://anoyer.cn/article/2019-Wannafly-Camp-day8.html"/>
<id>https://anoyer.cn/article/2019-Wannafly-Camp-day8.html</id>
<published>2019-01-27T11:04:56.000Z</published>
<updated>2019-01-27T14:16:05.389Z</updated>
<content type="html"><![CDATA[<h3 id="自闭感受"><a href="#自闭感受" class="headerlink" title="自闭感受"></a>自闭感受</h3><blockquote><p>Camp最后一天了,上午 <font color="Red" size="6" face="宋体">hls</font> 给我们讲了计数和概率,太无奈自己太菜只听懂了一点点,有点可惜了。ε=(´ο`*)))唉。下午训练果然和我预想的一样,最后一场应该是自闭场 <del>(虽然天天自闭)</del>,一套题目下来,J题T了,A题队友被自己hack了,G题死怼一下午,从开始毫无思绪,到后面展开各种毛病。心态简直爆炸了</p><p>不知不觉就过去了8天,突然对这段时光有点不舍,虽然自闭但却快乐着。晚上和队友回去,看着路上6人的影子 <del>(包括另外一队)</del>,突然感觉ACM是多么一件快乐并有意义的事情!还有9个月时间,加油Anoyer!</p></blockquote><h3 id="上题解"><a href="#上题解" class="headerlink" title="上题解"></a>上题解</h3><p><a href="https://www.zhixincode.com/contest/29/problem/G?problem_id=420" target="_blank" rel="noopener"><strong>G - 穗乃果的考试</strong></a></p><p>先对方块求一个二维前缀和,这样就相当于枚举前缀和中每一个小块的和了。</p><p><img src="https://img.vim-cn.com/e3/d2c220ef7fa7ddbc72b16d12ba073a36e00b27.png" alt=""></p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> mod=<span class="number">998244353</span>;</span><br><span class="line"><span class="keyword">char</span> s[<span class="number">2200</span>][<span class="number">2200</span>];</span><br><span class="line">ll a[<span class="number">2200</span>][<span class="number">2200</span>],sum[<span class="number">2200</span>][<span class="number">2200</span>];</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> n,m;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d"</span>,&n,&m);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<n;i++)<span class="built_in">scanf</span>(<span class="string">"%s"</span>,s[i]);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;i++)</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j<=m;j++)a[i][j]=s[i<span class="number">-1</span>][j<span class="number">-1</span>]-<span class="string">'0'</span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;i++)</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j<=m;j++)</span><br><span class="line"> sum[i][j]=sum[i<span class="number">-1</span>][j]+sum[i][j<span class="number">-1</span>]-sum[i<span class="number">-1</span>][j<span class="number">-1</span>]+a[i][j];</span><br><span class="line"></span><br><span class="line"> ll ans=<span class="number">0</span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;i++)</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j<=m;j++)ans=(ans+sum[i][j]*(i*j))%mod;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<=n;i++)</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j<=m;j++)ans=(ans+sum[i][j]*(n-i)*(m-j))%mod;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;i++)</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j<=m;j++)ans=(ans-sum[i][j]*i*(m-j))%mod;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<=n;i++)</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j<=m;j++)ans=(ans-sum[i][j]*((n-i)*j))%mod;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">while</span>(ans<<span class="number">0</span>)ans+=mod;</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%lld\n"</span>,ans%mod);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h3 id="自闭感受"><a href="#自闭感受" class="headerlink" title="自闭感受"></a>自闭感受</h3><blockquote><p>Camp最后一天了,上午 <font color="Red" size="6" face="宋体">
</summary>
<category term="2019 Wannafly Winter Camp" scheme="https://anoyer.cn/categories/2019-Wannafly-Winter-Camp/"/>
<category term="Camp" scheme="https://anoyer.cn/tags/Camp/"/>
</entry>
<entry>
<title>2019 Wannafly Camp day7</title>
<link href="https://anoyer.cn/article/2019-Wannafly-Camp-day7.html"/>
<id>https://anoyer.cn/article/2019-Wannafly-Camp-day7.html</id>
<published>2019-01-26T14:05:58.000Z</published>
<updated>2019-01-27T02:51:25.045Z</updated>
<content type="html"><![CDATA[<h3 id="自闭感受"><a href="#自闭感受" class="headerlink" title="自闭感受"></a>自闭感受</h3><blockquote><p>Camp第七天,上午<font color="Red" size="8" face="宋体">xls</font>给我们来了一波意识流图论讲解,我没有包图论所以听了些前面简单的,就去补day3,div1的数论了。经过群里一群大佬的点醒,发现自己傻逼了,明明可以直接用我div2的欧拉函数写法套上两个杜教加分块就能过,还整半天直接用莫比乌斯跑TT。</p><p>下午训练赛,感觉题目有点坑,数据范围好大,就写了两道签到题EG,队友没有怼出A题,晚上听解题发现自己D题推的离答案就差一两步了,结果放弃了。难受!!!快被自己菜哭了。</p><p>以后还是要多刷题啊,题量太少了,大佬们看啥都是原题,加油。</p></blockquote><h3 id="上题解"><a href="#上题解" class="headerlink" title="上题解"></a>上题解</h3><p><a href="https://www.zhixincode.com/contest/25/problem/E?problem_id=363" target="_blank" rel="noopener"><strong>E - 线性探查法</strong></a></p><p>按照哈希的操作进行逆操作,求出每一位最小数值,利用set维护压入的最小值。</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">3e3</span>+<span class="number">20</span>;</span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">Node</span>{</span></span><br><span class="line"> ll a;</span><br><span class="line"> <span class="keyword">int</span> id;</span><br><span class="line"> <span class="keyword">bool</span> <span class="keyword">operator</span> < (<span class="keyword">const</span> Node &oth) <span class="keyword">const</span>{</span><br><span class="line"><span class="keyword">return</span> a < oth.a;</span><br><span class="line">}</span><br><span class="line">};</span><br><span class="line">ll b[maxn];</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> n;</span><br><span class="line"> <span class="built_in">set</span><Node>st;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&n);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<n;i++){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%lld"</span>,&b[i]);</span><br><span class="line"> <span class="keyword">if</span>(b[i]%n==i)st.insert({ b[i] , i });</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<n;i++){<span class="comment">//逆操作求解</span></span><br><span class="line"> Node f=*st.begin();</span><br><span class="line"> st.erase(st.begin());</span><br><span class="line"> b[f.id]=<span class="number">0</span>; <span class="comment">//已经插入</span></span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%lld "</span>,f.a);</span><br><span class="line"> <span class="keyword">int</span> j=f.id;</span><br><span class="line"> <span class="keyword">while</span>(!b[j])j=(j+<span class="number">1</span>)%n;<span class="comment">//找出应该放入的位置</span></span><br><span class="line"> <span class="keyword">int</span> k=b[j]%n,flag=<span class="number">1</span>;<span class="comment">//实际位置</span></span><br><span class="line"> <span class="keyword">while</span>(k!=j){</span><br><span class="line"> <span class="keyword">if</span>(b[k]){</span><br><span class="line"> flag=<span class="number">0</span>;</span><br><span class="line"> }</span><br><span class="line"> k=(k+<span class="number">1</span>)%n;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(flag)st.insert({b[j],j});</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">cout</span><<st.begin()->a<<<span class="built_in">endl</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><a href="https://www.zhixincode.com/contest/25/problem/G?problem_id=365" target="_blank" rel="noopener"><strong>G - 抢红包机器人</strong></a></p><p>枚举每个红包的第一个抢的人为机器人,去暴力正反扫两遍红包序列,找出机器人,最后取枚举得到的数的min,最后看看是否有人未参与抢红包,有的话就直接输出1。(可以更优,直接枚举人)</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">int</span> a[<span class="number">120</span>][<span class="number">120</span>];</span><br><span class="line"><span class="keyword">bool</span> b[<span class="number">120</span>],mp[<span class="number">120</span>];</span><br><span class="line"><span class="keyword">int</span> nn[<span class="number">120</span>];</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> n,m;</span><br><span class="line"> <span class="built_in">cin</span>>>n>>m;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<m;i++){</span><br><span class="line"> <span class="keyword">int</span> aa;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&nn[i]);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j<nn[i];j++){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&a[i][j]);</span><br><span class="line"> b[a[i][j]]=<span class="number">1</span>;<span class="comment">//标记此人参与了抢红包</span></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">int</span> cnt1=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;i++){</span><br><span class="line"> <span class="keyword">if</span>(b[i]==<span class="number">0</span>)cnt1++;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(cnt1)<span class="built_in">printf</span>(<span class="string">"1\n"</span>);</span><br><span class="line"> <span class="keyword">else</span> {</span><br><span class="line"> <span class="keyword">int</span> res=<span class="number">0</span>,ans=<span class="number">999999</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<m;i++){</span><br><span class="line"> <span class="built_in">memset</span>(mp,<span class="number">0</span>,<span class="keyword">sizeof</span>(mp));</span><br><span class="line"> mp[a[i][<span class="number">0</span>]]=<span class="number">1</span>;</span><br><span class="line"> res=<span class="number">0</span>;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j<m;j++){<span class="comment">//正扫</span></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> k=nn[j]<span class="number">-1</span>;k>=<span class="number">0</span>;k--){</span><br><span class="line"> <span class="keyword">if</span>(mp[a[j][k]]){</span><br><span class="line"> <span class="keyword">for</span>(k--;k>=<span class="number">0</span>;k--){</span><br><span class="line"> mp[a[j][k]]=<span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=m<span class="number">-1</span>;j>=<span class="number">0</span>;j--){<span class="comment">//反扫</span></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> k=nn[j]<span class="number">-1</span>;k>=<span class="number">0</span>;k--){</span><br><span class="line"> <span class="keyword">if</span>(mp[a[j][k]]){</span><br><span class="line"> <span class="keyword">for</span>(k--;k>=<span class="number">0</span>;k--){</span><br><span class="line"> mp[a[j][k]]=<span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;i++)<span class="keyword">if</span>(mp[i])res++;</span><br><span class="line"> ans=min(ans,res);</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d\n"</span>,ans);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h3 id="自闭感受"><a href="#自闭感受" class="headerlink" title="自闭感受"></a>自闭感受</h3><blockquote><p>Camp第七天,上午<font color="Red" size="8" face="宋体">xls
</summary>
<category term="2019 Wannafly Winter Camp" scheme="https://anoyer.cn/categories/2019-Wannafly-Winter-Camp/"/>
<category term="Camp" scheme="https://anoyer.cn/tags/Camp/"/>
</entry>
<entry>
<title>2019 Wannafly Camp day5</title>
<link href="https://anoyer.cn/article/2019-Wannafly-Camp-day5.html"/>
<id>https://anoyer.cn/article/2019-Wannafly-Camp-day5.html</id>
<published>2019-01-24T13:24:37.000Z</published>
<updated>2019-01-26T03:07:52.680Z</updated>
<content type="html"><![CDATA[<h3 id="自闭感受"><a href="#自闭感受" class="headerlink" title="自闭感受"></a>自闭感受</h3><blockquote><p>参加Camp第五天,今天是<font color="Red" size="6" face="宋体">dls</font>的计算几何专场,可是说是几何板子讲解,也是这几天听得最明白,学得最多的一天。dls从基础的点积叉积到线到圆等,感觉非常Nice,相对dls说<img src="http://pic1.sc.chinaz.com/Files/pic/Listfaces/5304/01.gif" alt="">。</p><p>下午依旧是训练赛,比昨天感觉好不少,真的是越来越亲民了,还以为今天要爆零自闭呢。同时经过今天的计算几何,感觉自己整理一套计算几何板子真的非常有必要,结束后也该操手了。</p></blockquote><h3 id="上题解"><a href="#上题解" class="headerlink" title="上题解"></a>上题解</h3><p><a href="https://www.zhixincode.com/contest/21/problem/A?problem_id=316" target="_blank" rel="noopener"><strong>A - Cactus Draw</strong></a></p><p>把节点的深度做x坐标,儿子序做y坐标,进行DFS遍历,因为是棵树所以肯定不会交边</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br></pre></td><td class="code"><pre><span class="line">#include<stdio.h></span><br><span class="line">#include<bits/stdc++.h></span><br><span class="line">using namespace std;</span><br><span class="line">const int maxn=1e4+10;</span><br><span class="line">struct edge{</span><br><span class="line"> int v,next;</span><br><span class="line">}e[maxn];</span><br><span class="line">int head[maxn],hcnt=0;</span><br><span class="line">int u[maxn],v[maxn];</span><br><span class="line">void add(int u,int v){</span><br><span class="line"> e[hcnt]=edge{v,head[u]};</span><br><span class="line"> head[u]=hcnt++;</span><br><span class="line">}</span><br><span class="line">pair<int,int> point[maxn];</span><br><span class="line">bool vi[maxn];</span><br><span class="line">int vis[maxn];</span><br><span class="line">void dfs(int u,int x){</span><br><span class="line"> if(vi[u])return;</span><br><span class="line"> vi[u]=1;</span><br><span class="line"> if(!vis[x])</span><br><span class="line"> vis[x]=1;</span><br><span class="line"> point[u]=make_pair(x,vis[x]++);</span><br><span class="line"> for(int i=head[u];i>=0;i=e[i].next){</span><br><span class="line"> int v=e[i].v;</span><br><span class="line"> if(vi[v])continue;</span><br><span class="line"> dfs(v,x+1);</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line">int main(){</span><br><span class="line"> int n,m;</span><br><span class="line"> scanf("%d%d",&n,&m);</span><br><span class="line"> memset(head,-1,sizeof(head));</span><br><span class="line"> for(int i=1;i<=m;i++)</span><br><span class="line"> scanf("%d%d",&u[i],&v[i]),add(u[i],v[i]),add(v[i],u[i]);</span><br><span class="line"> dfs(1,1);</span><br><span class="line"> for(int i=1;i<=n;i++)</span><br><span class="line"> cout<<point[i].first<<' '<<point[i].second<<endl;</span><br><span class="line"> return 0;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><a href="https://www.zhixincode.com/contest/21/problem/C?problem_id=318" target="_blank" rel="noopener"><strong>C - Division</strong></a></p><p>把每个数先压到优先队列中,每次操作取队顶元素除2再压进去,同时判断下队顶是否为0,如果为0就没必要继续操作了。因为数大小1e9所以每个数最多就操作30次。</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">1e5</span>+<span class="number">7</span>;</span><br><span class="line">priority_queue<<span class="keyword">int</span>>a;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> n,k,aa;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d"</span>,&n,&k);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<n;i++){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&aa);</span><br><span class="line"> a.push(aa);</span><br><span class="line"> }</span><br><span class="line"> ll ans=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<k;i++){</span><br><span class="line"> aa=a.top();</span><br><span class="line"> a.pop();</span><br><span class="line"> <span class="keyword">if</span>(aa==<span class="number">0</span>){</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> a.push(aa/<span class="number">2</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">while</span>(!a.empty()){</span><br><span class="line"> <span class="keyword">if</span>(a.top()==<span class="number">0</span>)<span class="keyword">break</span>;</span><br><span class="line"> ans+=a.top();</span><br><span class="line"> a.pop();</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%lld\n"</span>,ans);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><a href="https://www.zhixincode.com/contest/21/problem/I?problem_id=324" target="_blank" rel="noopener"><strong>I - Sorting</strong></a></p><p>将小于等于X的数当做0,大于x的数当做1,因为交换后相对顺序不会变,就可以预处理出各自的前缀和,根据处于的位置计算值。用线段树来维护区间内01的个数,Ok啦</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br><span class="line">105</span><br><span class="line">106</span><br><span class="line">107</span><br><span class="line">108</span><br><span class="line">109</span><br><span class="line">110</span><br><span class="line">111</span><br><span class="line">112</span><br><span class="line">113</span><br><span class="line">114</span><br><span class="line">115</span><br><span class="line">116</span><br><span class="line">117</span><br><span class="line">118</span><br><span class="line">119</span><br><span class="line">120</span><br><span class="line">121</span><br><span class="line">122</span><br><span class="line">123</span><br><span class="line">124</span><br><span class="line">125</span><br><span class="line">126</span><br><span class="line">127</span><br><span class="line">128</span><br><span class="line">129</span><br><span class="line">130</span><br><span class="line">131</span><br><span class="line">132</span><br><span class="line">133</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">2e5</span>+<span class="number">10</span>;</span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ls rt<<1</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> rs rt<<1|1</span></span><br><span class="line"><span class="keyword">int</span> a[maxn],b[maxn];</span><br><span class="line"><span class="keyword">long</span> <span class="keyword">long</span> <span class="keyword">int</span> r0[maxn],r1[maxn];</span><br><span class="line"><span class="keyword">int</span> cnt1=<span class="number">1</span>,cnt0=<span class="number">1</span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">tree</span>{</span></span><br><span class="line"> <span class="keyword">int</span> l,r;</span><br><span class="line"> <span class="keyword">int</span> x;</span><br><span class="line"> <span class="keyword">int</span> sum;</span><br><span class="line"> <span class="keyword">int</span> lazy;</span><br><span class="line">}t[maxn*<span class="number">4</span>];</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">pushdown</span><span class="params">(<span class="keyword">int</span> rt)</span></span>{</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span>(t[rt].lazy==<span class="number">1</span>){</span><br><span class="line"> t[ls].sum=t[ls].r-t[ls].l+<span class="number">1</span>;</span><br><span class="line"> t[rs].sum=t[rs].r-t[rs].l+<span class="number">1</span>;</span><br><span class="line"> t[ls].lazy=<span class="number">1</span>;</span><br><span class="line"> t[rs].lazy=<span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(t[rt].lazy==<span class="number">-1</span>){</span><br><span class="line"> t[ls].sum=<span class="number">0</span>;</span><br><span class="line"> t[rs].sum=<span class="number">0</span>;</span><br><span class="line"> t[ls].lazy=<span class="number">-1</span>;</span><br><span class="line"> t[rs].lazy=<span class="number">-1</span>;</span><br><span class="line"> }</span><br><span class="line"> t[rt].lazy=<span class="number">0</span>;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">build</span><span class="params">(<span class="keyword">int</span> rt,<span class="keyword">int</span> l,<span class="keyword">int</span> r)</span></span>{</span><br><span class="line"> t[rt].l=l;</span><br><span class="line"> t[rt].r=r;</span><br><span class="line"> t[rt].x=<span class="number">0</span>;</span><br><span class="line"> t[rt].sum=<span class="number">0</span>;</span><br><span class="line"> t[rt].lazy=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">if</span>(t[rt].l==t[rt].r){</span><br><span class="line"> <span class="keyword">return</span> ;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">int</span> mid=l+r>><span class="number">1</span>;</span><br><span class="line"> build(ls,l,mid);</span><br><span class="line"> build(rs,mid+<span class="number">1</span>,r);</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">dadd</span><span class="params">(<span class="keyword">int</span> rt,<span class="keyword">int</span> x)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(t[rt].l==x && t[rt].r==x){</span><br><span class="line"> t[rt].x=<span class="number">1</span>;</span><br><span class="line"> t[rt].sum++;</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">int</span> mid=t[rt].l+t[rt].r>><span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(mid<x)</span><br><span class="line"> dadd(rs,x);</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> dadd(ls,x);</span><br><span class="line"> t[rt].sum=t[ls].sum+t[rs].sum;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">change</span><span class="params">(<span class="keyword">int</span> rt,<span class="keyword">int</span> ql,<span class="keyword">int</span> qr,<span class="keyword">int</span> l,<span class="keyword">int</span> r,<span class="keyword">int</span> x,<span class="keyword">int</span> type)</span></span>{</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span>(ql>=l && qr<=r){</span><br><span class="line"> <span class="keyword">if</span>(x==<span class="number">0</span>){</span><br><span class="line"> t[rt].sum=<span class="number">0</span>;</span><br><span class="line"> t[rt].lazy=<span class="number">-1</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> t[rt].sum=qr-ql+<span class="number">1</span>;</span><br><span class="line"> t[rt].lazy=<span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> ;</span><br><span class="line"> }</span><br><span class="line"> pushdown(rt);</span><br><span class="line"> <span class="keyword">int</span> mid=ql+qr>><span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(l<=mid)</span><br><span class="line"> change(ls,ql,mid,l,r,x,type);</span><br><span class="line"> <span class="keyword">if</span>(r>mid)</span><br><span class="line"> change(rs,mid+<span class="number">1</span>,qr,l,r,x,type);</span><br><span class="line"> t[rt].sum=t[ls].sum+t[rs].sum;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">query</span><span class="params">(<span class="keyword">int</span> rt,<span class="keyword">int</span> ql,<span class="keyword">int</span> qr,<span class="keyword">int</span> l,<span class="keyword">int</span> r)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(l>r)<span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">if</span>(ql>=l && qr<=r){</span><br><span class="line"> <span class="keyword">return</span> t[rt].sum;</span><br><span class="line"> }</span><br><span class="line"> pushdown(rt);</span><br><span class="line"> <span class="keyword">int</span> mid=ql+qr>><span class="number">1</span>;</span><br><span class="line"> <span class="keyword">int</span> sum=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">if</span>(l<=mid)</span><br><span class="line"> sum+= query(ls,ql,mid,l,r);</span><br><span class="line"> <span class="keyword">if</span>(r>mid)</span><br><span class="line"> sum+=query(rs,mid+<span class="number">1</span>,qr,l,r);</span><br><span class="line"> <span class="keyword">return</span> sum;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> n,q,x;</span><br><span class="line"> <span class="built_in">cin</span>>>n>>q>>x;</span><br><span class="line"> build(<span class="number">1</span>,<span class="number">1</span>,n);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;i++){</span><br><span class="line"> <span class="built_in">cin</span>>>a[i];</span><br><span class="line"> <span class="keyword">if</span>(a[i]<=x)r0[cnt0]=r0[cnt0++<span class="number">-1</span>]+a[i];</span><br><span class="line"> <span class="keyword">else</span> dadd(<span class="number">1</span>,i),r1[cnt1]=r1[cnt1++<span class="number">-1</span>]+a[i];</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">int</span> o,L,R;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=q;i++){</span><br><span class="line"> <span class="built_in">cin</span>>>o>>L>>R;</span><br><span class="line"> <span class="keyword">if</span>(o==<span class="number">1</span>){</span><br><span class="line"> <span class="keyword">int</span> k=query(<span class="number">1</span>,<span class="number">1</span>,n,L,R);<span class="comment">//区间内有k个1</span></span><br><span class="line"> <span class="keyword">int</span> k1=query(<span class="number">1</span>,<span class="number">1</span>,n,<span class="number">1</span>,L<span class="number">-1</span>);<span class="comment">//前面有k1个1</span></span><br><span class="line"> <span class="keyword">int</span> S=R-L+<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">int</span> k0=S-k;</span><br><span class="line"> <span class="keyword">int</span> k00=L<span class="number">-1</span>-k1;</span><br><span class="line"> <span class="keyword">long</span> <span class="keyword">long</span> <span class="keyword">int</span> sum1=r1[k1+k]-r1[k1];</span><br><span class="line"> <span class="keyword">long</span> <span class="keyword">long</span> <span class="keyword">int</span> sum0=r0[ S-k + L<span class="number">-1</span>-k1 ]-r0[L<span class="number">-1</span>-k1];</span><br><span class="line"> <span class="built_in">cout</span><<sum1 + sum0<<<span class="built_in">endl</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(o==<span class="number">2</span>){</span><br><span class="line"> <span class="keyword">int</span> k=query(<span class="number">1</span>,<span class="number">1</span>,n,L,R);<span class="comment">//区间内有k个1</span></span><br><span class="line"> <span class="keyword">int</span> k1=R-L+<span class="number">1</span>-k;<span class="comment">//k1个0</span></span><br><span class="line"> change(<span class="number">1</span>,<span class="number">1</span>,n,L,L+k1<span class="number">-1</span>,<span class="number">0</span>,<span class="number">0</span>);</span><br><span class="line"> change(<span class="number">1</span>,<span class="number">1</span>,n,L+k1,R,<span class="number">1</span>,<span class="number">1</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(o==<span class="number">3</span>){</span><br><span class="line"> <span class="keyword">int</span> k=query(<span class="number">1</span>,<span class="number">1</span>,n,L,R);<span class="comment">//区间内有k个1</span></span><br><span class="line"> <span class="keyword">int</span> k1=R-L+<span class="number">1</span>-k;<span class="comment">//k1个0</span></span><br><span class="line"> change(<span class="number">1</span>,<span class="number">1</span>,n,L,L+k<span class="number">-1</span>,<span class="number">1</span>,<span class="number">1</span>);</span><br><span class="line"> change(<span class="number">1</span>,<span class="number">1</span>,n,L+k,R,<span class="number">0</span>,<span class="number">0</span>);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><a href="https://www.zhixincode.com/contest/21/problem/J?problem_id=325" target="_blank" rel="noopener"><strong>J - Special Judge</strong></a></p><p>对任意两条边都进行判断是否相交,如果相交则在判断是否是相交于端点,不过不是则ans++。是的话在判断下是不是重合边,如果不是重合边就不符合,是就ans++.</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">node</span>{</span></span><br><span class="line"><span class="keyword">double</span> x;</span><br><span class="line"><span class="keyword">double</span> y;</span><br><span class="line">};</span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">judge</span><span class="params">(node a,node b,node c,node d)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"><span class="keyword">if</span>(min(a.x,b.x) <= max(c.x,d.x) && min(c.x,d.x) <= max(a.x,b.x) && min(a.y,b.y) <= max(c.y,d.y) &&min(c.y,d.y)<=max(a.y,b.y))</span><br><span class="line">{</span><br><span class="line"></span><br><span class="line"><span class="keyword">double</span> u,v,w,z;<span class="comment">//保存叉乘</span></span><br><span class="line"> u=(c.x-a.x)*(b.y-a.y)-(b.x-a.x)*(c.y-a.y);</span><br><span class="line"> v=(d.x-a.x)*(b.y-a.y)-(b.x-a.x)*(d.y-a.y);</span><br><span class="line"> w=(a.x-c.x)*(d.y-c.y)-(d.x-c.x)*(a.y-c.y);</span><br><span class="line"> z=(b.x-c.x)*(d.y-c.y)-(d.x-c.x)*(b.y-c.y);</span><br><span class="line"> <span class="keyword">return</span> (u*v<=<span class="number">0.00000001</span> && w*z<=<span class="number">0.00000001</span>); <span class="comment">//浮点数判断大小</span></span><br><span class="line">}</span><br><span class="line"><span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">onsegment</span><span class="params">(node pi,node pj,node Q)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">if</span>((Q.x-pi.x)*(pj.y-pi.y)==(pj.x-pi.x)*(Q.y-pi.y)&&min(pi.x,pj.x)<=Q.x&&Q.x<=max(pi.x,pj.x)&&min(pi.y,pj.y)<=Q.y&&Q.y<=max(pi.y,pj.y)){</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">check</span><span class="params">(node a,node b,node c,node d)</span></span>{</span><br><span class="line"> <span class="keyword">double</span> len=(a.x-b.x)*(c.y-d.y)-(c.x-d.x)*(a.y-b.y);</span><br><span class="line"> <span class="keyword">if</span>(len==<span class="number">0</span>)<span class="keyword">return</span> <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">1020</span>;</span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">Node</span>{</span></span><br><span class="line"> <span class="keyword">int</span> a,b;</span><br><span class="line">}mp[<span class="number">2</span>*maxn];</span><br><span class="line">node p[maxn];</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> n,m;</span><br><span class="line"> <span class="keyword">int</span> ans=<span class="number">0</span>;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d"</span>,&n,&m);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=m;i++){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d"</span>,&mp[i].a,&mp[i].b);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;i++)<span class="built_in">scanf</span>(<span class="string">"%lf%lf"</span>,&p[i].x,&p[i].y);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=m;i++){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=i+<span class="number">1</span>;j<=m;j++){</span><br><span class="line"> <span class="keyword">if</span>(judge(p[mp[i].a],p[mp[i].b],p[mp[j].a],p[mp[j].b])){</span><br><span class="line"> <span class="keyword">if</span>(mp[i].a==mp[j].a||mp[i].a==mp[j].b||mp[i].b==mp[j].a||mp[i].b==mp[j].b){<span class="comment">//判断是否是交于端点</span></span><br><span class="line"> <span class="keyword">if</span>(check(p[mp[i].a],p[mp[i].b],p[mp[j].a],p[mp[j].b])){<span class="comment">//看两边是否平行</span></span><br><span class="line"><span class="comment">//如果平行,通过判断一边的两端点是否在另外一边上</span></span><br><span class="line"> <span class="keyword">if</span>((onsegment(p[mp[j].a],p[mp[j].b],p[mp[i].a])&&onsegment(p[mp[j].a],p[mp[j].b],p[mp[i].b]))||(onsegment(p[mp[i].a],p[mp[i].b],p[mp[j].a])&&onsegment(p[mp[i].a],p[mp[i].b],p[mp[j].b])))</span><br><span class="line"> ans++;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> ans++;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d\n"</span>,ans);</span><br><span class="line"><span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h3 id="自闭感受"><a href="#自闭感受" class="headerlink" title="自闭感受"></a>自闭感受</h3><blockquote><p>参加Camp第五天,今天是<font color="Red" size="6" face="宋体">
</summary>
<category term="2019 Wannafly Winter Camp" scheme="https://anoyer.cn/categories/2019-Wannafly-Winter-Camp/"/>
<category term="Camp" scheme="https://anoyer.cn/tags/Camp/"/>
</entry>
<entry>
<title>2019 Wannafly Camp day4</title>
<link href="https://anoyer.cn/article/2019-Wannafly-Camp-day4.html"/>
<id>https://anoyer.cn/article/2019-Wannafly-Camp-day4.html</id>
<published>2019-01-23T14:12:24.000Z</published>
<updated>2019-01-27T14:30:44.530Z</updated>
<content type="html"><![CDATA[<h3 id="自闭感受"><a href="#自闭感受" class="headerlink" title="自闭感受"></a>自闭感受</h3><blockquote><p>Camp第四天,非常傻逼并快乐的一天 。</p><p>上午<font color="Red" size="6" face="宋体">Claris</font>给我们讲DP,而且从基础开始讲,虽然没有包DP,但是还是学到了不少,非常棒。中午所有人在科技楼下面来了一张大合影 <del>(寒风中瑟瑟发抖)</del> ,<font color="Blue" size="4" face="宋体">最最最最happy</font>的是找各位巨巨们要到了签名,(可惜没要到唐老师的 )</p><p><img src="https://img.vim-cn.com/86/93a9af9b0b3ccb0d10da2e94559001ee065bfb.jpg" alt=""></p><p>下午训练是目前几场最签到的场了,但是不知为啥周围加我队3队人都傻逼了,明明非常简单片面的东西看的非常复杂,真的是…不想说了,<font color="Red" size="5" face="宋体">最后吸取教训不管题目怎么样,都有保持一颗平常心态和清醒的头脑</font>。</p></blockquote><h3 id="上题解"><a href="#上题解" class="headerlink" title="上题解"></a>上题解</h3><p><a href="https://www.zhixincode.com/contest/17/problem/A?problem_id=248" target="_blank" rel="noopener"><strong>A - 夺宝奇兵</strong></a></p><p>很简单的一道题,相邻两组宝藏走法只有两种交叉走,或者平行走(就是一号第一个宝藏走到二号第二个或者一号第一个走到二号第一个),所以for扫一遍去min就可以了</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">1e5</span>+<span class="number">7</span>;</span><br><span class="line"><span class="keyword">int</span> a[maxn],b[maxn];</span><br><span class="line"><span class="function">ll <span class="title">dis</span><span class="params">(<span class="keyword">int</span> i,<span class="keyword">int</span> j)</span></span>{</span><br><span class="line"> <span class="keyword">return</span> <span class="built_in">abs</span>(a[i]-a[j])+<span class="built_in">abs</span>(b[i]-b[j]);</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> n,m;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d"</span>,&n,&m);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<<span class="number">2</span>*n;i++)<span class="built_in">scanf</span>(<span class="string">"%d%d"</span>,&a[i],&b[i]);</span><br><span class="line"> ll ans=dis(<span class="number">2</span>*n<span class="number">-1</span>,<span class="number">2</span>*n<span class="number">-2</span>);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">2</span>;i<<span class="number">2</span>*n;i+=<span class="number">2</span>){</span><br><span class="line"> ans+=min(dis(i,i<span class="number">-2</span>)+dis(i+<span class="number">1</span>,i<span class="number">-1</span>),dis(i,i<span class="number">-1</span>)+dis(i+<span class="number">1</span>,i<span class="number">-2</span>));</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%lld\n"</span>,ans);</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><a href="https://www.zhixincode.com/contest/17/problem/C?problem_id=250" target="_blank" rel="noopener"><strong>C - 最小边覆盖</strong></a></p><p>最小边覆盖,不能有多余的边重复覆盖点。所以如果发现一个点被多余的覆盖了就不是最小点覆盖</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">2e5</span>+<span class="number">10</span>;</span><br><span class="line"><span class="keyword">int</span> in[maxn],u[maxn],v[maxn];</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> n,m;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d"</span>,&n,&m);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=m;i++){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d"</span>,&u[i],&v[i]);</span><br><span class="line"> in[u[i]]++;</span><br><span class="line"> in[v[i]]++;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=m;i++){</span><br><span class="line"> <span class="keyword">if</span>(in[u[i]]><span class="number">1</span> && in[v[i]]><span class="number">1</span>){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"No\n"</span>);</span><br><span class="line"> <span class="built_in">exit</span>(<span class="number">0</span>);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"Yes\n"</span>);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><a href="https://www.zhixincode.com/contest/17/problem/F?problem_id=253" target="_blank" rel="noopener"><strong>F - 小小马</strong></a></p><p>因为走法比较特殊,如果当前xy奇偶性相同,下一步则必定不同,所以黑白格子是轮流出现的,这样就可以根据起点和终点的奇偶性判断是否黑格数等于白格数了。同时可以发现只有棋盘大于3 <em>4可以从一个点到达棋盘任何点, 3</em> 3的棋盘除去中心点其余点都能相互走到,其他棋盘情况就看看从起点和终点xy的关系,如果a%2==0&&(a/2)%2==1&&b==1则可以走。</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> n,m,sx,sy,ex,ey;</span><br><span class="line"> <span class="built_in">cin</span>>>n>>m>>sx>>sy>>ex>>ey;</span><br><span class="line"> <span class="keyword">if</span>(n>=<span class="number">3</span>&&m>=<span class="number">3</span>){</span><br><span class="line"> <span class="keyword">if</span>((n==<span class="number">3</span>&&m==<span class="number">3</span>)&&(sx==<span class="number">2</span>&&sy==<span class="number">2</span>)||(ex==<span class="number">2</span>&&sy==<span class="number">2</span>)){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"No\n"</span>);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>((sx%<span class="number">2</span>+sy%<span class="number">2</span>)%<span class="number">2</span>==(ex%<span class="number">2</span>+ey%<span class="number">2</span>)%<span class="number">2</span>)<span class="built_in">printf</span>(<span class="string">"No\n"</span>);</span><br><span class="line"> <span class="keyword">else</span> <span class="built_in">printf</span>(<span class="string">"Yes\n"</span>);</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">int</span> a=max(<span class="built_in">abs</span>(sy-ey),<span class="built_in">abs</span>(sx-ex)),b=min(<span class="built_in">abs</span>(sy-ey),<span class="built_in">abs</span>(sx-ex));</span><br><span class="line"> <span class="keyword">if</span>(a%<span class="number">2</span>==<span class="number">0</span>&&(a/<span class="number">2</span>)%<span class="number">2</span>==<span class="number">1</span>&&b==<span class="number">1</span>)</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"Yes\n"</span>);</span><br><span class="line"> <span class="keyword">else</span> <span class="built_in">printf</span>(<span class="string">"No\n"</span>);</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><a href="https://www.zhixincode.com/contest/17/problem/G" target="_blank" rel="noopener"><strong>G - 置置置换</strong></a></p><p>定义dp[i][j]为 i个数的排列中,最后一个数字为j</p><p>当i为偶数的时候,位于山谷,需要前面大于他<br><code>dp[i][j]+=dp[i-1][k], j<=k<=i-1</code><br>之所以可以这么写是因为,前面并没有出现i这个数字,所以也没有计算dp[i-1][i],但是有个巧妙的做法<br>假设把前面所有大于等于j的数+1,就刚好解决这个问题了。</p><p>当i为奇数的时候,位于山峰,需要前面小于他<br><code>dp[i][j]+=dp[i-1][k], 1<=k<=j-1;</code><br>这个很显然直接写是n^3,可以使用前缀和优化</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">2e5</span>+<span class="number">10</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> MOD=<span class="number">1e9</span>+<span class="number">7</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line">ll dp[<span class="number">1010</span>][<span class="number">1010</span>];</span><br><span class="line"><span class="keyword">int</span> sum[maxn];</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> n;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&n);</span><br><span class="line"> dp[<span class="number">1</span>][<span class="number">1</span>]=<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">2</span>;i<=n;i++){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j<=i;j++){</span><br><span class="line"> <span class="keyword">if</span>(i&<span class="number">1</span>)<span class="comment">//奇数,升序 从1->(j-1)转移</span></span><br><span class="line"> dp[i][j]=(dp[i][j<span class="number">-1</span>]+dp[i<span class="number">-1</span>][j<span class="number">-1</span>]+MOD)%MOD;<span class="comment">//前缀和优化</span></span><br><span class="line"> <span class="keyword">else</span>{<span class="comment">//偶数,降序 从j -> i转移</span></span><br><span class="line"> dp[i][j]=(dp[i][j<span class="number">-1</span>]+dp[i<span class="number">-1</span>][i<span class="number">-1</span>]-dp[i<span class="number">-1</span>][j<span class="number">-1</span>]+MOD)%MOD;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%lld\n"</span>,dp[n][n]);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><a href="https://www.zhixincode.com/contest/17/problem/I?problem_id=256" target="_blank" rel="noopener"><strong>I - 咆咆咆哮</strong></a></p><p>基本思路就是贪心枚举选a的数量num,去选择num个对ans贡献最大a,然后ans取min。</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">1e3</span>+<span class="number">7</span>;</span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">Node</span>{</span></span><br><span class="line"> <span class="keyword">int</span> a,b;</span><br><span class="line">}a[maxn];</span><br><span class="line"><span class="keyword">int</span> num;</span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">cmp</span><span class="params">(Node a,Node b)</span></span>{</span><br><span class="line"> <span class="keyword">return</span> a.a-num*a.b>b.a-num*b.b;</span><br><span class="line"></span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> n;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&n);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<n;i++){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d"</span>,&a[i].a,&a[i].b);</span><br><span class="line"> }</span><br><span class="line"> ll ans=<span class="number">0</span>,anss=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(num=<span class="number">1</span>;num<=n;num++){</span><br><span class="line"> sort(a,a+n,cmp);</span><br><span class="line"> anss=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<num;i++)anss+=a[i].a;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=num;i<n;i++)anss+=num*a[i].b;</span><br><span class="line"> ans=max(ans,anss);</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%lld\n"</span>,ans);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h3 id="自闭感受"><a href="#自闭感受" class="headerlink" title="自闭感受"></a>自闭感受</h3><blockquote><p>Camp第四天,非常傻逼并快乐的一天 。</p><p>上午<font color="Red" si
</summary>
<category term="2019 Wannafly Winter Camp" scheme="https://anoyer.cn/categories/2019-Wannafly-Winter-Camp/"/>
<category term="Camp" scheme="https://anoyer.cn/tags/Camp/"/>
</entry>
<entry>
<title>2019 Wannafly Camp day3</title>
<link href="https://anoyer.cn/article/2019-Wannafly-Camp-day3.html"/>
<id>https://anoyer.cn/article/2019-Wannafly-Camp-day3.html</id>
<published>2019-01-22T08:46:05.000Z</published>
<updated>2019-01-26T03:08:03.583Z</updated>
<content type="html"><![CDATA[<h3 id="自闭感受"><a href="#自闭感受" class="headerlink" title="自闭感受"></a>自闭感受</h3><blockquote><p>参加Camp的第三天,上午是数据结构专题分享,<font color="Red" size="6" face="宋体">dls</font> <del><font color="Blue" size="face=">不打CF,分数可能比我们都低的2300分只打过三场的巨巨队友</font></del> <font color="orange" size="6" face="宋体">wls</font>来给我们讲的 。比起昨天的数论专场,今天感觉好多了,懵逼少很多还能跟上节奏。wls是带着题目来给我们讲常见的数据结构运用,比如堆,并查集,线段树,平衡树等等。下午原本以为是数据结构专题训练,便戏耍的和lyy说下午你专场我回去了哈 。结果下午题目比day1,day2还难,而且不是想象中的数据结构专题。一开始我便瞄到了F题,好眼熟!!!这不是莫比乌斯反演吗?就开始怼了。lyy开了D,结果这 SB不会写,我先放了下F题,看了下G题发现G题是个签到题 <del>(上面写的)</del> 。我就叫他看G,然后我切回了我的F。一波推式子,发现思路可行就巴拉巴拉敲了起来,中间因为炸int问题wa了几发,SB了!队友G题比我先过了,确实是个签到题 。最后有个乌龙,4点多的样子,队友和旁队的一起随机猜吧A题(因为只有2组数据,一共就1024种情况),竟然A了,然后大喊了一声答案,果断一波A的AC流。不知道出题人看到会心咋想</p><p>感受:非常难得场上A出一道正儿八经的数论反演题,开森,同时发现队伍配合实在差,必须好好抓抓,不然要GG,尤其新人。</p></blockquote><h3 id="上题解(后期补题会更新其他能力范围内的题解)"><a href="#上题解(后期补题会更新其他能力范围内的题解)" class="headerlink" title="上题解(后期补题会更新其他能力范围内的题解)"></a>上题解(后期补题会更新其他能力范围内的题解)</h3><p><a href="https://www.zhixincode.com/contest/13/problem/F?problem_id=198" target="_blank" rel="noopener"><strong>F - 小清新数论</strong></a></p><p>做法一:欧拉函数</p><p><img src="https://img.vim-cn.com/38/bab153e92bc0ebeb28f1298554313cc751d7d9.png" alt=""></p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> LL long long</span></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn = <span class="number">1e7</span>+<span class="number">9</span>;</span><br><span class="line"><span class="keyword">const</span> LL mod = <span class="number">998244353</span>;</span><br><span class="line">LL phi[maxn],miu[maxn],fac[maxn];<span class="comment">//phi--欧拉函数表 miu--莫比乌斯函数表 fac--i最大的素因子辅助打phi表</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">init</span><span class="params">()</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">1</span>; i < maxn; ++i) fac[i] = i;</span><br><span class="line">phi[<span class="number">1</span>] = miu[<span class="number">1</span>] = <span class="number">1</span>;</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> i = <span class="number">2</span>; i < maxn; ++i)</span><br><span class="line">{</span><br><span class="line"><span class="keyword">if</span> (fac[i] == i)</span><br><span class="line"><span class="keyword">for</span> (<span class="keyword">int</span> j = i << <span class="number">1</span>; j < maxn; j += i)</span><br><span class="line">fac[j] = i;</span><br><span class="line"><span class="keyword">if</span> (i / fac[i] % fac[i]) phi[i] = (fac[i] - <span class="number">1</span>)*phi[i / fac[i]], miu[i] = -miu[i / fac[i]]; <span class="comment">//如果b质数 a%b!=0 phi(a*b) = phi(a)*b - phi(a)</span></span><br><span class="line"><span class="keyword">else</span> phi[i] = fac[i] * phi[i / fac[i]], miu[i] = <span class="number">0</span>;<span class="comment">//当b是质数,a%b==0,phi(a*b)=phi(a)*b</span></span><br><span class="line">}</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<maxn;i++)phi[i]=phi[i]+phi[i<span class="number">-1</span>];</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> init();</span><br><span class="line"> LL n;</span><br><span class="line"> <span class="built_in">cin</span>>>n;</span><br><span class="line"> LL NN=n;</span><br><span class="line"> LL ans=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(LL i=<span class="number">1</span>;i<=NN;i++){</span><br><span class="line"> LL res=(phi[NN/i]*(LL)<span class="number">2</span><span class="number">-1</span>)%mod;</span><br><span class="line"> ans=(ans+miu[i]*res%mod)%mod;</span><br><span class="line"> <span class="keyword">while</span>(ans<<span class="number">0</span>)ans+=mod;</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%lld\n"</span>,ans);</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>做法二:莫比乌斯反演</p><p><img src="https://img.vim-cn.com/3a/35d7086a95b8df2e7f472561afaa9574aa28a7.png" alt=""></p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> mod=<span class="number">998244353</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">1e7</span>+<span class="number">1</span>;</span><br><span class="line">ll phi[maxn],miu[maxn],vis[maxn];</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">init</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<maxn;++i)vis[i]=i;</span><br><span class="line"> phi[<span class="number">1</span>]=miu[<span class="number">1</span>]=<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">2</span>;i<maxn;i++){</span><br><span class="line"> <span class="keyword">if</span>(vis[i]==i){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=i<<<span class="number">1</span>;j<maxn;j+=i)vis[j]=i;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(i/vis[i]%vis[i])miu[i]= -miu[i/vis[i]];</span><br><span class="line"> <span class="keyword">else</span> miu[i]=<span class="number">0</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<maxn;i++)miu[i]=miu[i]+miu[i<span class="number">-1</span>];</span><br><span class="line">}</span><br><span class="line"><span class="function">ll <span class="title">solve</span><span class="params">(<span class="keyword">int</span> n,<span class="keyword">int</span> m)</span></span>{</span><br><span class="line"> ll ans=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">int</span> N=min(n,m),r;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> l =<span class="number">1</span>;l<=N;l=r+<span class="number">1</span>){</span><br><span class="line"> r=min(n/(n/l),m/(m/l)); <span class="comment">//取分块小的数</span></span><br><span class="line"> ll res=(miu[r]-miu[l<span class="number">-1</span>]+mod)%mod*(n/l)%mod*(n/l)%mod; <span class="comment">//miu[r]-miu[l-1]表示l~r区间miu和,</span></span><br><span class="line"> ans=(ans+res+mod)%mod;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> ans;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> init();</span><br><span class="line"> <span class="keyword">int</span> n,r;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&n);</span><br><span class="line"> ll ans=<span class="number">0</span>,res;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> l=<span class="number">1</span>;l<=n;l=r+<span class="number">1</span>){</span><br><span class="line"> r=n/(n/l);</span><br><span class="line"> res=(miu[r]-miu[l<span class="number">-1</span>]+mod)%mod*solve(n/l,n/l)%mod;</span><br><span class="line"> ans=(ans+res+mod)%mod;</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%lld\n"</span>,ans);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p>做法三:杜教筛能过div1,跑了1423ms,对做法一中欧拉函数前n项和,欧拉函数前n项和进行杜教筛,然后套一个分块求解</p><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br></pre></td><td class="code"><pre><span class="line">#include<stdio.h></span><br><span class="line">#include<bits/stdc++.h></span><br><span class="line">#include<tr1/unordered_map></span><br><span class="line">#define INV2 499122177</span><br><span class="line">using namespace std;</span><br><span class="line">typedef long long ll;</span><br><span class="line">const int N=1e7+20;</span><br><span class="line">const int mod=998244353;</span><br><span class="line">bool vis[N];</span><br><span class="line">int mu[N],sum1[N];</span><br><span class="line">long long phi[N],sum2[N];</span><br><span class="line">int cnt,prim[N];</span><br><span class="line">int e,e1;</span><br><span class="line">tr1::unordered_map<long long,long long>w,w1; //哈希 w用来求phi前缀和 w1用来求miu前缀和</span><br><span class="line">void get(int maxn)</span><br><span class="line">{</span><br><span class="line"> phi[1]=mu[1]=1;</span><br><span class="line"> for(int i=2;i<=maxn;i++)</span><br><span class="line"> {</span><br><span class="line"> if(!vis[i])</span><br><span class="line"> {</span><br><span class="line"> prim[++cnt]=i;</span><br><span class="line"> mu[i]=-1;phi[i]=i-1;</span><br><span class="line"> }</span><br><span class="line"> for(int j=1;j<=cnt&&prim[j]*i<=maxn;j++)</span><br><span class="line"> {</span><br><span class="line"> vis[i*prim[j]]=1;</span><br><span class="line"> if(i%prim[j]==0)</span><br><span class="line"> {</span><br><span class="line"> phi[i*prim[j]]=phi[i]*prim[j];</span><br><span class="line"> break;</span><br><span class="line"> }</span><br><span class="line"> else mu[i*prim[j]]=-mu[i],phi[i*prim[j]]=phi[i]*(prim[j]-1);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> for(int i=1;i<=maxn;i++)sum1[i]=sum1[i-1]+mu[i],sum2[i]=(sum2[i-1]+phi[i])%mod; //打一个maxn的phi前缀和表 和miu前缀和表</span><br><span class="line">}</span><br><span class="line">int djsmu(long long x)//求miu前缀和</span><br><span class="line">{</span><br><span class="line"> if(x<=10000000)return sum1[x];</span><br><span class="line"> if(w[x])return w[x];</span><br><span class="line"> int ans=1;</span><br><span class="line"> for(long long l=2,r;l<=x;l=r+1)</span><br><span class="line"> {</span><br><span class="line"> r=x/(x/l);</span><br><span class="line"> ans-=(r-l+1ll)*djsmu(x/l);</span><br><span class="line"> }</span><br><span class="line"> return w[x]=ans;</span><br><span class="line">}</span><br><span class="line">long long djsphi(long long x)//求phi 前缀和</span><br><span class="line">{</span><br><span class="line"> if(x<=10000000)return sum2[x];</span><br><span class="line"> if(w1[x])return w1[x];</span><br><span class="line"> long long ans=x%mod*(x+1)%mod*INV2%mod;</span><br><span class="line"> for(long long l=2,r;l<=x;l=r+1)</span><br><span class="line"> {</span><br><span class="line"> r=x/(x/l);</span><br><span class="line"> ans=(ans-(r-l+1)%mod*djsphi(x/l)+mod)%mod;</span><br><span class="line"> }</span><br><span class="line"> while(ans<0)ans+=mod;</span><br><span class="line"> return w1[x]=ans%mod;</span><br><span class="line">}</span><br><span class="line">int main(){</span><br><span class="line"> get(10000000);</span><br><span class="line"> ll n,r;</span><br><span class="line"> scanf("%lld",&n);</span><br><span class="line"> ll ans=0,res;</span><br><span class="line"> for(ll l=1;l<=n;l=r+1){</span><br><span class="line"> r=n/(n/l);</span><br><span class="line"> res=(ll)(djsmu(r)-djsmu(l-1)+mod)%mod*((djsphi(n/l)%mod*(ll)2%mod-1+mod)%mod)%mod;</span><br><span class="line"> ans=(ans+res+mod)%mod;</span><br><span class="line"> }</span><br><span class="line"> printf("%lld\n",ans);</span><br><span class="line"> return 0;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><a href="https://www.zhixincode.com/contest/13/problem/G?problem_id=199" target="_blank" rel="noopener">G - 排列**</a></p><p>搞清楚每个数组都是干什么的。</p><ul><li>P 原数组</li><li>Ap 前缀数组</li><li>q Ap中第i大的位置(相同的先取左边,例如 AP={2,1, 1},第1小的位置是2而不是3.)</li></ul><p>现在题目给了q,可以根据q倒推出Ap,然后倒推出P</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line">include<stdio.h></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn =<span class="number">1e5</span>+<span class="number">10</span>;</span><br><span class="line"><span class="keyword">int</span> a[maxn];</span><br><span class="line"><span class="keyword">int</span> q[maxn];</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> n;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&n);</span><br><span class="line"> <span class="keyword">int</span> cnt=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">int</span> pre=maxn+<span class="number">10</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;i++){</span><br><span class="line"><span class="built_in">scanf</span>(<span class="string">"%d"</span>,&a[i]);</span><br><span class="line"><span class="keyword">if</span>(a[i]>pre)</span><br><span class="line">q[a[i]]=cnt;</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">q[a[i]]=++cnt;</span><br><span class="line">pre=a[i];</span><br><span class="line"> }</span><br><span class="line"> cnt=q[<span class="number">1</span>];</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d "</span>,cnt);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">2</span>;i<=n;i++){</span><br><span class="line"> <span class="keyword">if</span>(q[i]<q[i<span class="number">-1</span>])</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d "</span>,q[i]);</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d "</span>,++cnt);</span><br><span class="line"></span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h3 id="自闭感受"><a href="#自闭感受" class="headerlink" title="自闭感受"></a>自闭感受</h3><blockquote><p>参加Camp的第三天,上午是数据结构专题分享,<font color="Red" size="6"
</summary>
<category term="2019 Wannafly Winter Camp" scheme="https://anoyer.cn/categories/2019-Wannafly-Winter-Camp/"/>
<category term="Camp" scheme="https://anoyer.cn/tags/Camp/"/>
</entry>
<entry>
<title>2019 Wannafly Camp day2</title>
<link href="https://anoyer.cn/article/2019-Wannafly-Camp-day2.html"/>
<id>https://anoyer.cn/article/2019-Wannafly-Camp-day2.html</id>
<published>2019-01-21T14:23:52.000Z</published>
<updated>2019-01-26T03:07:40.209Z</updated>
<content type="html"><![CDATA[<h3 id="自闭感受"><a href="#自闭感受" class="headerlink" title="自闭感受"></a>自闭感受</h3><blockquote><p>今天上午<font color="Red" size="9" face="宋体">吉老师</font>吉老师给我们讲了一通数论知识,可以说是醍醐灌顶吧,半懂半懵<del>(简单的懂了,难的n^n脸懵逼)</del>,真的是菜的教不来啊 <del><font color="Blue" size="1" face="宋体">不过吉老师不亏是WF金牌爷,属实强大啊</font></del>。下午数论自闭专场(好像大部分数论题都没几个做出来的 ),自闭场了就写出2道题AH,有点难受,K题队友T了,B吃饭时候想出了正确的贪心策略。</p><p>开始我先开的A题,队友lyy和hxx开了K题,同时写崩,A题写半天发现怼的是div1的B题,K题lyy先T。后来A题瞎几把想了个假的贪心,贪最大值,果断wa了3发,发现是个假策略并算了算复杂度发现直接n方暴力。然后hxx的k也T了,对拍了波两人代码,发现没错误,那就凉了假算法。此时lyy便切到了B题,我开了H题,发现是个求球交体积的题目,取横截面积进行微积分<del>(我有板子自己裸板子过的)</del>,在这题还闹了个乌龙,样例完全正确后,我交了H并和队友说了句过了,队友说小心WA,秒回了“样例过了就是过了”,结果CE ,有个结构体函数忘了函数类型,改改就A了。H过后便和lyy开始怼B题,因为K题实在不会了,目测是状压DP不会写。B题HACK了好几个YY出来的的假贪心策略之后,就直接去吃饭了,吃饭时候想到了贪长度,可惜已经GG了。</p><p>今天虽然是数论专场,但是感觉打脸最多的就是自己的假贪心策略,以后想出的策略觉得要证明正确性再写,一定不要莽</p></blockquote><h3 id="上题解(后期补题会更新其他能力范围内的题解)"><a href="#上题解(后期补题会更新其他能力范围内的题解)" class="headerlink" title="上题解(后期补题会更新其他能力范围内的题解)"></a>上题解(后期补题会更新其他能力范围内的题解)</h3><p><a href="https://www.zhixincode.com/contest/8/problem/A?problem_id=122" target="_blank" rel="noopener"><strong>A-Erase Numbers II</strong></a></p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> ull unsigned long long</span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn = <span class="number">6e3</span> + <span class="number">10</span>;</span><br><span class="line">ull a[maxn];</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">slove</span><span class="params">(ull &a, ull b)</span></span>{</span><br><span class="line"> <span class="keyword">while</span>(b){</span><br><span class="line"> a *= <span class="number">10</span>;</span><br><span class="line"> b /= <span class="number">10</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> t, t1 = <span class="number">1</span>;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &t);</span><br><span class="line"> <span class="keyword">while</span>(t--){</span><br><span class="line"> <span class="keyword">int</span> n;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &n);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i < n; ++i)</span><br><span class="line"> <span class="built_in">cin</span> >> a[i];</span><br><span class="line"> ull ans = <span class="number">0</span>, temp;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i = <span class="number">0</span>; i < n - <span class="number">1</span>; ++i){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j = i + <span class="number">1</span>; j < n; ++j){</span><br><span class="line"> temp = a[i];</span><br><span class="line"> slove(temp, a[j]);</span><br><span class="line"> ans = max(ans, temp + a[j]);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">cout</span> << <span class="string">"Case #"</span> << t1++ << <span class="string">": "</span> << ans << <span class="built_in">endl</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><a href="https://www.zhixincode.com/contest/8/problem/H?problem_id=129" target="_blank" rel="noopener"><strong>H-Cosmic Cleaner</strong></a></p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br><span class="line">71</span><br><span class="line">72</span><br><span class="line">73</span><br><span class="line">74</span><br><span class="line">75</span><br><span class="line">76</span><br><span class="line">77</span><br><span class="line">78</span><br><span class="line">79</span><br><span class="line">80</span><br><span class="line">81</span><br><span class="line">82</span><br><span class="line">83</span><br><span class="line">84</span><br><span class="line">85</span><br><span class="line">86</span><br><span class="line">87</span><br><span class="line">88</span><br><span class="line">89</span><br><span class="line">90</span><br><span class="line">91</span><br><span class="line">92</span><br><span class="line">93</span><br><span class="line">94</span><br><span class="line">95</span><br><span class="line">96</span><br><span class="line">97</span><br><span class="line">98</span><br><span class="line">99</span><br><span class="line">100</span><br><span class="line">101</span><br><span class="line">102</span><br><span class="line">103</span><br><span class="line">104</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">double</span> PI = <span class="built_in">acos</span>(<span class="number">-1.0</span>);</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">120</span>;</span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">point</span> {</span></span><br><span class="line"> <span class="keyword">double</span> x,y,z;</span><br><span class="line"> point() {}</span><br><span class="line"> <span class="function"><span class="keyword">void</span> <span class="title">Init</span><span class="params">(<span class="keyword">double</span> a, <span class="keyword">double</span> b,<span class="keyword">double</span> c)</span></span>{</span><br><span class="line"> x = a;</span><br><span class="line"> y = b;</span><br><span class="line"> z = c;</span><br><span class="line"> }</span><br><span class="line"> point(<span class="keyword">double</span> a, <span class="keyword">double</span> b,<span class="keyword">double</span> c){</span><br><span class="line"> x = a;</span><br><span class="line"> y = b;</span><br><span class="line"> z = c;</span><br><span class="line"> }</span><br><span class="line"> point <span class="keyword">operator</span> -(<span class="keyword">const</span> point &b)<span class="keyword">const</span> { <span class="comment">//返回减去后的新点</span></span><br><span class="line"> <span class="keyword">return</span> point(x - b.x, y - b.y,z-b.z);</span><br><span class="line"> }</span><br><span class="line"> point <span class="keyword">operator</span> +(<span class="keyword">const</span> point &b)<span class="keyword">const</span> { <span class="comment">//返回加上后的新点</span></span><br><span class="line"> <span class="keyword">return</span> point(x + b.x, y + b.y,z+b.z);</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">//数乘计算</span></span><br><span class="line"> point <span class="keyword">operator</span> *(<span class="keyword">const</span> <span class="keyword">double</span> &k)<span class="keyword">const</span> { <span class="comment">//返回相乘后的新点</span></span><br><span class="line"> <span class="keyword">return</span> point(x * k, y * k,z*k);</span><br><span class="line"> }</span><br><span class="line"> point <span class="keyword">operator</span> /(<span class="keyword">const</span> <span class="keyword">double</span> &k)<span class="keyword">const</span> { <span class="comment">//返回相除后的新点</span></span><br><span class="line"> <span class="keyword">return</span> point(x / k, y / k,z/k);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">double</span> <span class="keyword">operator</span> *(<span class="keyword">const</span> point &b)<span class="keyword">const</span> { <span class="comment">//点乘</span></span><br><span class="line"> <span class="keyword">return</span> x*b.x + y*b.y+z*b.z;</span><br><span class="line"> }</span><br><span class="line">};</span><br><span class="line"><span class="function"><span class="keyword">double</span> <span class="title">dist</span><span class="params">(point p1, point p2)</span> </span>{ <span class="comment">//返回平面上两点距离</span></span><br><span class="line"> <span class="keyword">return</span> <span class="built_in">sqrt</span>((p1 - p2)*(p1 - p2));</span><br><span class="line">}</span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">sphere</span> {</span><span class="comment">//球</span></span><br><span class="line"> <span class="keyword">double</span> r;</span><br><span class="line"> point centre;</span><br><span class="line">};</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">SphereInterVS</span><span class="params">(sphere a, sphere b,<span class="keyword">double</span> &v)</span> </span>{</span><br><span class="line"> <span class="keyword">double</span> d = dist(a.centre, b.centre);<span class="comment">//球心距</span></span><br><span class="line"> <span class="keyword">if</span>(d>=a.r+b.r)<span class="keyword">return</span>;</span><br><span class="line"> <span class="keyword">if</span>(a.r-d>=b.r){</span><br><span class="line"> v+=PI*<span class="number">4.0</span>/<span class="number">3.0</span>*b.r*b.r*b.r;</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(a.r<=b.r-d){</span><br><span class="line"> v+=PI*<span class="number">4.0</span>/<span class="number">3.0</span>*a.r*a.r*a.r;</span><br><span class="line"> <span class="keyword">return</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">double</span> t = (d*d + a.r*a.r - b.r*b.r) / (<span class="number">2.0</span> * d);<span class="comment">//</span></span><br><span class="line"> <span class="keyword">double</span> h = <span class="built_in">sqrt</span>((a.r*a.r) - (t*t)) * <span class="number">2</span>;<span class="comment">//h1=h2,球冠的高</span></span><br><span class="line"> <span class="keyword">double</span> angle_a = <span class="number">2</span> * <span class="built_in">acos</span>((a.r*a.r + d*d - b.r*b.r) / (<span class="number">2.0</span> * a.r*d)); <span class="comment">//余弦公式计算r1对应圆心角,弧度</span></span><br><span class="line"> <span class="keyword">double</span> angle_b = <span class="number">2</span> * <span class="built_in">acos</span>((b.r*b.r + d*d - a.r*a.r) / (<span class="number">2.0</span> * b.r*d)); <span class="comment">//余弦公式计算r2对应圆心角,弧度</span></span><br><span class="line"> <span class="keyword">double</span> l1 = ((a.r*a.r - b.r*b.r) / d + d) / <span class="number">2</span>;</span><br><span class="line"> <span class="keyword">double</span> l2 = d - l1;</span><br><span class="line"> <span class="keyword">double</span> x1 = a.r - l1, x2 = b.r - l2;<span class="comment">//分别为两个球缺的高度</span></span><br><span class="line"> <span class="keyword">double</span> v1 = PI*x1*x1*(a.r - x1 / <span class="number">3</span>);<span class="comment">//相交部分r1圆所对应的球缺部分体积</span></span><br><span class="line"> <span class="keyword">double</span> v2 = PI*x2*x2*(b.r - x2 / <span class="number">3</span>);<span class="comment">//相交部分r2圆所对应的球缺部分体积</span></span><br><span class="line"> v += v1 + v2;<span class="comment">//相交部分体积</span></span><br><span class="line">}</span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">Node</span>{</span></span><br><span class="line"> <span class="keyword">double</span> x,y,z,r;</span><br><span class="line">}a[maxn];</span><br><span class="line"><span class="keyword">double</span> x,y,z,r;</span><br><span class="line"><span class="keyword">int</span> n;</span><br><span class="line"><span class="function"><span class="keyword">double</span> <span class="title">Solve</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">double</span> v=<span class="number">0</span>;</span><br><span class="line"> sphere A,B;</span><br><span class="line"> A.r=r;</span><br><span class="line"> A.centre.Init(x,y,z);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<n;i++){</span><br><span class="line"> B.r=a[i].r;</span><br><span class="line"> B.centre.Init(a[i].x,a[i].y,a[i].z);</span><br><span class="line"> SphereInterVS(A,B,v);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> v;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> t,tt=<span class="number">1</span>;</span><br><span class="line"> <span class="comment">/*sphere A,B;</span></span><br><span class="line"><span class="comment"> A.r=1;</span></span><br><span class="line"><span class="comment"> A.centre.Init(0,0,0);</span></span><br><span class="line"><span class="comment"> B.r=1;</span></span><br><span class="line"><span class="comment"> B.centre.Init(0,0,0);</span></span><br><span class="line"><span class="comment"> double v=0;</span></span><br><span class="line"><span class="comment"> SphereInterVS(A,B,v);</span></span><br><span class="line"><span class="comment"> printf("%lf",v);*/</span></span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&t);</span><br><span class="line"> <span class="keyword">while</span>(tt<=t){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&n);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<n;i++){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%lf%lf%lf%lf"</span>,&a[i].x,&a[i].y,&a[i].z,&a[i].r);</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%lf%lf%lf%lf"</span>,&x,&y,&z,&r);</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"Case #%d: %.10lf\n"</span>,tt++,Solve());</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h3 id="自闭感受"><a href="#自闭感受" class="headerlink" title="自闭感受"></a>自闭感受</h3><blockquote><p>今天上午<font color="Red" size="9" face="宋体">吉老师</font
</summary>
<category term="2019 Wannafly Winter Camp" scheme="https://anoyer.cn/categories/2019-Wannafly-Winter-Camp/"/>
<category term="Camp" scheme="https://anoyer.cn/tags/Camp/"/>
</entry>
<entry>
<title>2019 Wannafly Camp Day1</title>
<link href="https://anoyer.cn/article/2019-Wannafly-Camp-day1.html"/>
<id>https://anoyer.cn/article/2019-Wannafly-Camp-day1.html</id>
<published>2019-01-20T14:19:23.000Z</published>
<updated>2019-01-27T11:03:59.008Z</updated>
<content type="html"><![CDATA[<h3 id="自闭感受"><a href="#自闭感受" class="headerlink" title="自闭感受"></a>自闭感受</h3><blockquote><p>第一次参加这种线下的算法Camp,不得不说和队友都是内心非常的小鸡动。上午开幕式<font color="Red" size="6" face="宋体">wls</font>讲了一堆话,差不多就是一起呲逼加鸡汤吧<del>(哈哈希望wls不要打死我)</del>。下午就是day训练赛了,因为一个主力队友生病没来,带着一个新队友2排,直接跳过了图论和DP题,差点就死怼C构造和E暴零自闭了,最后发现J题原题一发A,最后C题放弃了构造去写了100*100的暴力过了<del>(抹汗)</del>。自己还是太菜了,还有好多成长空间,细节,第一解题反应,耐心等等。</p></blockquote><h3 id="不多说上题解(后期补题会更新其他能力范围内的题解)"><a href="#不多说上题解(后期补题会更新其他能力范围内的题解)" class="headerlink" title="不多说上题解(后期补题会更新其他能力范围内的题解)"></a>不多说上题解(后期补题会更新其他能力范围内的题解)</h3><p><a href="https://www.zhixincode.com/contest/1/problem/B?problem_id=13" target="_blank" rel="noopener"><strong>B-吃豆豆</strong></a></p><p>思路:3维DP维护一个3维数组,表示(i,j)位置第K秒有多少糖果,通过k-1秒5个位置转移得到(i,j,k)</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">10010</span>;</span><br><span class="line"><span class="keyword">int</span> dp[<span class="number">20</span>][<span class="number">20</span>][maxn];</span><br><span class="line"><span class="keyword">int</span> mp[<span class="number">20</span>][<span class="number">20</span>];</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> n,m,c,xs,ys,xt,yt;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d%d"</span>,&n,&m,&c);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;i++)</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j<=m;j++)<span class="built_in">scanf</span>(<span class="string">"%d"</span>,&mp[i][j]);</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d%d%d"</span>,&xs,&ys,&xt,&yt);</span><br><span class="line"> <span class="built_in">memset</span>(dp,<span class="number">-0x3f</span>,<span class="keyword">sizeof</span>(dp));</span><br><span class="line"> dp[xs][ys][<span class="number">0</span>]=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> k=<span class="number">1</span>;k<maxn;k++)</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;i++)</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j<=m;j++){</span><br><span class="line"> dp[i][j][k]=max({dp[i<span class="number">-1</span>][j][k<span class="number">-1</span>],dp[i][j+<span class="number">1</span>][k<span class="number">-1</span>],dp[i+<span class="number">1</span>][j][k<span class="number">-1</span>],dp[i][j<span class="number">-1</span>][k<span class="number">-1</span>],dp[i][j][k<span class="number">-1</span>]})+(k%mp[i][j]==<span class="number">0</span>?<span class="number">1</span>:<span class="number">0</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">int</span> _max=<span class="number">-1</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<maxn;i++)<span class="keyword">if</span>(dp[xt][yt][i]>=c){_max=i;<span class="keyword">break</span>;}</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d\n"</span>,_max);</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><a href="https://www.zhixincode.com/contest/1/problem/C?problem_id=14" target="_blank" rel="noopener"><strong>C-拆拆拆数</strong></a></p><p>思路:题目只有1和2的情况,如果ab互质则为1,如果不互质n为2,且一定存在答案(第一感觉是这样)。开始我对n=2的情况去构造,发现一直wa<del>(菜哭了)</del>,后来A了J题后重新换了100*100暴力枚举两组ai,bi。</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">1e9</span>+<span class="number">7</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> mod=<span class="number">1e5</span>+<span class="number">7</span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">int</span> t;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&t);</span><br><span class="line"> <span class="keyword">while</span>(t--){</span><br><span class="line"> ll a,b;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%lld%lld"</span>,&a,&b);</span><br><span class="line"> <span class="keyword">if</span>(__gcd(a,b)==<span class="number">1</span>){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"1\n%lld %lld\n"</span>,a,b);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">int</span> flag=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(ll i=<span class="number">2</span>;i<=<span class="number">100</span>;i++){</span><br><span class="line"> <span class="keyword">for</span>(ll j=<span class="number">2</span>;j<=<span class="number">100</span>;j++){</span><br><span class="line"> <span class="keyword">if</span>(__gcd(a-i,b-j)==<span class="number">1</span>&&__gcd(i,j)==<span class="number">1</span>){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"2\n%lld %lld\n"</span>,i,j);</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%lld %lld\n"</span>,a-i,b-j);</span><br><span class="line"> flag=<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(flag)<span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><a href="https://www.zhixincode.com/contest/1/problem/E?problem_id=16" target="_blank" rel="noopener"><strong>E - 流流流动</strong></a></p><p>直接连边树形dp计算。需要注意的是图并非联通,可以使用并查集,判断这个集合是否已经处理过。</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">110</span>;</span><br><span class="line"><span class="built_in">vector</span><<span class="keyword">int</span>> e[maxn];</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">add</span><span class="params">(<span class="keyword">int</span> u,<span class="keyword">int</span> v)</span></span>{e[u].push_back(v),e[v].push_back(u);}</span><br><span class="line"><span class="keyword">int</span> pre[maxn];</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">fin</span><span class="params">(<span class="keyword">int</span> x)</span></span>{<span class="keyword">return</span> pre[x]==x?x:pre[x]=fin(pre[x]);}</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">unio</span><span class="params">(<span class="keyword">int</span> a,<span class="keyword">int</span> b)</span></span>{pre[fin(a)]=fin(b);}</span><br><span class="line"><span class="keyword">int</span> f[maxn],d[maxn];</span><br><span class="line"><span class="keyword">long</span> <span class="keyword">long</span> <span class="keyword">int</span> dp[maxn][<span class="number">2</span>];</span><br><span class="line"><span class="keyword">bool</span> vis[maxn];</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">dfs</span><span class="params">(<span class="keyword">int</span> u,<span class="keyword">int</span> pre)</span></span>{</span><br><span class="line"> dp[u][<span class="number">1</span>]=f[u];</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<e[u].size();i++){</span><br><span class="line"> <span class="keyword">int</span> v=e[u][i];</span><br><span class="line"> <span class="keyword">if</span>(v==pre)<span class="keyword">continue</span>;</span><br><span class="line"> dfs(v,u);</span><br><span class="line"> dp[u][<span class="number">0</span>]+=max(dp[v][<span class="number">0</span>],dp[v][<span class="number">1</span>]);</span><br><span class="line"> dp[u][<span class="number">1</span>]+=max(dp[v][<span class="number">0</span>],dp[v][<span class="number">1</span>]-d[min(u,v)]);</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> n;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>,&n);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;i++){<span class="built_in">scanf</span>(<span class="string">"%d"</span>,&f[i]);pre[i]=i;}</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;i++){<span class="built_in">scanf</span>(<span class="string">"%d"</span>,&d[i]);}</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">2</span>;i<=n;i++){</span><br><span class="line"> <span class="keyword">if</span>((i&<span class="number">1</span>) && (<span class="number">3</span>*i+<span class="number">1</span><=n)){</span><br><span class="line"> add(i,<span class="number">3</span>*i+<span class="number">1</span>);</span><br><span class="line"> unio(i,<span class="number">3</span>*i+<span class="number">1</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span> (i%<span class="number">2</span>==<span class="number">0</span>){</span><br><span class="line"> add(i,i/<span class="number">2</span>);</span><br><span class="line"> unio(i,i/<span class="number">2</span>);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">long</span> <span class="keyword">long</span> ans=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;i++){</span><br><span class="line"> <span class="keyword">int</span> p=fin(i);</span><br><span class="line"> <span class="keyword">if</span>(!vis[fin(i)]){</span><br><span class="line"> vis[fin(i)]=<span class="number">1</span>;</span><br><span class="line"> dfs(fin(i),fin(i));</span><br><span class="line"> ans+=max(dp[fin(i)][<span class="number">0</span>],dp[fin(i)][<span class="number">1</span>]);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%lld\n"</span>,ans);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><a href="https://www.zhixincode.com/contest/1/problem/F?problem_id=17" target="_blank" rel="noopener"><strong>F-爬爬爬山</strong></a></p><p>第一座山的高度确定了,R[1]。当前体力为k,山与山之间的边权为w。那么当后面山的高度大于R[1]+k的时候就需要将山的高度降低。上山消耗体力,下山增加体力,其实就相同高度低于R[1]的时候这个山不存在。因为如果碰到了一个在高的山,增加的体力就被抵消了,相同于没有。那就将边权加上多出来的那部分,(R[x]-(R[1]+k))^2,然后跑最短路就行了。</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits/stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">1e5</span>+<span class="number">10</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">long</span> <span class="keyword">long</span> inf=<span class="number">0x3f3f3f3f3f3f3f3f</span>;</span><br><span class="line"><span class="keyword">long</span> <span class="keyword">long</span> dis[maxn];</span><br><span class="line"><span class="keyword">bool</span> vis[maxn];</span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">node</span>{</span></span><br><span class="line"> <span class="keyword">int</span> u;</span><br><span class="line"> <span class="keyword">long</span> <span class="keyword">long</span> dis;</span><br><span class="line"> <span class="keyword">bool</span> <span class="keyword">operator</span> < (<span class="keyword">const</span> node &r)<span class="keyword">const</span>{</span><br><span class="line"> <span class="keyword">return</span> dis>r.dis;</span><br><span class="line"> }</span><br><span class="line">};</span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">edge</span>{</span></span><br><span class="line"> <span class="keyword">int</span> v;</span><br><span class="line"> <span class="keyword">long</span> <span class="keyword">long</span> w;</span><br><span class="line"> <span class="keyword">int</span> next;</span><br><span class="line">}e[maxn*<span class="number">10</span>];</span><br><span class="line"><span class="keyword">int</span> head[maxn*<span class="number">10</span>],hcnt=<span class="number">0</span>;</span><br><span class="line"><span class="keyword">int</span> n,m,k;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">add</span><span class="params">(<span class="keyword">int</span> u,<span class="keyword">int</span> v,<span class="keyword">long</span> <span class="keyword">long</span> <span class="keyword">int</span> w)</span></span>{</span><br><span class="line"> e[hcnt]=edge{v,w,head[u]};</span><br><span class="line"> head[u]=hcnt++;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">dij</span><span class="params">(<span class="keyword">int</span> start)</span></span>{</span><br><span class="line"> priority_queue<node> que;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;i++)</span><br><span class="line"> vis[i]=<span class="literal">false</span>,dis[i]=inf;</span><br><span class="line"> que.push({start,<span class="number">0</span>});</span><br><span class="line"> dis[start]=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">while</span>(!que.empty()){</span><br><span class="line"> <span class="keyword">int</span> u=que.top().u;</span><br><span class="line"> que.pop();</span><br><span class="line"> <span class="keyword">if</span>(vis[u])<span class="keyword">continue</span>;</span><br><span class="line"> vis[u]=<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=head[u];i>=<span class="number">0</span>;i=e[i].next){</span><br><span class="line"> <span class="keyword">int</span> v=e[i].v;</span><br><span class="line"> <span class="keyword">if</span>(dis[v]>dis[u]+e[i].w)</span><br><span class="line"> dis[v]=dis[u]+e[i].w,que.push({v,dis[v]});</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="keyword">long</span> <span class="keyword">long</span> <span class="keyword">int</span> r[maxn];</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="built_in">memset</span>(head,<span class="number">-1</span>,<span class="keyword">sizeof</span>(head));</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d%d"</span>,&n,&m,&k);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;i++)<span class="built_in">scanf</span>(<span class="string">"%lld"</span>,&r[i]);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=m;i++){</span><br><span class="line"> <span class="keyword">int</span> u,v,w;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d%d"</span>,&u,&v,&w);</span><br><span class="line"> add(u,v,w+max(<span class="number">0L</span>L,r[v]-(r[<span class="number">1</span>]+k))*max(<span class="number">0L</span>L,r[v]-(r[<span class="number">1</span>]+k)));</span><br><span class="line"> add(v,u,w+max(<span class="number">0L</span>L,r[u]-(r[<span class="number">1</span>]+k))*max(<span class="number">0L</span>L,r[u]-(r[<span class="number">1</span>]+k)));</span><br><span class="line"> }</span><br><span class="line"> dij(<span class="number">1</span>);</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%lld\n"</span>,dis[n]);</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><p><a href="https://www.zhixincode.com/contest/1/problem/J?problem_id=21" target="_blank" rel="noopener"><strong>J-夺宝奇兵</strong></a></p><p>思路:看着题比较晚了,一看woc这不就是CF原题嘛,考虑枚举最终票数。枚举完票数就开始处理,把每个党超过这个票数且收钱最少的人收买过来,如果这些人都收买完了可是还没有达到预定的票数,就一直收买之前还没有收买过的学生直到人数达标,就这样巴拉巴拉A了</p><figure class="highlight c"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><stdio.h></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span><span class="meta-string"><bits\stdc++.h></span></span></span><br><span class="line"><span class="keyword">using</span> <span class="keyword">namespace</span> <span class="built_in">std</span>;</span><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">long</span> <span class="keyword">long</span> ll;</span><br><span class="line"><span class="keyword">int</span> n,m,ns,cnt[<span class="number">3005</span>],Sum[<span class="number">3005</span>];</span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">peo</span>{</span></span><br><span class="line"> <span class="keyword">int</span> p,c,rk;</span><br><span class="line">}a[<span class="number">3005</span>];</span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">val</span>{</span></span><br><span class="line"> <span class="keyword">int</span> rk,v;</span><br><span class="line">}b[<span class="number">3005</span>];</span><br><span class="line"><span class="keyword">bool</span> vis[<span class="number">3005</span>];</span><br><span class="line">ll min_ans=<span class="number">-1</span>,ans;</span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">cmpa</span> <span class="params">(peo a,peo b)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(a.p==b.p) <span class="keyword">return</span> a.c<b.c;</span><br><span class="line"> <span class="keyword">return</span> a.p<b.p;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">cmpb</span> <span class="params">(val a,val b)</span></span>{</span><br><span class="line"> <span class="keyword">return</span> a.v<b.v;</span><br><span class="line">}</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d"</span>,&m,&n);</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;++i){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d%d"</span>,&a[i].c,&a[i].p);</span><br><span class="line"> a[i].p++;</span><br><span class="line"> a[i].rk=i;</span><br><span class="line"> b[i].rk=i;</span><br><span class="line"> b[i].v=a[i].c;</span><br><span class="line"> }</span><br><span class="line"> sort(a+<span class="number">1</span>,a+<span class="number">1</span>+n,cmpa);</span><br><span class="line"> sort(b+<span class="number">1</span>,b+<span class="number">1</span>+n,cmpb);</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;++i)</span><br><span class="line"> Sum[ a[i].p ]++;</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> s=<span class="number">1</span>;s<=n;++s){</span><br><span class="line"> ns=<span class="number">0</span>;</span><br><span class="line"> ans=<span class="number">0</span>;</span><br><span class="line"> <span class="built_in">memset</span>(vis,<span class="number">0</span>,<span class="keyword">sizeof</span>(vis));</span><br><span class="line"> <span class="built_in">memset</span>(cnt,<span class="number">0</span>,<span class="keyword">sizeof</span>(cnt));</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> j=<span class="number">1</span>;j<=n;++j){</span><br><span class="line"> <span class="keyword">if</span>(a[j].p==<span class="number">1</span>) ns++,vis[ a[j].rk ]=<span class="literal">true</span>;</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">if</span>(Sum[ a[j].p ]-cnt[ a[j].p ]>=s){</span><br><span class="line"> vis[ a[j].rk ]=<span class="literal">true</span>;</span><br><span class="line"> cnt[ a[j].p ]++;</span><br><span class="line"> ans+=a[j].c;</span><br><span class="line"> ns++;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;++i){</span><br><span class="line"> <span class="keyword">if</span>(ns>=s) <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">if</span>(vis[ b[i].rk ]) <span class="keyword">continue</span>;</span><br><span class="line"> ns++;</span><br><span class="line"> ans+=b[i].v;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(min_ans==<span class="number">-1</span>) min_ans=ans;</span><br><span class="line"> min_ans=min(ans,min_ans);</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">cout</span><<min_ans;</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure>]]></content>
<summary type="html">
<h3 id="自闭感受"><a href="#自闭感受" class="headerlink" title="自闭感受"></a>自闭感受</h3><blockquote><p>第一次参加这种线下的算法Camp,不得不说和队友都是内心非常的小鸡动。上午开幕式<font colo
</summary>
<category term="2019 Wannafly Winter Camp" scheme="https://anoyer.cn/categories/2019-Wannafly-Winter-Camp/"/>
<category term="Camp" scheme="https://anoyer.cn/tags/Camp/"/>
</entry>
</feed>