-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsearch.xml
652 lines (313 loc) · 471 KB
/
search.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
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
<?xml version="1.0" encoding="utf-8"?>
<search>
<entry>
<title>csp-201604</title>
<link href="/2019/09/21/csp-201604/"/>
<url>/2019/09/21/csp-201604/</url>
<content type="html"><![CDATA[<h2 id="201604-1-折点计数"><a href="#201604-1-折点计数" class="headerlink" title="201604-1 折点计数"></a>201604-1 折点计数</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id="201604-2-俄罗斯方块"><a href="#201604-2-俄罗斯方块" class="headerlink" title="201604-2 俄罗斯方块"></a>201604-2 俄罗斯方块</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id="201604-3-路径解析"><a href="#201604-3-路径解析" class="headerlink" title="201604-3 路径解析"></a>201604-3 路径解析</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><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"><string></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="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><sstream></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><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">printStack</span><span class="params">(<span class="keyword">const</span> <span class="built_in">vector</span><<span class="built_in">string</span>> &stk)</span> </span>{</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>; i<stk.size(); i++) {</span><br><span class="line"> <span class="built_in">cout</span> << <span class="string">"/"</span> << stk[i];</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(stk.empty()) <span class="built_in">cout</span> << <span class="string">"/"</span>;</span><br><span class="line"> <span class="built_in">cout</span> << <span class="string">"\n"</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">formalize</span><span class="params">(<span class="built_in">vector</span><<span class="built_in">string</span>> &stk, <span class="built_in">string</span> path)</span> </span>{</span><br><span class="line"> <span class="function"><span class="built_in">stringstream</span> <span class="title">ss</span><span class="params">(path)</span></span>;</span><br><span class="line"> <span class="built_in">string</span> dir;</span><br><span class="line"> <span class="keyword">bool</span> first = <span class="literal">true</span>;</span><br><span class="line"> <span class="keyword">while</span>(getline(ss, dir, <span class="string">'/'</span>)) {</span><br><span class="line"> <span class="keyword">if</span>(dir.empty()) {</span><br><span class="line"> <span class="keyword">if</span> (first) stk = <span class="built_in">vector</span><<span class="built_in">string</span>>();</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(dir == <span class="string">".."</span>) {</span><br><span class="line"> <span class="keyword">if</span>(!stk.empty()) stk.pop_back();</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(dir == <span class="string">"."</span>) {}</span><br><span class="line"> <span class="keyword">else</span> {</span><br><span class="line"> stk.push_back(dir);</span><br><span class="line"> }</span><br><span class="line"> first = <span class="literal">false</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> N;</span><br><span class="line"> <span class="built_in">cin</span> >> N;</span><br><span class="line"> <span class="built_in">string</span> current, relative;</span><br><span class="line"> <span class="built_in">cin</span> >> current;</span><br><span class="line"> <span class="built_in">vector</span><<span class="built_in">string</span>> stk, newStk;</span><br><span class="line"> formalize(stk, current);</span><br><span class="line"> <span class="built_in">cin</span>.ignore();</span><br><span class="line"> <span class="keyword">while</span>(N--) {</span><br><span class="line"> getline(<span class="built_in">cin</span>, relative);</span><br><span class="line"> newStk = stk;</span><br><span class="line"> formalize(newStk, relative);</span><br><span class="line"> printStack(newStk);</span><br><span class="line"> }</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="201604-4-游戏"><a href="#201604-4-游戏" class="headerlink" title="201604-4 游戏"></a>201604-4 游戏</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//40</span></span><br><span class="line"><span class="comment">//50 游戏开始时刻为0看漏 导致动态规划初始条件弄错 </span></span><br><span class="line"><span class="comment">//误判时间边界条件 dp 时间维只给了105 应该至少给100+100*sqrt(2)</span></span><br><span class="line"><span class="comment">// 100</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><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">const</span> <span class="keyword">int</span> maxm=<span class="number">105</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> n,m,t; </span><br><span class="line"><span class="keyword">int</span> dp[maxn][maxm][<span class="number">1000</span>];</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">vertex</span>{</span></span><br><span class="line"> <span class="keyword">int</span> x;</span><br><span class="line"> <span class="keyword">int</span> y;</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">outbound</span><span class="params">(<span class="keyword">const</span> vertex & v)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(v.x<=<span class="number">0</span>||v.y<=<span class="number">0</span>||v.x>n||v.y>m) <span class="keyword">return</span> <span class="literal">true</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">vertex <span class="title">v2d</span><span class="params">(<span class="keyword">const</span> vertex & v, <span class="keyword">int</span> d)</span></span>{</span><br><span class="line"> <span class="keyword">switch</span>(d){</span><br><span class="line"> <span class="keyword">case</span> <span class="number">0</span>: <span class="keyword">return</span> {v.x<span class="number">-1</span>,v.y};<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">1</span>: <span class="keyword">return</span> {v.x,v.y<span class="number">-1</span>};<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">2</span>: <span class="keyword">return</span> {v.x+<span class="number">1</span>,v.y};<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">3</span>: <span class="keyword">return</span> {v.x,v.y+<span class="number">1</span>};<span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> {<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 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 %d"</span>, &n, &m, &t);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<t;i++){</span><br><span class="line"> <span class="keyword">int</span> r,c,a,b;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d %d %d"</span>, &r, &c, &a, &b);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> s=a;s<=b;s++) dp[r][c][s]=<span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> dp[<span class="number">1</span>][<span class="number">1</span>][<span class="number">0</span>] = <span class="number">2</span>;</span><br><span class="line"> <span class="keyword">int</span> s;</span><br><span class="line"> <span class="keyword">for</span>(s=<span class="number">0</span>;s<=<span class="number">1000</span>;s++){</span><br><span class="line"> <span class="keyword">if</span>(dp[n][m][s]==<span class="number">2</span>) <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> x=<span class="number">1</span>;x<=n;x++){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> y=<span class="number">1</span>;y<=m;y++){</span><br><span class="line"> <span class="keyword">if</span>(dp[x][y][s]==<span class="number">2</span>){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> d=<span class="number">0</span>;d<<span class="number">4</span>;d++){</span><br><span class="line"> vertex v = v2d({x,y}, d);</span><br><span class="line"> <span class="keyword">if</span>(outbound(v)) <span class="keyword">continue</span>;</span><br><span class="line"> <span class="keyword">if</span>(dp[v.x][v.y][s+<span class="number">1</span>]==<span class="number">1</span>) <span class="keyword">continue</span>;</span><br><span class="line"> dp[v.x][v.y][s+<span class="number">1</span>] = <span class="number">2</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><br><span class="line"></span><br><span class="line"> <span class="comment">// for(s=1;s<=7;s++){</span></span><br><span class="line"> <span class="comment">// printf("DEBUG s:%d\n", s);</span></span><br><span class="line"> <span class="comment">// for(int x=1;x<=n;x++){</span></span><br><span class="line"> <span class="comment">// for(int y=1;y<=m;y++){</span></span><br><span class="line"> <span class="comment">// printf("%d ", dp[x][y][s]);</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> <span class="comment">// putchar('\n');</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"></span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d\n"</span>, s);</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><h2 id="201604-5-网络连接"><a href="#201604-5-网络连接" class="headerlink" title="201604-5 网络连接"></a>201604-5 网络连接</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id><a href="#" class="headerlink" title></a><a href="/2019/09/10/csp-intergrated/" title="csp题集汇总">csp题集汇总</a></h2><hr>]]></content>
<categories>
<category> csp </category>
</categories>
<tags>
<tag> csp </tag>
</tags>
</entry>
<entry>
<title>csp-201512</title>
<link href="/2019/09/21/csp-201512/"/>
<url>/2019/09/21/csp-201512/</url>
<content type="html"><![CDATA[<h2 id="201512-1-数位之和"><a href="#201512-1-数位之和" class="headerlink" title="201512-1 数位之和"></a>201512-1 数位之和</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id="201512-2-消除类游戏"><a href="#201512-2-消除类游戏" class="headerlink" title="201512-2 消除类游戏"></a>201512-2 消除类游戏</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id="201512-3-画图"><a href="#201512-3-画图" class="headerlink" title="201512-3 画图"></a>201512-3 画图</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//90错误</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><br><span class="line"><span class="keyword">int</span> m,n,q;</span><br><span class="line"><span class="keyword">char</span> canvas[<span class="number">110</span>][<span class="number">110</span>];</span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">outbound</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>(x<<span class="number">0</span>||y<<span class="number">0</span>||x>=m||y>=n) <span class="keyword">return</span> <span class="literal">true</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 class="keyword">bool</span> visit[<span class="number">110</span>][<span class="number">110</span>];</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 class="keyword">char</span> c)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(outbound(x, y)) <span class="keyword">return</span>;</span><br><span class="line"> <span class="keyword">if</span>(visit[x][y]) <span class="keyword">return</span>;</span><br><span class="line"> <span class="keyword">if</span>(canvas[x][y] == <span class="string">'-'</span> || canvas[x][y] == <span class="string">'|'</span> ||canvas[x][y] == <span class="string">'+'</span>) <span class="keyword">return</span>;</span><br><span class="line"> visit[x][y] = <span class="literal">true</span>;</span><br><span class="line"> canvas[x][y] = c;</span><br><span class="line"> dfs(x+<span class="number">1</span>, y, c);</span><br><span class="line"> dfs(x<span class="number">-1</span>, y, c);</span><br><span class="line"> dfs(x, y+<span class="number">1</span>, c);</span><br><span class="line"> dfs(x, y<span class="number">-1</span>, c);</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 %d"</span>, &m, &n, &q);</span><br><span class="line"> <span class="built_in">memset</span>(canvas, <span class="string">'.'</span>, <span class="keyword">sizeof</span>(canvas));</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<q;i++){</span><br><span class="line"> <span class="keyword">int</span> op;</span><br><span class="line"> <span class="built_in">cin</span> >> op;</span><br><span class="line"> <span class="keyword">if</span>(op==<span class="number">0</span>){</span><br><span class="line"> <span class="keyword">int</span> x1, y1, x2, y2;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d %d %d"</span>, &x1, &y1, &x2, &y2);</span><br><span class="line"> <span class="keyword">if</span>(x1==x2){</span><br><span class="line"> <span class="keyword">int</span> x=x1;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> y=min(y1,y2);y<=max(y1,y2);y++){</span><br><span class="line"> <span class="keyword">if</span>(canvas[x][y]==<span class="string">'-'</span>) canvas[x][y] = <span class="string">'+'</span> ;</span><br><span class="line"> <span class="keyword">else</span> canvas[x][y] = <span class="string">'|'</span>;</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> y=y1;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> x=min(x1,x2);x<=max(x1,x2);x++){</span><br><span class="line"> <span class="keyword">if</span>(canvas[x][y]==<span class="string">'|'</span>) canvas[x][y] = <span class="string">'+'</span> ;</span><br><span class="line"> <span class="keyword">else</span> canvas[x][y] = <span class="string">'-'</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> x,y;</span><br><span class="line"> <span class="keyword">char</span> c;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d %c"</span>, &x, &y, &c);</span><br><span class="line"> <span class="built_in">memset</span>(visit, <span class="number">0</span> ,<span class="keyword">sizeof</span>(visit));</span><br><span class="line"> dfs(x, y, c);</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> y=n<span class="number">-1</span>;y>=<span class="number">0</span>;y--){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> x=<span class="number">0</span>;x<m;x++){</span><br><span class="line"> <span class="comment">// if(x!=0) putchar(' ');</span></span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%c"</span>, canvas[x][y]);</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">putchar</span>(<span class="string">'\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><h2 id="201512-4-送货"><a href="#201512-4-送货" class="headerlink" title="201512-4 送货"></a>201512-4 送货</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//欧拉回路</span></span><br><span class="line"><span class="comment">//70分 猜测爆栈</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><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn = <span class="number">10000</span> + <span class="number">10</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxm = (<span class="number">100000</span>+<span class="number">10</span>)*<span class="number">2</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> n,m;</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">int</span> idx;</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="built_in">vector</span><Edge> adj[maxn];</span><br><span class="line"><span class="keyword">bool</span> visit[maxm];</span><br><span class="line"></span><br><span class="line"><span class="built_in">deque</span> <<span class="keyword">int</span>> ans;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">dfs</span><span class="params">(<span class="keyword">int</span> u, <span class="keyword">int</span> num)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(num==m){</span><br><span class="line"> ans.push_front(u);</span><br><span class="line"> <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">auto</span> vi : adj[u]){</span><br><span class="line"> <span class="keyword">int</span> v = vi.v;</span><br><span class="line"> <span class="keyword">int</span> idx = vi.idx;</span><br><span class="line"> <span class="keyword">if</span>(visit[idx]) <span class="keyword">continue</span>;</span><br><span class="line"> visit[idx] = <span class="literal">true</span>;</span><br><span class="line"> <span class="keyword">if</span>(dfs(v, num+<span class="number">1</span>)){</span><br><span class="line"> ans.push_front(u);</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"> visit[idx] = <span class="literal">false</span>;</span><br><span class="line"> }</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><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, &m);</span><br><span class="line"> <span class="keyword">int</span> idx=<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<m;i++){</span><br><span class="line"> <span class="keyword">int</span> a,b;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d"</span>, &a, &b);</span><br><span class="line"> adj[a].push_back({b, ++idx});</span><br><span class="line"> adj[b].push_back({a, idx}); <span class="comment">//same idx;</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"> sort(adj[i].begin(), adj[i].end(), [](Edge & a, Edge & b){ <span class="keyword">return</span> a.v < b.v;});</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">bool</span> res = dfs(<span class="number">1</span>, <span class="number">0</span>);</span><br><span class="line"> <span class="keyword">if</span>(res){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">auto</span> v:ans){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d "</span>, v);</span><br><span class="line"> }</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"-1\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><h2 id="201512-5-矩阵"><a href="#201512-5-矩阵" class="headerlink" title="201512-5 矩阵"></a>201512-5 矩阵</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id><a href="#" class="headerlink" title></a><a href="/2019/09/10/csp-intergrated/" title="csp题集汇总">csp题集汇总</a></h2><hr>]]></content>
<categories>
<category> csp </category>
</categories>
<tags>
<tag> csp </tag>
</tags>
</entry>
<entry>
<title>csp-201612</title>
<link href="/2019/09/21/csp-201612/"/>
<url>/2019/09/21/csp-201612/</url>
<content type="html"><![CDATA[<h2 id="201612-1-中间数"><a href="#201612-1-中间数" class="headerlink" title="201612-1 中间数"></a>201612-1 中间数</h2><figure class="highlight cpp"><table><tr><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="keyword">int</span> n;</span><br><span class="line"><span class="keyword">int</span> a[<span class="number">1010</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">scanf</span>(<span class="string">"%d"</span>, &n);</span><br><span class="line"> <span class="keyword">int</span> mmax=<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> val;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &val);</span><br><span class="line"> a[val] ++;</span><br><span class="line"> mmax = max(mmax, val);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> tar=<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">int</span> oldsum=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">bool</span> flag=<span class="literal">false</span>;</span><br><span class="line"> <span class="keyword">while</span>(tar<=mmax){</span><br><span class="line"> <span class="keyword">if</span>(a[tar]==<span class="number">0</span>){</span><br><span class="line"> tar++;</span><br><span class="line"> <span class="keyword">continue</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(oldsum == n-a[tar]-oldsum){</span><br><span class="line"> flag=<span class="literal">true</span>;</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> oldsum += a[tar];</span><br><span class="line"> tar++;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(flag) <span class="built_in">printf</span>(<span class="string">"%d"</span>, tar);</span><br><span class="line"> <span class="keyword">else</span> <span class="built_in">printf</span>(<span class="string">"-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><h2 id="201612-2-工资计算"><a href="#201612-2-工资计算" class="headerlink" title="201612-2 工资计算"></a>201612-2 工资计算</h2><figure class="highlight cpp"><table><tr><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="keyword">double</span> tmp[<span class="number">10</span>] = {<span class="number">0</span>, <span class="number">1500</span>, <span class="number">4500</span>, <span class="number">9000</span>, <span class="number">35000</span>, <span class="number">55000</span>, <span class="number">80000</span>, <span class="number">1e20</span>};</span><br><span class="line"><span class="keyword">double</span> rate[<span class="number">10</span>] = {<span class="number">0</span>, <span class="number">0.03</span>, <span class="number">0.1</span>, <span class="number">0.2</span>, <span class="number">0.25</span>, <span class="number">0.3</span>, <span class="number">0.35</span>, <span class="number">0.45</span>};</span><br><span class="line"><span class="keyword">double</span> bound[<span class="number">10</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> ret;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &ret);</span><br><span class="line"> <span class="keyword">if</span>(ret <= <span class="number">3500</span>){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d\n"</span>, ret);</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><span class="line"> ret -= <span class="number">3500</span>;</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">7</span>;i++){</span><br><span class="line"> bound[i] = bound[i<span class="number">-1</span>]+(tmp[i]-tmp[i<span class="number">-1</span>])*(<span class="number">1</span>-rate[i]);</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// for(int i=0;i<=7;i++){</span></span><br><span class="line"> <span class="comment">// printf("DEBUG bound[%d]:%f\n",i, bound[i]);</span></span><br><span class="line"> <span class="comment">// }</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">6</span>;i++){</span><br><span class="line"> <span class="keyword">if</span>(ret >= bound[i] && ret < bound[i+<span class="number">1</span>]){</span><br><span class="line"> <span class="keyword">int</span> ans = tmp[i] + (ret-bound[i])/(<span class="number">1</span>-rate[i+<span class="number">1</span>]);</span><br><span class="line"> <span class="comment">// printf("%.2f %.2f\n", tmp[i], (ret-bound[i])/(1-rate[i+1]));</span></span><br><span class="line"> ans += <span class="number">3500</span>;</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">break</span>;</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><h2 id="201612-3-权限查询"><a href="#201612-3-权限查询" class="headerlink" title="201612-3 权限查询"></a>201612-3 权限查询</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">// </span></span><br><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"><iostream></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><string></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"><vector></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"><deque></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><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="keyword">int</span> N;</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> p,r,u,q;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">PRIVALUE</span>{</span></span><br><span class="line"><span class="keyword">bool</span> ifleveled;</span><br><span class="line"><span class="keyword">int</span> level;</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="built_in">map</span> <<span class="built_in">string</span>, <span class="built_in">map</span> <<span class="built_in">string</span>, PRIVALUE>> roles;</span><br><span class="line"><span class="built_in">map</span> <<span class="built_in">string</span>, <span class="built_in">map</span> <<span class="built_in">string</span>, PRIVALUE>> users;</span><br><span class="line"></span><br><span class="line"><span class="keyword">typedef</span> <span class="built_in">map</span> <<span class="built_in">string</span>, PRIVALUE> NMAP;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">printm</span><span class="params">(<span class="built_in">map</span> <<span class="built_in">string</span>, <span class="built_in">map</span> <<span class="built_in">string</span>, PRIVALUE>> & m)</span></span>{</span><br><span class="line"><span class="built_in">map</span> <<span class="built_in">string</span>, NMAP> ::iterator it;</span><br><span class="line"><span class="keyword">for</span>(it=m.begin();it!=m.end();it++){</span><br><span class="line"><span class="built_in">cout</span> << (*it).first <<<span class="string">"||"</span>;</span><br><span class="line">NMAP & nm = (*it).second;</span><br><span class="line">NMAP::iterator mit;</span><br><span class="line"><span class="keyword">for</span>(mit=nm.begin();mit!=nm.end();mit++){</span><br><span class="line"><span class="built_in">cout</span> << (*mit).first << <span class="string">":\t"</span>;</span><br><span class="line"><span class="keyword">if</span>((*mit).second.ifleveled){</span><br><span class="line"><span class="built_in">cout</span> << <span class="string">"|"</span> << (*mit).second.level << <span class="string">"\t"</span>;</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><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">printnm</span><span class="params">(NMAP & nm)</span></span>{</span><br><span class="line">NMAP::iterator mit;</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"DEBUG mit:%x\n"</span>, mit);</span><br><span class="line"><span class="keyword">for</span>(mit=nm.begin();mit!=nm.end();mit++){</span><br><span class="line"><span class="built_in">cout</span> << (*mit).first << <span class="string">":\t"</span>;</span><br><span class="line"><span class="keyword">if</span>((*mit).second.ifleveled){</span><br><span class="line"><span class="built_in">cout</span> << <span class="string">"|"</span> << (*mit).second.level << <span class="string">"\t"</span>;</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><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">cin</span> >> p;</span><br><span class="line">getchar();</span><br><span class="line"><span class="built_in">string</span> line;</span><br><span class="line"><span class="keyword">while</span>(p-- ><span class="number">0</span>){</span><br><span class="line">getline(<span class="built_in">cin</span>, line);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="built_in">cin</span> >> r;</span><br><span class="line"><span class="built_in">map</span> <<span class="built_in">string</span>, PRIVALUE> prim;</span><br><span class="line"><span class="keyword">while</span>(r-- ><span class="number">0</span>){</span><br><span class="line"><span class="built_in">string</span> rolename,pristr;</span><br><span class="line"><span class="keyword">int</span> t;</span><br><span class="line"><span class="built_in">cin</span> >> rolename >> t;</span><br><span class="line">prim.clear();</span><br><span class="line"><span class="keyword">while</span>(t-- ><span class="number">0</span>){</span><br><span class="line"><span class="built_in">cin</span> >> pristr;</span><br><span class="line"><span class="keyword">if</span>(pristr.find(<span class="string">":"</span>)!=<span class="built_in">string</span>::npos){</span><br><span class="line"><span class="built_in">string</span> priname = pristr.substr(<span class="number">0</span>, pristr.find(<span class="string">":"</span>));</span><br><span class="line"><span class="keyword">int</span> level = stoi(pristr.substr(pristr.find(<span class="string">":"</span>)+<span class="number">1</span>));</span><br><span class="line">prim[priname] = {<span class="literal">true</span>, level};</span><br><span class="line"><span class="comment">// prim.insert(pair<string, PRIVALUE>(priname, {true, level}));</span></span><br><span class="line">}<span class="keyword">else</span></span><br><span class="line">prim[pristr]={<span class="literal">false</span>, <span class="number">0</span>};</span><br><span class="line"><span class="comment">// prim.insert(pair<string, PRIVALUE>(pristr, {false, 0}));</span></span><br><span class="line">}</span><br><span class="line">roles[rolename]=prim;</span><br><span class="line"><span class="comment">// roles.insert(pair<string, NMAP>(rolename, prim));</span></span><br><span class="line">}</span><br><span class="line"><span class="comment">// printm(roles);</span></span><br><span class="line"><span class="built_in">cin</span> >> u;</span><br><span class="line"><span class="built_in">map</span> <<span class="built_in">string</span>, PRIVALUE> prims;</span><br><span class="line"><span class="keyword">while</span>(u-- ><span class="number">0</span>){</span><br><span class="line"><span class="built_in">string</span> username;</span><br><span class="line"><span class="keyword">int</span> t;</span><br><span class="line"><span class="built_in">cin</span> >> username >> t;</span><br><span class="line">prims.clear();</span><br><span class="line"><span class="keyword">while</span>(t-- ><span class="number">0</span>){</span><br><span class="line"><span class="built_in">string</span> rolename;</span><br><span class="line"><span class="built_in">cin</span> >> rolename;</span><br><span class="line">NMAP nm = roles[rolename];</span><br><span class="line">NMAP::iterator mit;</span><br><span class="line"><span class="keyword">for</span>(mit=nm.begin();mit!=nm.end();mit++){</span><br><span class="line"><span class="built_in">string</span> priname = (*mit).first;</span><br><span class="line"><span class="keyword">if</span>(prims.find(priname) != prims.end()){</span><br><span class="line">PRIVALUE & p = (*mit).second;</span><br><span class="line"><span class="keyword">if</span>(p.ifleveled && prims[priname].level<p.level) prims[priname].level = p.level;</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line">prims[priname] = (*mit).second;</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line">users.insert(pair<<span class="built_in">string</span>, NMAP>(username, prims));</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">// printf("DEBUG users\n");</span></span><br><span class="line"><span class="comment">// printm(users);</span></span><br><span class="line"><span class="built_in">cin</span> >> q;</span><br><span class="line"><span class="keyword">while</span>(q-- ><span class="number">0</span>){</span><br><span class="line"><span class="built_in">string</span> uname, pname;</span><br><span class="line"><span class="built_in">cin</span> >> uname >> pname;</span><br><span class="line"><span class="comment">// printf("DEBUG uname:%s pname:%s\n", uname.c_str(), pname.c_str());</span></span><br><span class="line"><span class="keyword">if</span>(users.find(uname)!=users.end()){</span><br><span class="line">NMAP & nm = users[uname];</span><br><span class="line"><span class="keyword">if</span>(pname.find(<span class="string">":"</span>)!=<span class="built_in">string</span>::npos){</span><br><span class="line"><span class="built_in">string</span> priname = pname.substr(<span class="number">0</span>, pname.find(<span class="string">":"</span>));</span><br><span class="line"><span class="keyword">int</span> level = stoi(pname.substr(pname.find(<span class="string">":"</span>)+<span class="number">1</span>));</span><br><span class="line"><span class="keyword">if</span>(nm.find(priname)!=nm.end()){</span><br><span class="line"><span class="keyword">if</span>(nm[priname].level >= level) <span class="built_in">printf</span>(<span class="string">"true\n"</span>);</span><br><span class="line"><span class="keyword">else</span> <span class="built_in">printf</span>(<span class="string">"false\n"</span>);</span><br><span class="line">}<span class="keyword">else</span></span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"false\n"</span>);</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line"><span class="keyword">if</span>(nm.find(pname)!=nm.end()){</span><br><span class="line"><span class="keyword">if</span>(nm[pname].ifleveled){</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"%d\n"</span>, nm[pname].level);</span><br><span class="line">}</span><br><span class="line"><span class="keyword">else</span> <span class="built_in">printf</span>(<span class="string">"true\n"</span>);</span><br><span class="line">}</span><br><span class="line"><span class="keyword">else</span> <span class="built_in">printf</span>(<span class="string">"false\n"</span>);</span><br><span class="line">}</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"false\n"</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><span class="line"><span class="comment">//字符串分割函数</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">SplitString</span><span class="params">(<span class="keyword">const</span> <span class="built_in">string</span>& s, <span class="built_in">vector</span><<span class="built_in">string</span>>& v, <span class="keyword">const</span> <span class="built_in">string</span>& c)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"><span class="built_in">string</span>::size_type pos1, pos2;</span><br><span class="line">pos2 = s.find(c);</span><br><span class="line">pos1 = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">while</span>(<span class="built_in">string</span>::npos != pos2)</span><br><span class="line">{</span><br><span class="line">v.push_back(s.substr(pos1, pos2-pos1));</span><br><span class="line">pos1 = pos2 + c.size();</span><br><span class="line">pos2 = s.find(c, pos1);</span><br><span class="line">}</span><br><span class="line"><span class="keyword">if</span>(pos1 != s.length())</span><br><span class="line">v.push_back(s.substr(pos1));</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="201612-4-压缩编码"><a href="#201612-4-压缩编码" class="headerlink" title="201612-4 压缩编码"></a>201612-4 压缩编码</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id="201612-5-卡牌游戏"><a href="#201612-5-卡牌游戏" class="headerlink" title="201612-5 卡牌游戏"></a>201612-5 卡牌游戏</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id><a href="#" class="headerlink" title></a><a href="/2019/09/10/csp-intergrated/" title="csp题集汇总">csp题集汇总</a></h2><hr>]]></content>
<categories>
<category> csp </category>
</categories>
<tags>
<tag> csp </tag>
</tags>
</entry>
<entry>
<title>csp-201609</title>
<link href="/2019/09/21/csp-201609/"/>
<url>/2019/09/21/csp-201609/</url>
<content type="html"><![CDATA[<h2 id="201609-1-最大波动"><a href="#201609-1-最大波动" class="headerlink" title="201609-1 最大波动"></a>201609-1 最大波动</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id="201609-2-火车购票"><a href="#201609-2-火车购票" class="headerlink" title="201609-2 火车购票"></a>201609-2 火车购票</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id="201609-3-炉石传说"><a href="#201609-3-炉石传说" class="headerlink" title="201609-3 炉石传说"></a>201609-3 炉石传说</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id="201609-4-交通规划"><a href="#201609-4-交通规划" class="headerlink" title="201609-4 交通规划"></a>201609-4 交通规划</h2><figure class="highlight cpp"><table><tr><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="meta">#<span class="meta-keyword">define</span> INF 0x3FFFFFFF</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> PB(X) push_back(X)</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> MP(X,Y) make_pair(X,Y)</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">typedef</span> pair <<span class="keyword">int</span>,<span class="keyword">int</span>> PII;</span><br><span class="line"><span class="keyword">typedef</span> <span class="built_in">vector</span> <PII> VII;</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn = <span class="number">100010</span>;</span><br><span class="line"></span><br><span class="line"><span class="built_in">vector</span><PII> adj[maxn];</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">mix</span>{</span></span><br><span class="line"> <span class="keyword">int</span> dis;</span><br><span class="line"> <span class="keyword">int</span> s;</span><br><span class="line"> <span class="keyword">int</span> w;</span><br><span class="line"> <span class="keyword">bool</span> <span class="keyword">operator</span> < (<span class="keyword">const</span> mix &p) <span class="keyword">const</span></span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">if</span>(dis==p.dis) <span class="keyword">return</span> w > p.w;</span><br><span class="line"> <span class="keyword">return</span> dis > p.dis;</span><br><span class="line"> }</span><br><span class="line">}; <span class="comment">//最小堆</span></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">add_edge</span><span class="params">(<span class="keyword">int</span> u,<span class="keyword">int</span> v,<span class="keyword">int</span> d)</span></span>{</span><br><span class="line"> adj[u].PB(MP(v,d));</span><br><span class="line">}</span><br><span class="line"><span class="comment">//上面与上一版本一致</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">bool</span> vis[maxn];</span><br><span class="line"><span class="keyword">int</span> dis[maxn]; </span><br><span class="line"><span class="keyword">long</span> <span class="keyword">long</span> ans;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">dijkstra</span><span class="params">(<span class="keyword">int</span> s,<span class="keyword">int</span> n)</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="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=n;i++) dis[i] = (i == s ? <span class="number">0</span> : INF);</span><br><span class="line"> priority_queue<mix>q;<span class="comment">//声明优先队列:每次从队列中取出的是具有最高优先权的元素。</span></span><br><span class="line"> <span class="comment">//优先队列第一个参数为比较类型,第二个为容器类型,第三个为比较函数。</span></span><br><span class="line"> <span class="comment">//greater实现小顶堆//less 实现大顶堆(默认为大顶堆)</span></span><br><span class="line"> q.push({dis[s], s, <span class="number">0</span>});<span class="comment">//将他本身先推进优先队列</span></span><br><span class="line"> <span class="keyword">while</span>(!q.empty()){<span class="comment">//当队列空时已将所有边加入队列并推出</span></span><br><span class="line"> mix p = q.top();</span><br><span class="line"> <span class="keyword">int</span> x = p.s;</span><br><span class="line"> <span class="comment">// printf("DE<span class="doctag">BUG:</span>%d %d\n", p.s, p.w);</span></span><br><span class="line"> q.pop();</span><br><span class="line"> <span class="keyword">if</span>(vis[x]) <span class="keyword">continue</span>;</span><br><span class="line"> ans += p.w;</span><br><span class="line"> vis[x] = <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<adj[x].size();i++){<span class="comment">//每一条与x相邻的边都要更新</span></span><br><span class="line"> <span class="keyword">int</span> y = adj[x][i].first;</span><br><span class="line"> <span class="keyword">int</span> d = adj[x][i].second;</span><br><span class="line"> <span class="keyword">if</span>(!vis[y] && dis[x] + d <= dis[y]){</span><br><span class="line"> dis[y] = dis[x] + d;</span><br><span class="line"> q.push({dis[y], y, d});<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><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">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, &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> a,b,c;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d %d"</span>, &a, &b, &c);</span><br><span class="line"> add_edge(a, b, c);</span><br><span class="line"> add_edge(b, a, c);</span><br><span class="line"> }</span><br><span class="line"> dijkstra(<span class="number">1</span>, n);</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><h2 id="201609-5-祭坛"><a href="#201609-5-祭坛" class="headerlink" title="201609-5 祭坛"></a>201609-5 祭坛</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id><a href="#" class="headerlink" title></a><a href="/2019/09/10/csp-intergrated/" title="csp题集汇总">csp题集汇总</a></h2><hr>]]></content>
<categories>
<category> csp </category>
</categories>
<tags>
<tag> csp </tag>
</tags>
</entry>
<entry>
<title>csp-201509</title>
<link href="/2019/09/21/csp-201509/"/>
<url>/2019/09/21/csp-201509/</url>
<content type="html"><![CDATA[<h2 id="201509-1-数列分段"><a href="#201509-1-数列分段" class="headerlink" title="201509-1 数列分段"></a>201509-1 数列分段</h2><figure class="highlight cpp"><table><tr><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="keyword">int</span> n;</span><br><span class="line"><span class="keyword">int</span> ans;</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"</span>, &n);</span><br><span class="line"> <span class="keyword">int</span> old = <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<n;i++){</span><br><span class="line"> <span class="keyword">int</span> val;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &val);</span><br><span class="line"> <span class="keyword">if</span>(val!=old) ans ++ ;</span><br><span class="line"> old = val;</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><h2 id="201509-2-日期计算"><a href="#201509-2-日期计算" class="headerlink" title="201509-2 日期计算"></a>201509-2 日期计算</h2><figure class="highlight cpp"><table><tr><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="keyword">int</span> month_days[<span class="number">13</span>] = {<span class="number">0</span>, <span class="number">31</span>, <span class="number">28</span>, <span class="number">31</span>, <span class="number">30</span>, <span class="number">31</span>, <span class="number">30</span>, <span class="number">31</span>, <span class="number">31</span>, <span class="number">30</span>, <span class="number">31</span>, <span class="number">30</span>, <span class="number">31</span>};</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">run</span><span class="params">(<span class="keyword">int</span> year)</span></span>{</span><br><span class="line"> <span class="keyword">return</span> (!(year%<span class="number">400</span>) || !(year%<span class="number">4</span>) && year%<span class="number">100</span>);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> y,d;</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>, &y, &d);</span><br><span class="line"> <span class="keyword">int</span> m = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(run(y)){</span><br><span class="line"> month_days[<span class="number">2</span>] = <span class="number">29</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">while</span>(d > month_days[m]){</span><br><span class="line"> d -= month_days[m];</span><br><span class="line"> m++;</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d\n%d\n"</span>, m, d);</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><h2 id="201509-3-模板生成系统"><a href="#201509-3-模板生成系统" class="headerlink" title="201509-3 模板生成系统"></a>201509-3 模板生成系统</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//模板处理 标答</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><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">mix</span>{</span></span><br><span class="line"> <span class="keyword">int</span> linum;</span><br><span class="line"> <span class="keyword">size_t</span> s;</span><br><span class="line"> <span class="keyword">size_t</span> e;</span><br><span class="line">};</span><br><span class="line"><span class="keyword">int</span> m,n;</span><br><span class="line"></span><br><span class="line"><span class="built_in">map</span> <<span class="built_in">string</span>, <span class="built_in">vector</span><mix>> format;</span><br><span class="line"><span class="built_in">map</span> <<span class="built_in">string</span>, <span class="built_in">string</span>> varmap;</span><br><span class="line"><span class="built_in">string</span> lines[<span class="number">110</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">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">0</span>;i<m;i++){</span><br><span class="line"> <span class="built_in">string</span> line;</span><br><span class="line"> getline(<span class="built_in">cin</span>, line);</span><br><span class="line"> lines[i] = line;</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">" "</span>);</span><br><span class="line"> <span class="built_in">string</span> varname,val;</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> >> varname;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">" \""</span>);</span><br><span class="line"> getline(<span class="built_in">cin</span>, val);</span><br><span class="line"> val.pop_back();</span><br><span class="line"> varmap[varname] = val;</span><br><span class="line"> }</span><br><span class="line"></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">0</span>;i<m;i++){</span><br><span class="line"> <span class="built_in">string</span> line = lines[i];</span><br><span class="line"> <span class="keyword">size_t</span> pos=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">size_t</span> old=<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"> pos = line.find(<span class="string">"{{"</span>, pos);</span><br><span class="line"> <span class="built_in">cout</span> << line.substr(old, pos-old);</span><br><span class="line"> <span class="keyword">if</span>(pos == line.npos)</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">size_t</span> endpos = line.find(<span class="string">"}}"</span>, pos)+<span class="number">2</span>;</span><br><span class="line"> <span class="function"><span class="built_in">stringstream</span> <span class="title">ss</span><span class="params">(line.substr(pos+<span class="number">2</span>, endpos-pos<span class="number">-4</span>))</span></span>;</span><br><span class="line"> <span class="built_in">string</span> key;</span><br><span class="line"> ss >> key;</span><br><span class="line"> <span class="keyword">if</span>(varmap.find(key)!=varmap.end()){</span><br><span class="line"> <span class="built_in">cout</span> << varmap[key];</span><br><span class="line"> }</span><br><span class="line"> pos = endpos;</span><br><span class="line"> }</span><br><span class="line"> old = pos;</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><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><h2 id="201509-4-高速公路"><a href="#201509-4-高速公路" class="headerlink" title="201509-4 高速公路"></a>201509-4 高速公路</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//强连通分量</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><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">long</span> ull;</span><br><span class="line"></span><br><span class="line"><span class="function">ull <span class="title">C</span><span class="params">(ull n, ull r)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(r==<span class="number">1</span>) <span class="keyword">return</span> n;</span><br><span class="line"> <span class="keyword">return</span> n*C(n<span class="number">-1</span>, r<span class="number">-1</span>)/r;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn = <span class="number">1e4</span> + <span class="number">10</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxm = (<span class="number">1e5</span> + <span class="number">10</span>)*<span class="number">2</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> n,m;</span><br><span class="line">ull ans;</span><br><span class="line"><span class="keyword">int</span> head[maxn], cnt=<span class="number">0</span>;<span class="comment">//head用来表示以i为起点的第一条边存储的位置,cnt读入边的计数器</span></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> next; <span class="comment">//同一起点的上一条边的储存位置</span></span><br><span class="line"> <span class="keyword">int</span> to; <span class="comment">//第i条边的终点</span></span><br><span class="line">};</span><br><span class="line"></span><br><span class="line">Edge edge[maxm];</span><br><span class="line"></span><br><span class="line"><span class="comment">//读入边</span></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>{</span><br><span class="line"> edge[cnt].to = v;</span><br><span class="line"> edge[cnt].next = head[u];</span><br><span class="line"> head[u] = cnt++;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> DFN[maxn]; <span class="comment">//时间戳</span></span><br><span class="line"><span class="keyword">int</span> LOW[maxn]; <span class="comment">//当前点子树能访问到的点的最早时间戳</span></span><br><span class="line"><span class="keyword">int</span> Dindex = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">int</span> instack[maxn];</span><br><span class="line"><span class="keyword">int</span> Stap[maxn], Stop=<span class="number">0</span>;</span><br><span class="line"><span class="keyword">int</span> Bcnt;</span><br><span class="line"><span class="keyword">int</span> Belong[maxn]; <span class="comment">//联通分量属于</span></span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">tarjan</span><span class="params">(<span class="keyword">int</span> u)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="comment">// printf("DEBUG u:%d\n", u);</span></span><br><span class="line"> DFN[u]=LOW[u]=++Dindex;</span><br><span class="line"> instack[u]=<span class="literal">true</span>;</span><br><span class="line"> Stap[++Stop]=u;</span><br><span class="line"> <span class="keyword">for</span> (<span class="keyword">int</span> j=head[u];j!=<span class="number">-1</span>;j=edge[j].next)</span><br><span class="line"> {</span><br><span class="line"> <span class="keyword">int</span> v = edge[j].to;</span><br><span class="line"> <span class="comment">// printf("DEBUG v:%d\n", v);</span></span><br><span class="line"> <span class="keyword">if</span> (!DFN[v]) <span class="comment">//未访问过</span></span><br><span class="line"> {</span><br><span class="line"> tarjan(v);</span><br><span class="line"> <span class="keyword">if</span> (LOW[v]<LOW[u])</span><br><span class="line"> LOW[u]=LOW[v];</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span> (instack[v] && DFN[v]<LOW[u]) <span class="comment">//访问过且在栈内 更新LOW</span></span><br><span class="line"> LOW[u]=DFN[v];</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span> (DFN[u]==LOW[u]) <span class="comment">//栈内为强连通分量</span></span><br><span class="line"> {</span><br><span class="line"> Bcnt++;</span><br><span class="line"> <span class="keyword">int</span> v;</span><br><span class="line"> <span class="keyword">int</span> bsize = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">do</span>{</span><br><span class="line"> v=Stap[Stop--];</span><br><span class="line"> instack[v]=<span class="literal">false</span>;</span><br><span class="line"> Belong[v]=Bcnt;</span><br><span class="line"> bsize ++ ;</span><br><span class="line"> }<span class="keyword">while</span> (v!=u);</span><br><span class="line"> <span class="keyword">if</span>(bsize><span class="number">1</span>){</span><br><span class="line"> ans += C(bsize, <span class="number">2</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">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"</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> a,b;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d"</span>, &a, &b);</span><br><span class="line"> add(a, b);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">int</span> i;</span><br><span class="line"> Stop=Bcnt=Dindex=<span class="number">0</span>;</span><br><span class="line"> <span class="built_in">memset</span>(DFN,<span class="number">0</span>,<span class="keyword">sizeof</span>(DFN));</span><br><span class="line"> <span class="keyword">for</span> (i=<span class="number">1</span>;i<=n;i++)</span><br><span class="line"> <span class="keyword">if</span> (!DFN[i])</span><br><span class="line"> tarjan(i);</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%llu\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><h2 id="201509-5-最佳文章"><a href="#201509-5-最佳文章" class="headerlink" title="201509-5 最佳文章"></a>201509-5 最佳文章</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id><a href="#" class="headerlink" title></a><a href="/2019/09/10/csp-intergrated/" title="csp题集汇总">csp题集汇总</a></h2><hr>]]></content>
<categories>
<category> csp </category>
</categories>
<tags>
<tag> csp </tag>
</tags>
</entry>
<entry>
<title>code-server在 WSL上运行</title>
<link href="/2019/09/21/code-server-paly/"/>
<url>/2019/09/21/code-server-paly/</url>
<content type="html"><![CDATA[<h2 id="x准备"><a href="#x准备" class="headerlink" title="x准备"></a>x准备</h2><p>WSL 在windows上下载即可,由于我的windows 的WSL安装在C盘,我将其移动到E盘,参考博客<a href="https://blog.csdn.net/starhosea/article/details/82624629。" target="_blank" rel="noopener">https://blog.csdn.net/starhosea/article/details/82624629。</a></p><h2 id="过程"><a href="#过程" class="headerlink" title="过程"></a>过程</h2><ol><li><p>直接下载<a href="https://github.com/cdr/sshcode/releases" target="_blank" rel="noopener">sshcode</a> linux版binary 解压 放入到WSL的/home下</p></li><li><p>在WSL编辑/etc/ssh/sshd_config将PasswordAuthentication 设置为yes</p></li><li><figure class="highlight powershell"><table><tr><td class="code"><pre><span class="line">sizheree@LAPTOP-AMQVVGCO:~$ vi /etc/ssh/sshd_config</span><br><span class="line">sizheree@LAPTOP-AMQVVGCO:~$ sudo service ssh restart</span><br><span class="line">sizheree@LAPTOP-AMQVVGCO:~$ ./sshcode sizheree@<span class="number">127.0</span>.<span class="number">0.1</span> --bind <span class="number">0.0</span>.<span class="number">0.0</span>:<span class="number">8081</span></span><br></pre></td></tr></table></figure></li></ol>]]></content>
<categories>
<category> WSL </category>
<category> code-server </category>
</categories>
<tags>
<tag> 技术 </tag>
</tags>
</entry>
<entry>
<title>reading-认知迭代-2</title>
<link href="/2019/09/16/reading-%E8%AE%A4%E7%9F%A5%E8%BF%AD%E4%BB%A3-2/"/>
<url>/2019/09/16/reading-%E8%AE%A4%E7%9F%A5%E8%BF%AD%E4%BB%A3-2/</url>
<content type="html"><![CDATA[]]></content>
<categories>
<category> 读书 </category>
<category> 认知迭代 </category>
</categories>
<tags>
<tag> 读书 </tag>
</tags>
</entry>
<entry>
<title>csp-201503</title>
<link href="/2019/09/13/csp-201503/"/>
<url>/2019/09/13/csp-201503/</url>
<content type="html"><![CDATA[<h2 id="201503-1-图像旋转"><a href="#201503-1-图像旋转" class="headerlink" title="201503-1 图像旋转"></a>201503-1 图像旋转</h2><figure class="highlight cpp"><table><tr><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="keyword">int</span> pic[<span class="number">1010</span>][<span class="number">1010</span>];</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">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, &m);</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"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &pic[i][j]);</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;j>=<span class="number">1</span>;j--){</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">printf</span>(<span class="string">"%d"</span>, pic[i][j]);</span><br><span class="line"> <span class="keyword">if</span>(i==n)</span><br><span class="line"> <span class="built_in">putchar</span>(<span class="string">'\n'</span>);</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> <span class="built_in">putchar</span>(<span class="string">' '</span>);</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><h2 id="201503-2-数字排序"><a href="#201503-2-数字排序" class="headerlink" title="201503-2 数字排序"></a>201503-2 数字排序</h2><figure class="highlight cpp"><table><tr><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="class"><span class="keyword">struct</span> <span class="title">mix</span>{</span></span><br><span class="line"> <span class="keyword">int</span> n;</span><br><span class="line"> <span class="keyword">int</span> t;</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">cmp</span> <span class="params">(mix & a, mix & b)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(a.t==b.t) <span class="keyword">return</span> a.n < b.n;</span><br><span class="line"> <span class="keyword">return</span> a.t > b.t;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> num[<span class="number">1010</span>];</span><br><span class="line"><span class="keyword">int</span> n;</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"</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="keyword">int</span> val;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &val);</span><br><span class="line"> num[val]++;</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">vector</span> <mix> pool;</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">1000</span>;i++){</span><br><span class="line"> <span class="keyword">if</span>(num[i]){</span><br><span class="line"> pool.push_back({i, num[i]});</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> sort(pool.begin(), pool.end(), cmp);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">auto</span> p: pool){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d %d\n"</span>, p.n, p.t);</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><h2 id="201503-3-节日"><a href="#201503-3-节日" class="headerlink" title="201503-3 节日"></a>201503-3 节日</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//100</span></span><br><span class="line"><span class="comment">//简单模拟</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><br><span class="line"><span class="keyword">int</span> month_days[<span class="number">13</span>] = {<span class="number">0</span>, <span class="number">31</span>, <span class="number">28</span>, <span class="number">31</span>, <span class="number">30</span>, <span class="number">31</span>, <span class="number">30</span>, <span class="number">31</span>, <span class="number">31</span>, <span class="number">30</span>, <span class="number">31</span>, <span class="number">30</span>, <span class="number">31</span>};</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">run</span><span class="params">(<span class="keyword">int</span> year)</span></span>{</span><br><span class="line"> <span class="keyword">return</span> (!(year%<span class="number">400</span>) || !(year%<span class="number">4</span>) && year%<span class="number">100</span>);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> a,b,c,y1,y2;</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 %d %d %d"</span>,&a,&b,&c,&y1,&y2);</span><br><span class="line"> <span class="keyword">int</span> y = <span class="number">1850</span>;</span><br><span class="line"> <span class="keyword">int</span> dayofweek = <span class="number">2</span>;</span><br><span class="line"> <span class="keyword">int</span> rpredays, npredays;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> i=<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">while</span>(i<a) npredays += month_days[i],i++;</span><br><span class="line"> rpredays = a><span class="number">2</span> ? npredays + <span class="number">1</span> : npredays;</span><br><span class="line"></span><br><span class="line"> <span class="comment">// printf("DEBUG rp:%d np:%d\n", rpredays, npredays);</span></span><br><span class="line"> <span class="keyword">while</span>(y<y1){</span><br><span class="line"> dayofweek = (dayofweek + (run(y)? <span class="number">366</span> : <span class="number">365</span>))%<span class="number">7</span>;</span><br><span class="line"> y++;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span>(;y<=y2;y++){</span><br><span class="line"> <span class="keyword">int</span> start = dayofweek;</span><br><span class="line"> <span class="comment">// printf("DEBUG start:%d\n", start);</span></span><br><span class="line"> start = (start + (run(y)? rpredays : npredays))%<span class="number">7</span>;</span><br><span class="line"> <span class="keyword">if</span>(start==<span class="number">0</span>) start = <span class="number">7</span>;</span><br><span class="line"> <span class="keyword">int</span> dayofmonth = <span class="number">1</span>+ (c - start + <span class="number">7</span>)%<span class="number">7</span> + (b<span class="number">-1</span>)*<span class="number">7</span>;</span><br><span class="line"> <span class="comment">// printf("dayofmonth:%d\n", dayofmonth);</span></span><br><span class="line"> <span class="comment">// printf("start:%d\n", start);</span></span><br><span class="line"> <span class="keyword">if</span>(a==<span class="number">2</span> && run(y)){</span><br><span class="line"> <span class="keyword">if</span>(dayofmonth > <span class="number">29</span>)</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"none\n"</span>);</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/%02d/%02d\n"</span>, y, a, dayofmonth);</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">if</span>(dayofmonth > month_days[a]){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"none\n"</span>);</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/%02d/%02d\n"</span>, y, a, dayofmonth);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> dayofweek = (dayofweek + (run(y)? <span class="number">366</span> : <span class="number">365</span>))%<span class="number">7</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><h2 id="201503-4-网络延时"><a href="#201503-4-网络延时" class="headerlink" title="201503-4 网络延时"></a>201503-4 网络延时</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//第一次错误 50</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><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn = <span class="number">20000</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxm = (<span class="number">20000</span>)*<span class="number">2</span>;</span><br><span class="line"><span class="keyword">int</span> head[maxn], cnt=<span class="number">0</span>;<span class="comment">//head用来表示以i为起点的第一条边存储的位置,cnt读入边的计数器</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> n,m;</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="class">{</span></span><br><span class="line"> <span class="keyword">int</span> next; <span class="comment">//同一起点的上一条边的储存位置</span></span><br><span class="line"> <span class="keyword">int</span> to; <span class="comment">//第i条边的终点</span></span><br><span class="line">};</span><br><span class="line"></span><br><span class="line">Edge edge[maxm];</span><br><span class="line"></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 class="comment">//读入边</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> edge[cnt].to = v;</span><br><span class="line"> edge[cnt].next = head[u];</span><br><span class="line"> head[u] = cnt++;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">read</span><span class="params">()</span> <span class="comment">//遍历所有边</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">0</span>; i<=n; i++){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d:"</span>, i);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=head[i]; j!=<span class="number">-1</span>; j=edge[j].next){</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"%d "</span>, edge[j].to);</span><br><span class="line">}</span><br><span class="line"> <span class="built_in">putchar</span>(<span class="string">'\n'</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><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">dfs</span><span class="params">(<span class="keyword">int</span> u)</span></span>{</span><br><span class="line"> <span class="built_in">vector</span> <<span class="keyword">int</span>> pool = {<span class="number">0</span>, <span class="number">0</span>};</span><br><span class="line"> <span class="keyword">int</span> vnum=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=head[u];j!=<span class="number">-1</span>;j=edge[j].next){</span><br><span class="line"> <span class="keyword">int</span> v = edge[j].to;</span><br><span class="line"> pool.push_back(dfs(v) + <span class="number">1</span>);</span><br><span class="line"> vnum++;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="keyword">if</span>(vnum==<span class="number">0</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"> sort(pool.begin(), pool.end(), greater<<span class="keyword">int</span>>());</span><br><span class="line"> <span class="comment">// printf("DE<span class="doctag">BUG:</span> %d:", u);</span></span><br><span class="line"> <span class="comment">// for(auto p:pool){</span></span><br><span class="line"> <span class="comment">// printf("%d ", p);</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> <span class="comment">// putchar('\n');</span></span><br><span class="line"> </span><br><span class="line"> <span class="keyword">if</span>(pool[<span class="number">0</span>] && pool[<span class="number">1</span>]){</span><br><span class="line"> ans = max(ans, pool[<span class="number">0</span>]+pool[<span class="number">1</span>]);</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(pool[<span class="number">0</span>]){</span><br><span class="line"> ans = max(ans, pool[<span class="number">0</span>]);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> pool.front();</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">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"</span>, &n, &m);</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">int</span> u;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &u);</span><br><span class="line"> add(u, i);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=n+<span class="number">1</span>;i<=n+m;i++){</span><br><span class="line"> <span class="keyword">int</span> u;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &u);</span><br><span class="line"> add(u, i);</span><br><span class="line"> }</span><br><span class="line"> dfs(<span class="number">1</span>);</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d"</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><h2 id="201503-5-最小花费"><a href="#201503-5-最小花费" class="headerlink" title="201503-5 最小花费"></a>201503-5 最小花费</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id><a href="#" class="headerlink" title></a><a href="/2019/09/10/csp-intergrated/" title="csp题集汇总">csp题集汇总</a></h2><hr>]]></content>
<categories>
<category> csp </category>
</categories>
<tags>
<tag> csp </tag>
</tags>
</entry>
<entry>
<title>csp-201412</title>
<link href="/2019/09/13/csp-201412/"/>
<url>/2019/09/13/csp-201412/</url>
<content type="html"><![CDATA[<h2 id="201412-1-门禁系统"><a href="#201412-1-门禁系统" class="headerlink" title="201412-1 门禁系统"></a>201412-1 门禁系统</h2><figure class="highlight cpp"><table><tr><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="keyword">int</span> a[<span class="number">1010</span>];</span><br><span class="line"><span class="keyword">int</span> n;</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"</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="keyword">int</span> val;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &val);</span><br><span class="line"> a[val]++;</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d "</span>, a[val]);</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><h2 id="201412-2-Z字形扫描"><a href="#201412-2-Z字形扫描" class="headerlink" title="201412-2 Z字形扫描"></a>201412-2 Z字形扫描</h2><figure class="highlight cpp"><table><tr><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="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">505</span>;</span><br><span class="line"><span class="keyword">int</span> graph[maxn][maxn];</span><br><span class="line"><span class="keyword">int</span> n;</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"</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="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j<=n;j++){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &graph[i][j]);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">int</span> x = <span class="number">1</span>, y = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">while</span>(<span class="number">1</span>){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d "</span>, graph[x][y]);</span><br><span class="line"> <span class="keyword">if</span>(x==n && y==n) <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">if</span>(x==n){</span><br><span class="line"> <span class="keyword">if</span>((x+y)%<span class="number">2</span>){</span><br><span class="line"> y++;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> x--;y++;</span><br><span class="line"> }</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(y==n){</span><br><span class="line"> <span class="keyword">if</span>(!((x+y)%<span class="number">2</span>)){</span><br><span class="line"> x++;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> x++;y--;</span><br><span class="line"> }</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(x==<span class="number">1</span>){</span><br><span class="line"> <span class="keyword">if</span>(y%<span class="number">2</span>){</span><br><span class="line"> y++;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> x++,y--;</span><br><span class="line"> }</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(y==<span class="number">1</span>){</span><br><span class="line"> <span class="keyword">if</span>(!(x%<span class="number">2</span>)){</span><br><span class="line"> x++;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> x--,y++;</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>((x+y)%<span class="number">2</span>){</span><br><span class="line"> x++;y--;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> x--,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">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="201412-3-集合竞价"><a href="#201412-3-集合竞价" class="headerlink" title="201412-3 集合竞价"></a>201412-3 集合竞价</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//分析:开盘价在买价中,枚举即可</span></span><br><span class="line"><span class="comment">//看题出现错误!!!看成了最小值之和 导向了匹配算法</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><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">op</span>{</span></span><br><span class="line"> <span class="keyword">double</span> p;</span><br><span class="line"> <span class="keyword">int</span> s;</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="built_in">deque</span> <op> buy, sell;</span><br><span class="line"></span><br><span class="line"><span class="built_in">string</span> lines[<span class="number">5005</span>];</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">cmp1</span><span class="params">(op & a, op & b)</span></span>{</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><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">cmp2</span><span class="params">(op & a, op & b)</span></span>{</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><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 class="number">1</span>;</span><br><span class="line"> <span class="built_in">string</span> line;</span><br><span class="line"> <span class="keyword">while</span>(getline(<span class="built_in">cin</span>, line)){</span><br><span class="line"> lines[n] = line;</span><br><span class="line"> <span class="keyword">if</span>(line[<span class="number">0</span>]==<span class="string">'c'</span>){</span><br><span class="line"> lines[n] = <span class="string">""</span>;</span><br><span class="line"> <span class="built_in">string</span> word;</span><br><span class="line"> <span class="keyword">int</span> i;</span><br><span class="line"> <span class="function"><span class="built_in">stringstream</span> <span class="title">ss</span><span class="params">(line)</span></span>;</span><br><span class="line"> ss >> word >> i;</span><br><span class="line"> lines[i] = <span class="string">""</span>;</span><br><span class="line"> }</span><br><span class="line"> n++;</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>(lines[i]!=<span class="string">""</span>){</span><br><span class="line"> <span class="built_in">string</span> op;</span><br><span class="line"> <span class="keyword">double</span> p;</span><br><span class="line"> <span class="keyword">int</span> s;</span><br><span class="line"> <span class="function"><span class="built_in">stringstream</span> <span class="title">ss</span><span class="params">(lines[i])</span></span>;</span><br><span class="line"> ss >> op >> p >> s;</span><br><span class="line"> <span class="comment">// cout << "DE<span class="doctag">BUG:</span>" << op << " " << p << " "<< s << endl;</span></span><br><span class="line"> <span class="keyword">if</span>(op==<span class="string">"buy"</span>){</span><br><span class="line"> buy.push_back({p, s});</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(op==<span class="string">"sell"</span>){</span><br><span class="line"> sell.push_back({p, s});</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> sort(buy.begin(), buy.end(), cmp1);</span><br><span class="line"> sort(sell.begin(), sell.end(), cmp2);</span><br><span class="line"> <span class="keyword">double</span> maxp=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">long</span> <span class="keyword">long</span> maxs=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">long</span> <span class="keyword">long</span> buysum=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">auto</span> b:buy){</span><br><span class="line"> <span class="keyword">double</span> price = b.p;</span><br><span class="line"> buysum += b.s;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> i=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">long</span> <span class="keyword">long</span> sellsum = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">while</span>(sell[i].p<=price&&i<sell.size()){</span><br><span class="line"> sellsum += sell[i].s;</span><br><span class="line"> i++;</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// printf("DE<span class="doctag">BUG:</span>%.2f %lld %lld\n", price, buysum, sellsum);</span></span><br><span class="line"> <span class="keyword">long</span> <span class="keyword">long</span> s = min(buysum, sellsum);</span><br><span class="line"> <span class="keyword">if</span>(maxs < s){</span><br><span class="line"> maxs = s;</span><br><span class="line"> maxp = price;</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(maxs == s){</span><br><span class="line"> maxp = max(price, maxp);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%.2f %lld\n"</span>, maxp, maxs);</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><h2 id="201412-4-最优灌溉"><a href="#201412-4-最优灌溉" class="headerlink" title="201412-4 最优灌溉"></a>201412-4 最优灌溉</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//运行错误 maxn=1e3+10错误 1e5+10正确??1e4+10超时??</span></span><br><span class="line"><span class="comment">//简单最小生成树</span></span><br><span class="line"></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><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><br><span class="line"><span class="keyword">int</span> fa[maxn];</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> n,m;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">init</span><span class="params">(<span class="keyword">int</span> n)</span> </span>{ <span class="comment">// 不要忘记哦!!!</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"> fa[i] = i;</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">find</span><span class="params">(<span class="keyword">int</span> u)</span> </span>{</span><br><span class="line"> <span class="keyword">if</span> (fa[u] != u) {</span><br><span class="line"> fa[u] = find(fa[u]);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> fa[u];</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">unin</span><span class="params">(<span class="keyword">int</span> u, <span class="keyword">int</span> v)</span> </span>{</span><br><span class="line"> <span class="keyword">int</span> fau = find(u);</span><br><span class="line"> <span class="keyword">int</span> fav = find(v);</span><br><span class="line"> <span class="keyword">if</span> (fau == fav) <span class="keyword">return</span>;</span><br><span class="line"> fa[fav] = fau;</span><br><span class="line">}</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_DEF</span>{</span></span><br><span class="line"> <span class="keyword">int</span> u,v,w;</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">cmp</span><span class="params">(EDGE_DEF & a, EDGE_DEF & b)</span></span>{</span><br><span class="line"> <span class="keyword">return</span> a.w < b.w;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="built_in">deque</span> <EDGE_DEF> edges;</span><br><span class="line"><span class="comment">// deque <EDGE_DEF> T;</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">long</span> <span class="keyword">long</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="built_in">scanf</span>(<span class="string">"%d %d"</span>, &n, &m);</span><br><span class="line"> init(m);</span><br><span class="line"> edges.resize(m);</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<m;i++){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d %d"</span>, &edges[i].u, &edges[i].v, &edges[i].w);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> sort(edges.begin(), edges.end(), cmp);</span><br><span class="line"></span><br><span class="line"> <span class="keyword">int</span> vnum = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">auto</span> e: edges){</span><br><span class="line"> <span class="keyword">if</span>(vnum==n) <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">if</span>(find(e.u) == find(e.v)){</span><br><span class="line"> <span class="keyword">continue</span>;</span><br><span class="line"> }</span><br><span class="line"> unin(e.u, e.v);</span><br><span class="line"> ans += e.w;</span><br><span class="line"> vnum++;</span><br><span class="line"> <span class="comment">// T.push_back(e);</span></span><br><span class="line"> <span class="comment">// printf("ans:%lld\n", ans);</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 class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="201412-5-货物调度"><a href="#201412-5-货物调度" class="headerlink" title="201412-5 货物调度"></a>201412-5 货物调度</h2><h2 id><a href="#" class="headerlink" title></a><a href="/2019/09/10/csp-intergrated/" title="csp题集汇总">csp题集汇总</a></h2><hr>]]></content>
<categories>
<category> csp </category>
</categories>
<tags>
<tag> csp </tag>
</tags>
</entry>
<entry>
<title>csp-201409</title>
<link href="/2019/09/13/csp-201409/"/>
<url>/2019/09/13/csp-201409/</url>
<content type="html"><![CDATA[<h2 id="201409-1相邻数对"><a href="#201409-1相邻数对" class="headerlink" title="201409-1相邻数对"></a>201409-1相邻数对</h2><figure class="highlight cpp"><table><tr><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="keyword">bool</span> num[<span class="number">10010</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="keyword">int</span> mmax=<span class="number">0</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="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">int</span> val;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &val);</span><br><span class="line"> num[val] = <span class="literal">true</span>;</span><br><span class="line"> mmax = max(mmax, val);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">int</span> j=<span class="number">1</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">bool</span> cons = <span class="literal">false</span>;</span><br><span class="line"> <span class="keyword">while</span>(j<=mmax){</span><br><span class="line"> <span class="keyword">if</span>(num[j]){</span><br><span class="line"> <span class="keyword">if</span>(<span class="keyword">not</span> cons){</span><br><span class="line"> cons=<span class="literal">true</span>;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> ans ++ ;</span><br><span class="line"> }</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> cons = <span class="literal">false</span>;</span><br><span class="line"> }</span><br><span class="line"> j++;</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><h2 id="201409-2画图"><a href="#201409-2画图" class="headerlink" title="201409-2画图"></a>201409-2画图</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//模拟 100*100*100 == 15ms</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><br><span class="line"><span class="keyword">bool</span> m[<span class="number">110</span>][<span class="number">110</span>];</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> n;</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"</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="keyword">int</span> x1,y1, x2,y2;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d %d %d"</span>, &x1, &y1, &x2, &y2);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> x=x1;x<x2;x++){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> y=y1;y<y2;y++){</span><br><span class="line"> m[x][y] = <span class="literal">true</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">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> x=<span class="number">0</span>;x<=<span class="number">100</span>;x++){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> y=<span class="number">0</span>;y<=<span class="number">100</span>;y++){</span><br><span class="line"> ans += m[x][y];</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><h2 id="201409-3字符串匹配"><a href="#201409-3字符串匹配" class="headerlink" title="201409-3字符串匹配"></a>201409-3字符串匹配</h2><figure class="highlight cpp"><table><tr><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="keyword">int</span> n;</span><br><span class="line"><span class="built_in">string</span> tar;</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> >> tar;</span><br><span class="line"> <span class="keyword">int</span> opt;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d "</span>, &opt, &n);</span><br><span class="line"> <span class="keyword">if</span>(opt==<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<tar.size();i++)</span><br><span class="line"> tar[i] = <span class="built_in">tolower</span>(tar[i]);</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">string</span> 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="built_in">cin</span> >> line;</span><br><span class="line"> <span class="built_in">string</span> nline = line;</span><br><span class="line"> <span class="keyword">if</span>(opt==<span class="number">0</span>){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j<nline.size();j++)</span><br><span class="line"> nline[j] = <span class="built_in">tolower</span>(nline[j]);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(nline.rfind(tar)!=<span class="built_in">string</span>::npos){</span><br><span class="line"> <span class="built_in">cout</span> << line << <span class="built_in">endl</span>;</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><h2 id="201409-4最优配餐"><a href="#201409-4最优配餐" class="headerlink" title="201409-4最优配餐"></a>201409-4最优配餐</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 传统bfs</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><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn = <span class="number">1000</span> + <span class="number">10</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> board[maxn][maxn];</span><br><span class="line"><span class="keyword">long</span> <span class="keyword">long</span> num[maxn][maxn];</span><br><span class="line"><span class="keyword">int</span> n,m,k,d;</span><br><span class="line"><span class="keyword">long</span> <span class="keyword">long</span> ans;</span><br><span class="line"></span><br><span class="line"><span class="keyword">bool</span> visit[maxn][maxn];</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">vertex</span>{</span></span><br><span class="line"> <span class="keyword">int</span> x;</span><br><span class="line"> <span class="keyword">int</span> y;</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">bool</span> <span class="title">outbound</span><span class="params">(<span class="keyword">const</span> vertex & v)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(v.x<=<span class="number">0</span>||v.y<=<span class="number">0</span>||v.x>n||v.y>n) <span class="keyword">return</span> <span class="literal">true</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">vertex <span class="title">v2d</span><span class="params">(<span class="keyword">const</span> vertex & v, <span class="keyword">int</span> d)</span></span>{</span><br><span class="line"> <span class="keyword">switch</span>(d){</span><br><span class="line"> <span class="keyword">case</span> <span class="number">0</span>: <span class="keyword">return</span> {v.x<span class="number">-1</span>,v.y};<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">1</span>: <span class="keyword">return</span> {v.x,v.y<span class="number">-1</span>};<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">2</span>: <span class="keyword">return</span> {v.x+<span class="number">1</span>,v.y};<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">3</span>: <span class="keyword">return</span> {v.x,v.y+<span class="number">1</span>};<span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> {<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 class="function"><span class="keyword">void</span> <span class="title">bfs</span><span class="params">(<span class="built_in">vector</span> <vertex> N)</span></span>{</span><br><span class="line"> <span class="built_in">vector</span> <vertex> T;</span><br><span class="line"> <span class="keyword">int</span> plen = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">while</span>(N.size()){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">auto</span> u:N){</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">auto</span> v = v2d(u, i);</span><br><span class="line"> <span class="keyword">if</span>(outbound(v)||visit[v.x][v.y]||board[v.x][v.y]==<span class="number">3</span>) <span class="keyword">continue</span>;</span><br><span class="line"> visit[v.x][v.y] = <span class="literal">true</span>;</span><br><span class="line"> T.push_back(v);</span><br><span class="line"> <span class="keyword">if</span>(board[v.x][v.y]==<span class="number">2</span>){</span><br><span class="line"> ans += plen*num[v.x][v.y];</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> N = T;</span><br><span class="line"> T.clear();</span><br><span class="line"> plen++;</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">scanf</span>(<span class="string">"%d %d %d %d"</span>, &n, &m, &k, &d);</span><br><span class="line"> <span class="built_in">vector</span> <vertex> S;</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> x,y;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d"</span>, &x, &y);</span><br><span class="line"> board[x][y] = <span class="number">1</span>;</span><br><span class="line"> S.push_back({x, y});</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">//客户</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"> <span class="keyword">int</span> x,y,val;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d %d"</span>, &x, &y, &val);</span><br><span class="line"> <span class="keyword">if</span>(board[x][y]!=<span class="number">1</span>){</span><br><span class="line"> board[x][y] = <span class="number">2</span>;</span><br><span class="line"> num[x][y] += val;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">//3</span></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<d;i++){</span><br><span class="line"> <span class="keyword">int</span> x,y;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d"</span>, &x, &y);</span><br><span class="line"> board[x][y] = <span class="number">3</span>;</span><br><span class="line"> }</span><br><span class="line"> bfs(S);</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><h2 id="201409-5拼图"><a href="#201409-5拼图" class="headerlink" title="201409-5拼图"></a>201409-5拼图</h2><h2 id><a href="#" class="headerlink" title></a><a href="/2019/09/10/csp-intergrated/" title="csp题集汇总">csp题集汇总</a></h2><hr>]]></content>
<categories>
<category> csp </category>
</categories>
<tags>
<tag> csp </tag>
</tags>
</entry>
<entry>
<title>csp-201403</title>
<link href="/2019/09/13/csp-201403/"/>
<url>/2019/09/13/csp-201403/</url>
<content type="html"><![CDATA[<h2 id="201403-1-相反数"><a href="#201403-1-相反数" class="headerlink" title="201403-1 相反数"></a>201403-1 相反数</h2><figure class="highlight cpp"><table><tr><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="keyword">const</span> <span class="keyword">int</span> maxn = <span class="number">1010</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">bool</span> pos[maxn], neg[maxn];</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="keyword">int</span> val;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &val);</span><br><span class="line"> <span class="keyword">if</span>(val><span class="number">0</span>){</span><br><span class="line"> pos[val] = <span class="literal">true</span>;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> neg[-val] = <span class="literal">true</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">int</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<=<span class="number">1000</span>;i++){</span><br><span class="line"> <span class="keyword">if</span>(pos[i] && neg[i]){</span><br><span class="line"> ans++;</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><h2 id="201403-2-窗口"><a href="#201403-2-窗口" class="headerlink" title="201403-2 窗口"></a>201403-2 窗口</h2><figure class="highlight cpp"><table><tr><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="class"><span class="keyword">struct</span> <span class="title">RECTAN</span>{</span></span><br><span class="line"> <span class="keyword">int</span> x1;</span><br><span class="line"> <span class="keyword">int</span> y1;</span><br><span class="line"> <span class="keyword">int</span> x2;</span><br><span class="line"> <span class="keyword">int</span> y2;</span><br><span class="line"> <span class="keyword">int</span> idx;</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><br><span class="line"><span class="built_in">deque</span> <RECTAN> pool;</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, &M);</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> x1, y1,x2, y2;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d %d %d"</span>, &x1, &y1, &x2, &y2);</span><br><span class="line"> pool.push_front({x1, y1,x2, y2, 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">int</span> x,y;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d"</span>, &x, &y);</span><br><span class="line"> <span class="built_in">deque</span><RECTAN>::iterator it;</span><br><span class="line"> <span class="keyword">bool</span> flag=<span class="literal">false</span>;</span><br><span class="line"> <span class="keyword">for</span>(it=pool.begin();it!=pool.end();it++){</span><br><span class="line"> <span class="keyword">auto</span> rec = *it;</span><br><span class="line"> <span class="keyword">if</span>(x>=rec.x1 && x<=rec.x2 && y>=rec.y1 && y<=rec.y2){</span><br><span class="line"> flag=<span class="literal">true</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><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d\n"</span>, it->idx);</span><br><span class="line"> <span class="keyword">auto</span> rec = *it;</span><br><span class="line"> pool.erase(it);</span><br><span class="line"> pool.push_front(rec);</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"IGNORED\n"</span>);</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><h2 id="201403-3-命令行选项"><a href="#201403-3-命令行选项" class="headerlink" title="201403-3 命令行选项"></a>201403-3 命令行选项</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//map 的用法不熟悉</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="built_in">map</span> <<span class="keyword">char</span>, <span class="keyword">bool</span>> format;</span><br><span class="line"><span class="built_in">map</span> <<span class="keyword">char</span>, <span class="built_in">string</span>> ans;</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> n;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">SplitString</span><span class="params">(<span class="keyword">const</span> <span class="built_in">string</span>& s, <span class="built_in">deque</span><<span class="built_in">string</span>>& v, <span class="keyword">const</span> <span class="built_in">string</span>& c)</span></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">char</span> old;</span><br><span class="line"> <span class="keyword">while</span>(<span class="number">1</span>){</span><br><span class="line"> <span class="keyword">char</span> c = getchar();</span><br><span class="line"> <span class="keyword">if</span>(c==<span class="string">'\n'</span>){</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(c==<span class="string">':'</span>){</span><br><span class="line"> format[old] = <span class="literal">true</span>;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> format[c] = <span class="literal">false</span>;</span><br><span class="line"> }</span><br><span class="line"> old = c;</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// for(auto m : format){</span></span><br><span class="line"> <span class="comment">// printf("%c %d\n", m.first, m.second);</span></span><br><span class="line"> <span class="comment">// }</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">string</span> 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"> ans.clear();</span><br><span class="line"> getline(<span class="built_in">cin</span>, line);</span><br><span class="line"> <span class="built_in">deque</span> <<span class="built_in">string</span>>vs;</span><br><span class="line"> SplitString(line, vs, <span class="string">" "</span>);</span><br><span class="line"> vs.pop_front();</span><br><span class="line"> <span class="comment">// for(auto v:vs){</span></span><br><span class="line"> <span class="comment">// cout << v << "," << endl;</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> <span class="built_in">deque</span> <<span class="built_in">string</span>> ::iterator it = vs.begin();</span><br><span class="line"> <span class="keyword">while</span>(it!=vs.end()){</span><br><span class="line"> <span class="keyword">auto</span> s = *it;</span><br><span class="line"> <span class="keyword">if</span>(s[<span class="number">0</span>]==<span class="string">'-'</span>&&s.size()==<span class="number">2</span>){</span><br><span class="line"> <span class="keyword">char</span> arg=s[<span class="number">1</span>];</span><br><span class="line"> <span class="keyword">if</span>(format.find(arg)==format.end())</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> <span class="comment">//with arg</span></span><br><span class="line"> <span class="keyword">if</span>(format[arg]){</span><br><span class="line"> it++;</span><br><span class="line"> <span class="keyword">if</span>(it==vs.end()) <span class="keyword">break</span>;</span><br><span class="line"> ans[arg] = *it;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> ans[arg] = <span class="string">""</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">break</span>;</span><br><span class="line"> }</span><br><span class="line"> it++;</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"Case %d:"</span>, i);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">auto</span> a: ans){</span><br><span class="line"> <span class="keyword">if</span>(format[a.first]){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">" -%c %s"</span>, a.first, a.second.c_str());</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">" -%c"</span>, a.first);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">putchar</span>(<span class="string">'\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><span class="line"></span><br><span class="line"><span class="comment">//字符串分割函数</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">SplitString</span><span class="params">(<span class="keyword">const</span> <span class="built_in">string</span>& s, <span class="built_in">deque</span><<span class="built_in">string</span>>& v, <span class="keyword">const</span> <span class="built_in">string</span>& c)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"><span class="built_in">string</span>::size_type pos1, pos2;</span><br><span class="line">pos2 = s.find(c);</span><br><span class="line">pos1 = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">while</span>(<span class="built_in">string</span>::npos != pos2)</span><br><span class="line">{</span><br><span class="line">v.push_back(s.substr(pos1, pos2-pos1));</span><br><span class="line">pos1 = pos2 + c.size();</span><br><span class="line">pos2 = s.find(c, pos1);</span><br><span class="line">}</span><br><span class="line"><span class="keyword">if</span>(pos1 != s.length())</span><br><span class="line">v.push_back(s.substr(pos1));</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="201403-4-无线网络"><a href="#201403-4-无线网络" class="headerlink" title="201403-4 无线网络"></a>201403-4 无线网络</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//dfs + dp 好题 70</span></span><br><span class="line"><span class="comment">//觉得网上的题解有问题</span></span><br><span class="line"></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><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn = <span class="number">210</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxm = <span class="number">210</span>*<span class="number">210</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> head[maxn], cnt=<span class="number">0</span>;<span class="comment">//head用来表示以i为起点的第一条边存储的位置,cnt读入边的计数器</span></span><br><span class="line"><span class="keyword">int</span> n,m,k,r;</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="class">{</span></span><br><span class="line"> <span class="keyword">int</span> next; <span class="comment">//同一起点的上一条边的储存位置</span></span><br><span class="line"> <span class="keyword">int</span> to; <span class="comment">//第i条边的终点</span></span><br><span class="line">};</span><br><span class="line"></span><br><span class="line">Edge edge[maxm];</span><br><span class="line"></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 class="comment">//读入边</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> edge[cnt].to = v;</span><br><span class="line"> edge[cnt].next = head[u];</span><br><span class="line"> head[u] = cnt++;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">read</span><span class="params">()</span> <span class="comment">//遍历所有边</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">0</span>; i<=n; i++){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d:"</span>, i);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=head[i]; j!=<span class="number">-1</span>; j=edge[j].next){</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"%d "</span>, edge[j].to);</span><br><span class="line">}</span><br><span class="line"> <span class="built_in">putchar</span>(<span class="string">'\n'</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> gx[maxn],gy[maxn];</span><br><span class="line"><span class="keyword">int</span> dp[maxn][maxn];</span><br><span class="line"><span class="keyword">bool</span> visit[maxn];</span><br><span class="line"><span class="keyword">bool</span> uncertain[maxn];</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">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 %d"</span>, &n, &m, &k, &r);</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>, &gx[i], &gy[i]);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=n+<span class="number">1</span>;i<=n+m;i++){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d"</span>, &gx[i], &gy[i]);</span><br><span class="line"> uncertain[i] = <span class="literal">true</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<=n+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<=n+m;j++){</span><br><span class="line"> <span class="keyword">long</span> <span class="keyword">long</span> d = (gx[i]-gx[j])*(gx[i]-gx[j]) + (gy[i]-gy[j])*(gy[i]-gy[j]);</span><br><span class="line"> <span class="keyword">long</span> <span class="keyword">long</span> r2 = r*r;</span><br><span class="line"> <span class="keyword">if</span>(d <= r2){</span><br><span class="line"> add(i, j);</span><br><span class="line"> add(j, i);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// read();</span></span><br><span class="line"> <span class="built_in">memset</span>(dp, <span class="number">-1</span>, <span class="keyword">sizeof</span>(dp));</span><br><span class="line"> <span class="built_in">vector</span> <<span class="keyword">int</span>> Ng, T;</span><br><span class="line"> Ng.push_back(<span class="number">1</span>);</span><br><span class="line"> visit[<span class="number">1</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<maxn;i++) dp[<span class="number">1</span>][i] = <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">while</span>(Ng.size()){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">auto</span> u: Ng){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=head[u];j!=<span class="number">-1</span>;j=edge[j].next){</span><br><span class="line"> <span class="keyword">int</span> v = edge[j].to;</span><br><span class="line"> <span class="keyword">if</span>(visit[v]) <span class="keyword">continue</span>;</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">if</span>(uncertain[v]){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=k;i++){</span><br><span class="line"> <span class="keyword">if</span>(dp[u][i<span class="number">-1</span>]==<span class="number">-1</span>) <span class="keyword">continue</span>;</span><br><span class="line"> <span class="keyword">if</span>(dp[v][i] < dp[u][i<span class="number">-1</span>]+<span class="number">1</span>)</span><br><span class="line"> dp[v][i] = dp[u][i<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><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"> <span class="keyword">if</span>(dp[u][i]==<span class="number">-1</span>) <span class="keyword">continue</span>;</span><br><span class="line"> <span class="keyword">if</span>(dp[v][i] < dp[u][i]+<span class="number">1</span>)</span><br><span class="line"> dp[v][i] = dp[u][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"> T.push_back(v);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">auto</span> v : T) visit[v] = <span class="literal">true</span>;</span><br><span class="line"> Ng = T;</span><br><span class="line"> T.clear();</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d\n"</span>, dp[<span class="number">2</span>][k]<span class="number">-1</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><h2 id="201403-5-任务调度"><a href="#201403-5-任务调度" class="headerlink" title="201403-5 任务调度"></a>201403-5 任务调度</h2><h2 id><a href="#" class="headerlink" title></a><a href="/2019/09/10/csp-intergrated/" title="csp题集汇总">csp题集汇总</a></h2><hr>]]></content>
<categories>
<category> csp </category>
</categories>
<tags>
<tag> csp </tag>
</tags>
</entry>
<entry>
<title>csp-201312</title>
<link href="/2019/09/13/csp-201312/"/>
<url>/2019/09/13/csp-201312/</url>
<content type="html"><![CDATA[<h2 id="201312-1-出现次数最多的数"><a href="#201312-1-出现次数最多的数" class="headerlink" title="201312-1 出现次数最多的数"></a>201312-1 出现次数最多的数</h2><figure class="highlight cpp"><table><tr><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="keyword">int</span> a[<span class="number">10010</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">scanf</span>(<span class="string">"%d"</span>, &n);</span><br><span class="line"> <span class="keyword">int</span> mmax=<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<n;i++){</span><br><span class="line"> <span class="keyword">int</span> val;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &val);</span><br><span class="line"> a[val]++;</span><br><span class="line"> mmax = max(mmax, a[val]);</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">10000</span>;i++){</span><br><span class="line"> <span class="keyword">if</span>(a[i]==mmax){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d\n"</span>, i);</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">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="201312-2-ISBN号码"><a href="#201312-2-ISBN号码" class="headerlink" title="201312-2 ISBN号码"></a>201312-2 ISBN号码</h2><figure class="highlight cpp"><table><tr><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> a[<span class="number">10</span>];</span><br><span class="line"> <span class="built_in">string</span> code;</span><br><span class="line"> <span class="built_in">cin</span> >> code;</span><br><span class="line"> a[<span class="number">0</span>] = code[<span class="number">0</span>]-<span class="string">'0'</span>;</span><br><span class="line"> a[<span class="number">1</span>] = code[<span class="number">2</span>]-<span class="string">'0'</span>;</span><br><span class="line"> a[<span class="number">2</span>] = code[<span class="number">3</span>]-<span class="string">'0'</span>;</span><br><span class="line"> a[<span class="number">3</span>] = code[<span class="number">4</span>]-<span class="string">'0'</span>;</span><br><span class="line"> a[<span class="number">4</span>] = code[<span class="number">6</span>]-<span class="string">'0'</span>;</span><br><span class="line"> a[<span class="number">5</span>] = code[<span class="number">7</span>]-<span class="string">'0'</span>;</span><br><span class="line"> a[<span class="number">6</span>] = code[<span class="number">8</span>]-<span class="string">'0'</span>;</span><br><span class="line"> a[<span class="number">7</span>] = code[<span class="number">9</span>]-<span class="string">'0'</span>;</span><br><span class="line"> a[<span class="number">8</span>] = code[<span class="number">10</span>]-<span class="string">'0'</span>;</span><br><span class="line"> a[<span class="number">9</span>] = code[<span class="number">12</span>]==<span class="string">'X'</span>?<span class="number">10</span>:code[<span class="number">12</span>]-<span class="string">'0'</span>;</span><br><span class="line"> <span class="keyword">int</span> res = <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<=<span class="number">9</span>;i++){</span><br><span class="line"> res += (a[i<span class="number">-1</span>]*i);</span><br><span class="line"> }</span><br><span class="line"> res = res % <span class="number">11</span>;</span><br><span class="line"> <span class="keyword">if</span>(res==a[<span class="number">9</span>]){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"Right\n"</span>);</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> code[<span class="number">12</span>] = res==<span class="number">10</span>?<span class="string">'X'</span>:res+<span class="string">'0'</span>;</span><br><span class="line"> <span class="built_in">cout</span> << code << <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><h2 id="201312-3-最大的矩形"><a href="#201312-3-最大的矩形" class="headerlink" title="201312-3 最大的矩形"></a>201312-3 最大的矩形</h2><figure class="highlight cpp"><table><tr><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><br><span class="line"><span class="keyword">int</span> a[<span class="number">1010</span>];</span><br><span class="line"><span class="keyword">int</span> dp[<span class="number">1010</span>][<span class="number">1010</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">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><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &a[i]);</span><br><span class="line"> dp[i][i] = a[i];</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">int</span> mmax=<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">for</span>(<span class="keyword">int</span> j=i+<span class="number">1</span>;j<=n;j++){</span><br><span class="line"> <span class="comment">// printf("DEBUG :%d\n", dp[i][j]);</span></span><br><span class="line"> dp[i][j] = min(dp[i][j<span class="number">-1</span>], a[j]);</span><br><span class="line"> mmax = max((j-i+<span class="number">1</span>)*dp[i][j], mmax);</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>, mmax);</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><h2 id="201312-4-有趣的数"><a href="#201312-4-有趣的数" class="headerlink" title="201312-4 有趣的数"></a>201312-4 有趣的数</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//回溯 判断没有return 栈溢出出错</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><br><span class="line"><span class="keyword">typedef</span> <span class="keyword">unsigned</span> <span class="keyword">long</span> <span class="keyword">long</span> ull;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn=<span class="number">1001</span>;</span><br><span class="line"></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> prime (1000000007)</span></span><br><span class="line"></span><br><span class="line">ull C[maxn][maxn];</span><br><span class="line"><span class="keyword">int</span> n;</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> num[<span class="number">8</span>];</span><br><span class="line">ull ans;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">fun</span><span class="params">(<span class="keyword">int</span> s, <span class="keyword">int</span> k)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(k < <span class="number">4</span> - s) <span class="keyword">return</span>;</span><br><span class="line"> <span class="keyword">if</span>(s==<span class="number">3</span>){</span><br><span class="line"> num[<span class="number">3</span>] = k;</span><br><span class="line"> ans = (ans + C[n<span class="number">-1</span>][num[<span class="number">0</span>]+num[<span class="number">1</span>]])%prime;</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=<span class="number">1</span>;i<=k;i++){</span><br><span class="line"> num[s] = i;</span><br><span class="line"> fun(s+<span class="number">1</span>, k-i);</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"</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"> C[i][<span class="number">1</span>] = 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">2</span>;i<=n;i++){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=i;j<=n;j++){</span><br><span class="line"> C[j][i] = (C[j<span class="number">-1</span>][i<span class="number">-1</span>] + C[j<span class="number">-1</span>][i])%prime;</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">2</span>;i<=n<span class="number">-2</span>;i++){</span><br><span class="line"> ans=(ans+C[n<span class="number">-1</span>][i<span class="number">-1</span>]*(i<span class="number">-1</span>)*(n-i<span class="number">-1</span>))%prime;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">// for(int i=1;i<=n;i++){</span></span><br><span class="line"> <span class="comment">// for(int j=1;j<=n;j++){</span></span><br><span class="line"> <span class="comment">// printf("C[%d][%d]:%llu\n", i, j, C[i][j]);</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"></span><br><span class="line"> <span class="comment">// fun(0, n);</span></span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%llu\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><h2 id="201312-5-I’m-stuck"><a href="#201312-5-I’m-stuck" class="headerlink" title="201312-5 I’m stuck"></a>201312-5 I’m stuck</h2><figure class="highlight cpp"><table><tr><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="keyword">char</span> bo[<span class="number">55</span>][<span class="number">55</span>];</span><br><span class="line"><span class="keyword">int</span> R,C;</span><br><span class="line"><span class="keyword">int</span> sx,sy,tx,ty;</span><br><span class="line"></span><br><span class="line"><span class="keyword">bool</span> fvi[<span class="number">55</span>][<span class="number">55</span>];</span><br><span class="line"><span class="keyword">bool</span> bvi[<span class="number">55</span>][<span class="number">55</span>];</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">fdfs</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>(x==<span class="number">0</span>||x>R||y==<span class="number">0</span>||y>C) <span class="keyword">return</span> ;</span><br><span class="line"> <span class="keyword">if</span>(fvi[x][y]) <span class="keyword">return</span>;</span><br><span class="line"> fvi[x][y] = <span class="literal">true</span>;</span><br><span class="line"> <span class="keyword">switch</span>(bo[x][y]){</span><br><span class="line"> <span class="keyword">case</span> <span class="string">'S'</span>: </span><br><span class="line"> <span class="keyword">case</span> <span class="string">'T'</span>:</span><br><span class="line"> <span class="keyword">case</span> <span class="string">'+'</span>: fdfs(x<span class="number">-1</span>,y),fdfs(x+<span class="number">1</span>,y),fdfs(x,y<span class="number">-1</span>),fdfs(x,y+<span class="number">1</span>);<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">'-'</span>: fdfs(x,y<span class="number">-1</span>),fdfs(x,y+<span class="number">1</span>);<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">'|'</span>: fdfs(x<span class="number">-1</span>,y),fdfs(x+<span class="number">1</span>,y);<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">'.'</span>: fdfs(x+<span class="number">1</span>,y);<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="string">'#'</span>: <span class="keyword">return</span>;</span><br><span class="line"> }</span><br><span class="line">}</span><br><span class="line"><span class="comment">// 1</span></span><br><span class="line"><span class="comment">//0 2</span></span><br><span class="line"><span class="comment">// 3</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">tdfs</span><span class="params">(<span class="keyword">int</span> x, <span class="keyword">int</span> y, <span class="keyword">int</span> d)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(x==<span class="number">0</span>||x>R||y==<span class="number">0</span>||y>C) <span class="keyword">return</span>;</span><br><span class="line"> <span class="keyword">if</span>(bvi[x][y]) <span class="keyword">return</span>;</span><br><span class="line"> <span class="keyword">char</span> c = bo[x][y]; </span><br><span class="line"> <span class="keyword">if</span>(c==<span class="string">'#'</span>) <span class="keyword">return</span>;</span><br><span class="line"> <span class="keyword">switch</span>(d){</span><br><span class="line"> <span class="keyword">case</span> <span class="number">0</span>: {</span><br><span class="line"> <span class="keyword">if</span>(c==<span class="string">'|'</span>||c==<span class="string">'.'</span>) <span class="keyword">return</span>;</span><br><span class="line"> }<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">1</span>: {</span><br><span class="line"> <span class="keyword">if</span>(c==<span class="string">'-'</span>) <span class="keyword">return</span>;</span><br><span class="line"> }<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">2</span>: {</span><br><span class="line"> <span class="keyword">if</span>(c==<span class="string">'|'</span>||c==<span class="string">'.'</span>) <span class="keyword">return</span>;</span><br><span class="line"> }<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">3</span>: {</span><br><span class="line"> <span class="keyword">if</span>(c==<span class="string">'-'</span>||c==<span class="string">'.'</span>) <span class="keyword">return</span>;</span><br><span class="line"> }<span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> bvi[x][y] = <span class="literal">true</span>;</span><br><span class="line"> tdfs(x, y<span class="number">-1</span>, <span class="number">0</span>);</span><br><span class="line"> tdfs(x<span class="number">-1</span>, y, <span class="number">1</span>);</span><br><span class="line"> tdfs(x, y+<span class="number">1</span>, <span class="number">2</span>);</span><br><span class="line"> tdfs(x+<span class="number">1</span>, y, <span class="number">3</span>);</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>, &R, &C);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=R;i++){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">" "</span>);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j<=C;j++){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%c"</span>, &bo[i][j]);</span><br><span class="line"> <span class="keyword">if</span>(bo[i][j]==<span class="string">'S'</span>){</span><br><span class="line"> sx=i,sy=j;</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(bo[i][j]==<span class="string">'T'</span>){</span><br><span class="line"> tx=i,ty=j;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> fdfs(sx, sy);</span><br><span class="line"> tdfs(tx, ty, <span class="number">0</span>);</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> i=<span class="number">1</span>;i<=R;i++){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">1</span>;j<=C;j++){</span><br><span class="line"> <span class="keyword">if</span>(fvi[i][j]&&!bvi[i][j]&&bo[i][j]!=<span class="string">'#'</span>){</span><br><span class="line"> <span class="comment">// putchar('X');</span></span><br><span class="line"> cnt++;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// putchar('\n');</span></span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(<span class="keyword">not</span> fvi[tx][ty]){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"I'm stuck!\n"</span>);</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\n"</span>, cnt);</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><h2 id><a href="#" class="headerlink" title></a><a href="/2019/09/10/csp-intergrated/" title="csp题集汇总">csp题集汇总</a></h2><hr>]]></content>
<categories>
<category> csp </category>
</categories>
<tags>
<tag> csp </tag>
</tags>
</entry>
<entry>
<title>csp-201703</title>
<link href="/2019/09/10/csp-201703/"/>
<url>/2019/09/10/csp-201703/</url>
<content type="html"><![CDATA[<h2 id="201703-1-分蛋糕"><a href="#201703-1-分蛋糕" class="headerlink" title="201703-1 分蛋糕"></a>201703-1 分蛋糕</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><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><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="meta">#<span class="meta-keyword">define</span> Max_N 10001</span></span><br><span class="line"><span class="keyword">int</span> ca[Max_N];</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, k;</span><br><span class="line"><span class="keyword">int</span> num, wei;</span><br><span class="line"><span class="built_in">cin</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">cin</span> >> ca[i];</span><br><span class="line">}</span><br><span class="line">num = <span class="number">0</span>, wei=<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<n;i++){</span><br><span class="line">wei += ca[i];</span><br><span class="line"><span class="keyword">if</span>(wei >= k){</span><br><span class="line">wei = <span class="number">0</span>;</span><br><span class="line">num ++;</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"><span class="keyword">if</span>(wei) num++;</span><br><span class="line"><span class="built_in">cout</span> << num << <span class="built_in">endl</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="201703-2-学生排队"><a href="#201703-2-学生排队" class="headerlink" title="201703-2 学生排队"></a>201703-2 学生排队</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//vector 满足的特性</span></span><br><span class="line"><span class="comment">//迭代器失效</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><br><span class="line"><span class="built_in">vector</span> <<span class="keyword">int</span>> 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,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<=n;i++){</span><br><span class="line">line.push_back(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">int</span> p,q;</span><br><span class="line"><span class="built_in">scanf</span>(<span class="string">"%d %d"</span>, &p, &q);</span><br><span class="line"><span class="keyword">auto</span> it = find(line.begin(), line.end(), p);</span><br><span class="line">it = line.erase(it);</span><br><span class="line">it+=q;</span><br><span class="line">line.insert(it, p);</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<line.size();i++){</span><br><span class="line"><span class="keyword">if</span>(i!=<span class="number">0</span>)</span><br><span class="line"><span class="built_in">putchar</span>(<span class="string">' '</span>);</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"%d"</span>, line[i]);</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><h2 id="201703-3-Markdown"><a href="#201703-3-Markdown" class="headerlink" title="201703-3 Markdown"></a>201703-3 Markdown</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//90 注意看题 不留空行</span></span><br><span class="line"><span class="comment">// getline 空行得空字符串</span></span><br><span class="line"><span class="comment">// accumulate empty做初始</span></span><br><span class="line"><span class="comment">// stringstream 的用法 fail为读完</span></span><br><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"><iostream></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><string></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"><vector></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"><sstream></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="function"><span class="keyword">void</span> <span class="title">SplitString</span><span class="params">(<span class="keyword">const</span> <span class="built_in">string</span>& s, <span class="built_in">vector</span><<span class="built_in">string</span>>& v, <span class="keyword">const</span> <span class="built_in">string</span>& c)</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">printv</span><span class="params">(<span class="built_in">vector</span> <<span class="built_in">string</span>> & vs)</span></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">void</span> <span class="title">inparse</span><span class="params">(<span class="built_in">string</span> & line, <span class="built_in">vector</span> <<span class="built_in">string</span>> & vs)</span></span>{</span><br><span class="line"><span class="keyword">char</span> c;</span><br><span class="line"><span class="function"><span class="built_in">stringstream</span> <span class="title">is</span> <span class="params">(line)</span></span>;</span><br><span class="line"><span class="built_in">string</span> tmp;</span><br><span class="line"><span class="keyword">while</span>(is.get(c), <span class="keyword">not</span> is.fail()){</span><br><span class="line"><span class="comment">// cout <<"DE<span class="doctag">BUG:</span>" << c << endl;</span></span><br><span class="line"><span class="keyword">if</span>(c==<span class="string">'_'</span>){</span><br><span class="line">vs.push_back(tmp);</span><br><span class="line">tmp.clear();</span><br><span class="line"><span class="keyword">while</span>(is.get(c), c!=<span class="string">'_'</span>) tmp+=c;</span><br><span class="line">vs.push_back(<span class="string">"<em>"</span> + tmp + <span class="string">"</em>"</span>);</span><br><span class="line">tmp.clear();</span><br><span class="line"><span class="comment">// printv(vs);</span></span><br><span class="line">}<span class="keyword">else</span> <span class="keyword">if</span>(c==<span class="string">'['</span>){</span><br><span class="line">vs.push_back(tmp);</span><br><span class="line">tmp.clear();</span><br><span class="line"><span class="built_in">string</span> Text, Link;</span><br><span class="line"><span class="keyword">while</span>(is.get(c), c!=<span class="string">']'</span>) Text+=c;</span><br><span class="line"><span class="keyword">while</span>(is.get(c), c!=<span class="string">'('</span>);</span><br><span class="line"><span class="keyword">while</span>(is.get(c), c!=<span class="string">')'</span>) Link+=c;</span><br><span class="line">vs.push_back(<span class="string">"<a href=\""</span>+Link+<span class="string">"\">"</span>+Text+<span class="string">"</a>"</span>);</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line">tmp+=c;</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line">vs.push_back(tmp);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="built_in">string</span> empty = <span class="string">""</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="built_in">vector</span> <<span class="built_in">string</span>> vs;</span><br><span class="line"><span class="built_in">string</span> line;</span><br><span class="line"><span class="keyword">while</span>(getline(<span class="built_in">cin</span>, line)) {</span><br><span class="line"><span class="keyword">if</span>(line==<span class="string">""</span>) {</span><br><span class="line"><span class="keyword">continue</span>;</span><br><span class="line">}</span><br><span class="line">vs.clear();</span><br><span class="line"><span class="function"><span class="built_in">stringstream</span> <span class="title">is</span> <span class="params">(line)</span></span>;</span><br><span class="line"><span class="built_in">string</span> head;</span><br><span class="line">is >> head;</span><br><span class="line"><span class="comment">// printf("DEBUG head:%s\n", head.c_str());</span></span><br><span class="line"><span class="keyword">if</span>(head[<span class="number">0</span>] == <span class="string">'*'</span>){</span><br><span class="line"><span class="keyword">size_t</span> spos;</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"<ul>\n"</span>);</span><br><span class="line"><span class="keyword">while</span>((spos=line.find(<span class="string">"*"</span>))!=<span class="built_in">string</span>::npos){</span><br><span class="line">vs.insert(vs.begin(), <span class="string">"<li>"</span>);</span><br><span class="line"><span class="built_in">string</span> newline = line.substr(line.find_first_not_of(<span class="string">'*'</span>, spos)+<span class="number">1</span>);</span><br><span class="line">inparse(newline, vs);</span><br><span class="line">vs.push_back(<span class="string">"</li>"</span>);</span><br><span class="line"><span class="built_in">cout</span> << accumulate(vs.begin(), vs.end(), empty) << <span class="built_in">endl</span>;</span><br><span class="line">vs.clear();</span><br><span class="line"><span class="keyword">if</span>(<span class="keyword">not</span> getline(<span class="built_in">cin</span>, line))<span class="keyword">break</span>;</span><br><span class="line">}</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"</ul>\n"</span>);</span><br><span class="line">}<span class="keyword">else</span> <span class="keyword">if</span>(head[<span class="number">0</span>] == <span class="string">'#'</span>){</span><br><span class="line"><span class="keyword">size_t</span> spos = line.find(<span class="string">"#"</span>);</span><br><span class="line"><span class="keyword">size_t</span> epos = line.find_first_not_of(<span class="string">"#"</span>, spos);</span><br><span class="line"><span class="keyword">int</span> num = epos - spos;</span><br><span class="line"><span class="built_in">string</span> Hnum = <span class="string">"h"</span>+to_string(num);</span><br><span class="line">vs.push_back(<span class="string">"<"</span>+Hnum+<span class="string">">"</span>);</span><br><span class="line"><span class="comment">// printv(vs);</span></span><br><span class="line"><span class="built_in">string</span> newline = line.substr(epos+<span class="number">1</span>);</span><br><span class="line"><span class="comment">// printf("DE<span class="doctag">BUG:</span> newline:%s\n", newline.c_str());</span></span><br><span class="line">inparse(newline, vs);</span><br><span class="line">vs.push_back(<span class="string">"</"</span>+Hnum+<span class="string">">"</span>);</span><br><span class="line"><span class="built_in">cout</span> << accumulate(vs.begin(), vs.end(), empty) << <span class="built_in">endl</span>;</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line">vs.push_back(<span class="string">"<p>"</span>);</span><br><span class="line"><span class="keyword">while</span>(<span class="number">1</span>){</span><br><span class="line">inparse(line, vs);</span><br><span class="line"><span class="keyword">if</span>(<span class="keyword">not</span> getline(<span class="built_in">cin</span>, line)) <span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">if</span>(line==<span class="string">""</span>) <span class="keyword">break</span>;</span><br><span class="line">vs.push_back(<span class="string">"\n"</span>);</span><br><span class="line">}</span><br><span class="line">vs.push_back(<span class="string">"</p>"</span>);</span><br><span class="line"><span class="built_in">cout</span> << accumulate(vs.begin(), vs.end(), empty) << <span class="built_in">endl</span>;</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="comment">//字符串分割函数</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">SplitString</span><span class="params">(<span class="keyword">const</span> <span class="built_in">string</span>& s, <span class="built_in">vector</span><<span class="built_in">string</span>>& v, <span class="keyword">const</span> <span class="built_in">string</span>& c)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"><span class="built_in">string</span>::size_type pos1, pos2;</span><br><span class="line">pos2 = s.find(c);</span><br><span class="line">pos1 = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">while</span>(<span class="built_in">string</span>::npos != pos2)</span><br><span class="line">{</span><br><span class="line">v.push_back(s.substr(pos1, pos2-pos1));</span><br><span class="line">pos1 = pos2 + c.size();</span><br><span class="line">pos2 = s.find(c, pos1);</span><br><span class="line">}</span><br><span class="line"><span class="keyword">if</span>(pos1 != s.length())</span><br><span class="line">v.push_back(s.substr(pos1));</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">printv</span><span class="params">(<span class="built_in">vector</span> <<span class="built_in">string</span>> & vs)</span></span>{</span><br><span class="line"><span class="built_in">vector</span> <<span class="built_in">string</span>> ::iterator it;</span><br><span class="line"><span class="comment">// printf("DE<span class="doctag">BUG:</span>||");</span></span><br><span class="line"><span class="keyword">for</span>(it=vs.begin();it!=vs.end();it++){</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"%s||\n"</span>, (*it).c_str());</span><br><span class="line">}</span><br><span class="line"><span class="built_in">putchar</span>(<span class="string">'\n'</span>);</span><br><span class="line"><span class="keyword">return</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="201703-4-地铁修建"><a href="#201703-4-地铁修建" class="headerlink" title="201703-4 地铁修建"></a>201703-4 地铁修建</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><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"><vector></span></span></span><br><span class="line"></span><br><span class="line"><span class="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> </span></span><br><span class="line"><span class="class">{</span></span><br><span class="line"><span class="keyword">long</span> v;</span><br><span class="line"><span class="keyword">long</span> w;</span><br><span class="line">} Node;</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="keyword">long</span> n,m;</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">cin</span> >> n >> m;</span><br><span class="line"><span class="built_in">vector</span> <<span class="built_in">vector</span> <Node> > Adj(n);</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">long</span> i=<span class="number">0</span>;i<m;i++){</span><br><span class="line">Node no;</span><br><span class="line"><span class="keyword">long</span> a,b,c;</span><br><span class="line"><span class="built_in">cin</span> >> a >> b >> c;</span><br><span class="line">no.v = b;</span><br><span class="line">no.w = c;</span><br><span class="line">Adj[a].push_back(no);</span><br><span class="line">}</span><br><span class="line"><span class="built_in">vector</span> <<span class="built_in">vector</span> < Node>> :: iterator=Adj.begin();</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">unsigned</span> <span class="keyword">long</span> j=<span class="number">0</span>;j<Adj[i].size();j++){</span><br><span class="line"><span class="built_in">cout</span> << Adj[i][j];</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><h2 id="201703-5"><a href="#201703-5" class="headerlink" title="201703-5"></a>201703-5</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id><a href="#" class="headerlink" title></a><a href="/2019/09/10/csp-intergrated/" title="csp题集汇总">csp题集汇总</a></h2><hr>]]></content>
<categories>
<category> csp </category>
</categories>
<tags>
<tag> csp </tag>
</tags>
</entry>
<entry>
<title>csp-201709</title>
<link href="/2019/09/10/csp-201709/"/>
<url>/2019/09/10/csp-201709/</url>
<content type="html"><![CDATA[<h2 id="201709-1-打酱油"><a href="#201709-1-打酱油" class="headerlink" title="201709-1 打酱油"></a>201709-1 打酱油</h2><h2 id="201709-2-公共钥匙盒"><a href="#201709-2-公共钥匙盒" class="headerlink" title="201709-2 公共钥匙盒"></a>201709-2 公共钥匙盒</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><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="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><vector></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><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="keyword">typedef</span> <span class="class"><span class="keyword">struct</span> </span></span><br><span class="line"><span class="class">{</span></span><br><span class="line"><span class="keyword">bool</span> type; <span class="comment">// true: lend, false: return;</span></span><br><span class="line"><span class="keyword">int</span> key;</span><br><span class="line"><span class="keyword">long</span> time;</span><br><span class="line">}Event_DEF;</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> key[<span class="number">1000</span>];</span><br><span class="line"><span class="keyword">int</span> key_index[<span class="number">1000</span>];</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">cmp</span></span></span><br><span class="line"><span class="class">{</span></span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">operator</span> <span class="params">()</span> <span class="params">(<span class="keyword">const</span> <span class="keyword">int</span> &a, <span class="keyword">const</span> <span class="keyword">int</span> &b)</span></span>{</span><br><span class="line"><span class="keyword">return</span> a > b; <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="function"><span class="keyword">bool</span> <span class="title">compare</span><span class="params">(<span class="keyword">const</span> Event_DEF &a, <span class="keyword">const</span> Event_DEF &b)</span></span>{</span><br><span class="line"><span class="comment">//!!先还再接</span></span><br><span class="line"><span class="keyword">if</span>(a.time < b.time) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line"><span class="keyword">else</span> <span class="keyword">if</span>(a.time == b.time){</span><br><span class="line"><span class="keyword">if</span>(a.type == <span class="literal">false</span> && b.type == <span class="literal">false</span>) <span class="keyword">return</span> a.key < b.key;</span><br><span class="line"><span class="keyword">if</span>(a.type == <span class="literal">false</span> && b.type == <span class="literal">true</span>) <span class="keyword">return</span> <span class="literal">true</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">compint</span><span class="params">(<span class="keyword">const</span> <span class="keyword">int</span> a, <span class="keyword">const</span> <span class="keyword">int</span> b)</span></span>{</span><br><span class="line"><span class="keyword">return</span> a<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, K;</span><br><span class="line"><span class="built_in">vector</span><Event_DEF> events;</span><br><span class="line"><span class="built_in">cin</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<K;i++){</span><br><span class="line">Event_DEF e;</span><br><span class="line"><span class="keyword">int</span> stime;</span><br><span class="line">e.type = <span class="literal">true</span>;</span><br><span class="line"><span class="built_in">cin</span> >> e.key;</span><br><span class="line">e.key--;</span><br><span class="line"><span class="built_in">cin</span> >> e.time;</span><br><span class="line">stime = e.time;</span><br><span class="line">events.push_back(e);</span><br><span class="line">e.type = <span class="literal">false</span>;</span><br><span class="line"><span class="built_in">cin</span> >> e.time;</span><br><span class="line">e.time += stime;</span><br><span class="line">events.push_back(e);</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<N;i++) {</span><br><span class="line">key_index[i]=i;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">sort(events.begin(), events.end(), compare);</span><br><span class="line"><span class="comment">// for(int i=0; i<2*N; i++) cout << events[i].type << ":" << events[i].time <<":"<< events[i].key << endl;</span></span><br><span class="line">priority_queue <<span class="keyword">int</span>, <span class="built_in">vector</span><<span class="keyword">int</span>>, cmp> pq;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">unsigned</span> <span class="keyword">int</span> i=<span class="number">0</span>;i<events.size();i++){</span><br><span class="line">Event_DEF e = events[i];</span><br><span class="line"><span class="keyword">if</span>(e.type){</span><br><span class="line">pq.push(key_index[e.key]);</span><br><span class="line">key_index[e.key] = <span class="number">-1</span>;</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line">key_index[e.key] = pq.top();</span><br><span class="line">pq.pop();</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<N;i++){</span><br><span class="line">key[key_index[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">0</span>;i<N;i++){</span><br><span class="line"><span class="built_in">cout</span> << key[i]+<span class="number">1</span> << <span class="string">" "</span>;</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></pre></td></tr></table></figure><h2 id="201709-3-JSON查询"><a href="#201709-3-JSON查询" class="headerlink" title="201709-3 JSON查询"></a>201709-3 JSON查询</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">// 引用不能迭代</span></span><br><span class="line"><span class="comment">// 90</span></span><br><span class="line"><span class="comment">// 注意 改变样例</span></span><br><span class="line"><span class="comment">// 标准嵌套做</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"><cstdio></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="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><string></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"><vector></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><cctype></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="function"><span class="keyword">void</span> <span class="title">SplitString</span><span class="params">(<span class="keyword">const</span> <span class="built_in">string</span>& s, <span class="built_in">vector</span><<span class="built_in">string</span>>& v, <span class="keyword">const</span> <span class="built_in">string</span>& c)</span></span>;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">OB</span>{</span></span><br><span class="line"><span class="built_in">string</span> key;</span><br><span class="line"><span class="keyword">bool</span> obj;</span><br><span class="line"><span class="built_in">string</span> value;</span><br><span class="line"><span class="built_in">vector</span> <OB> obv;</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><br><span class="line"><span class="function"><span class="built_in">string</span> <span class="title">inputkey</span><span class="params">()</span></span>{</span><br><span class="line"><span class="built_in">string</span> res;</span><br><span class="line"><span class="keyword">while</span>(getchar()!=<span class="string">'\"'</span>);</span><br><span class="line"><span class="keyword">char</span> c;</span><br><span class="line"><span class="keyword">while</span>(<span class="number">1</span>){</span><br><span class="line">c = getchar();</span><br><span class="line"><span class="keyword">if</span>(c==<span class="string">'\\'</span>){</span><br><span class="line">res+=getchar();</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line"><span class="keyword">if</span>(c==<span class="string">'\"'</span>)</span><br><span class="line"><span class="keyword">break</span>;</span><br><span class="line">res+=c;</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"><span class="keyword">return</span> res;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="built_in">string</span> <span class="title">inputvalue</span><span class="params">()</span></span>{</span><br><span class="line"><span class="built_in">string</span> res;</span><br><span class="line"><span class="keyword">char</span> c;</span><br><span class="line"><span class="keyword">while</span>(<span class="number">1</span>){</span><br><span class="line">c = getchar();</span><br><span class="line"><span class="keyword">if</span>(c==<span class="string">'\\'</span>){</span><br><span class="line">res+=getchar();</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line"><span class="keyword">if</span>(c==<span class="string">'\"'</span>) <span class="keyword">break</span>;</span><br><span class="line">res+=c;</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"><span class="keyword">return</span> res;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">createjson</span><span class="params">(<span class="built_in">vector</span> <OB> & obv)</span></span>{</span><br><span class="line"><span class="keyword">char</span> c;</span><br><span class="line"><span class="keyword">while</span>(<span class="number">1</span>){</span><br><span class="line">OB tar;</span><br><span class="line">tar.key = inputkey();</span><br><span class="line"><span class="comment">// printf("DEBUG key:%s\n", tar.key.c_str());</span></span><br><span class="line">c=getchar();</span><br><span class="line"><span class="keyword">while</span>((c!=<span class="string">'{'</span>)&&(c!=<span class="string">'\"'</span>)) c=getchar();</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span>(c==<span class="string">'\"'</span>){</span><br><span class="line">tar.obj =<span class="literal">false</span>;</span><br><span class="line">tar.value = inputvalue();</span><br><span class="line"><span class="comment">// printf("DEBUG value:%s\n", tar.value.c_str());</span></span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line">tar.obj = <span class="literal">true</span>;</span><br><span class="line">createjson(tar.obv);</span><br><span class="line">}</span><br><span class="line">obv.push_back(tar);</span><br><span class="line"><span class="keyword">while</span>(c=getchar(), (c!=<span class="string">','</span>)&&(c!=<span class="string">'}'</span>));</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span>(c==<span class="string">'}'</span>) <span class="keyword">break</span>;</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><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">printobj</span><span class="params">(OB tar)</span></span>{</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"%s: "</span>, tar.key.c_str());</span><br><span class="line"><span class="keyword">if</span>(tar.obj){</span><br><span class="line"><span class="built_in">vector</span> <OB>::iterator it;</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"{\n"</span>);</span><br><span class="line"><span class="keyword">for</span>(it=tar.obv.begin();it!=tar.obv.end();it++){</span><br><span class="line">printobj(*it);</span><br><span class="line">}</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"\n}\n"</span>);</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"%s,"</span>, tar.value.c_str());</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">OB root;</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, &m);</span><br><span class="line"><span class="keyword">while</span>(getchar()!=<span class="string">'{'</span>);</span><br><span class="line">root.obj=<span class="literal">true</span>;</span><br><span class="line">createjson(root.obv);</span><br><span class="line"><span class="comment">// printobj(root);</span></span><br><span class="line"></span><br><span class="line"><span class="built_in">string</span> line;</span><br><span class="line"><span class="built_in">vector</span> <<span class="built_in">string</span>> sels;</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">cin</span> >> line;</span><br><span class="line">sels.clear();</span><br><span class="line">SplitString(line, sels, <span class="string">"."</span>);</span><br><span class="line"><span class="built_in">vector</span> <<span class="built_in">string</span>>::iterator it;</span><br><span class="line"></span><br><span class="line"><span class="built_in">vector</span> <OB> * tar = &root.obv;</span><br><span class="line"><span class="built_in">vector</span> <OB>::iterator oit;</span><br><span class="line"><span class="keyword">for</span>(it=sels.begin();it!=sels.end();it++){</span><br><span class="line"><span class="comment">// printf("DE<span class="doctag">BUG:</span> sel:%s\n", (*it).c_str());</span></span><br><span class="line"><span class="keyword">for</span>(oit=tar->begin();oit!=tar->end();oit++){</span><br><span class="line"><span class="comment">// printf("DE<span class="doctag">BUG:</span> oit.key:%s\n", (*oit).key.c_str());</span></span><br><span class="line"><span class="keyword">if</span>((*oit).key==(*it)) <span class="keyword">goto</span> finds;</span><br><span class="line">}</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"NOTEXIST\n"</span>);</span><br><span class="line"><span class="keyword">break</span>;</span><br><span class="line">finds:</span><br><span class="line"><span class="keyword">if</span>(it == sels.end()<span class="number">-1</span>){</span><br><span class="line"><span class="keyword">if</span>((*oit).obj) <span class="built_in">printf</span>(<span class="string">"OBJECT\n"</span>);</span><br><span class="line"><span class="keyword">else</span> <span class="built_in">printf</span>(<span class="string">"STRING %s\n"</span>, (*oit).value.c_str());</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line"><span class="keyword">if</span>((*oit).obj){</span><br><span class="line">tar= &(*oit).obv;</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"NOTEXIST\n"</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><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="comment">//字符串分割函数</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">SplitString</span><span class="params">(<span class="keyword">const</span> <span class="built_in">string</span>& s, <span class="built_in">vector</span><<span class="built_in">string</span>>& v, <span class="keyword">const</span> <span class="built_in">string</span>& c)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"><span class="built_in">string</span>::size_type pos1, pos2;</span><br><span class="line">pos2 = s.find(c);</span><br><span class="line">pos1 = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">while</span>(<span class="built_in">string</span>::npos != pos2)</span><br><span class="line">{</span><br><span class="line">v.push_back(s.substr(pos1, pos2-pos1));</span><br><span class="line">pos1 = pos2 + c.size();</span><br><span class="line">pos2 = s.find(c, pos1);</span><br><span class="line">}</span><br><span class="line"><span class="keyword">if</span>(pos1 != s.length())</span><br><span class="line">v.push_back(s.substr(pos1));</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="201709-4-通信网络"><a href="#201709-4-通信网络" class="headerlink" title="201709-4 通信网络"></a>201709-4 通信网络</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//simple dfs</span></span><br><span class="line"><span class="comment">//暴力100</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><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxn = <span class="number">1010</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxm = <span class="number">10000</span>+<span class="number">10</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> head[maxn], cnt=<span class="number">0</span>;<span class="comment">//head用来表示以i为起点的第一条边存储的位置,cnt读入边的计数器</span></span><br><span class="line"><span class="keyword">int</span> n,m;</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="class">{</span></span><br><span class="line"> <span class="keyword">int</span> next; <span class="comment">//同一起点的上一条边的储存位置</span></span><br><span class="line"> <span class="keyword">int</span> to; <span class="comment">//第i条边的终点</span></span><br><span class="line"><span class="keyword">int</span> t;</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line">Edge edge[maxm];</span><br><span class="line"></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 class="comment">//读入边</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> edge[cnt].to = v;</span><br><span class="line"> edge[cnt].next = head[u];</span><br><span class="line"> head[u] = cnt++;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">read</span><span class="params">()</span> <span class="comment">//遍历所有边</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<=n; i++){</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"%d:"</span>, i);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=head[i]; j!=<span class="number">-1</span>; j=edge[j].next){</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"%d"</span>, edge[j].to);</span><br><span class="line">}</span><br><span class="line"><span class="built_in">putchar</span>(<span class="string">'\n'</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[maxn];</span><br><span class="line"><span class="keyword">bool</span> visit[maxn][maxn];</span><br><span class="line"></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> s)</span></span>{</span><br><span class="line"><span class="keyword">if</span>(visit[s][x]) <span class="keyword">return</span>;</span><br><span class="line">visit[s][x] = <span class="literal">true</span>;</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> j=head[x];j!=<span class="number">-1</span>;j=edge[j].next){</span><br><span class="line"><span class="keyword">int</span> v = edge[j].to;</span><br><span class="line">dfs(v, s);</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, &m);</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="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;</span><br><span class="line"><span class="built_in">scanf</span>(<span class="string">"%d %d"</span>, &u, &v);</span><br><span class="line">add(u, v);</span><br><span class="line">}</span><br><span class="line"><span class="built_in">memset</span>(visit, <span class="number">0</span>, <span class="keyword">sizeof</span>(visit));</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">dfs(i, i);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> res=<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">bool</span> flag=<span class="literal">true</span>;</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>(visit[i][j] || visit[j][i]){</span><br><span class="line">;</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line">flag=<span class="literal">false</span>;</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"><span class="keyword">if</span>(flag)</span><br><span class="line">res++;</span><br><span class="line">}</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"%d\n"</span>, res);</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><h2 id="201709-5-除法"><a href="#201709-5-除法" class="headerlink" title="201709-5 除法"></a>201709-5 除法</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//树状数组 全局n main局部n重复</span></span><br><span class="line"><span class="comment">//低级错误 c没有使用long long</span></span><br><span class="line"><span class="comment">//50分 除1剪枝 100</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><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><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 c[maxn];</span><br><span class="line"><span class="keyword">int</span> a[maxn];</span><br><span class="line"><span class="keyword">int</span> n,m;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">Lowbit</span><span class="params">(<span class="keyword">int</span> x)</span> <span class="comment">// 2^k</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"><span class="keyword">return</span> x&(-x);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">update</span><span class="params">(<span class="keyword">int</span> i, <span class="keyword">int</span> x)</span><span class="comment">//i点增量为x</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"><span class="keyword">while</span>(i <= n)</span><br><span class="line">{</span><br><span class="line">c[i] += x;</span><br><span class="line">i += Lowbit(i);</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function">ll <span class="title">sum</span><span class="params">(<span class="keyword">int</span> x)</span><span class="comment">//区间求和 [1,x]</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line">ll sum=<span class="number">0</span>;</span><br><span class="line"><span class="keyword">while</span>(x><span class="number">0</span>)</span><br><span class="line">{</span><br><span class="line">sum+=c[x];</span><br><span class="line">x-=Lowbit(x);</span><br><span class="line">}</span><br><span class="line"><span class="keyword">return</span> sum;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function">ll <span class="title">getsum</span><span class="params">(<span class="keyword">int</span> x1, <span class="keyword">int</span> x2)</span></span>{</span><br><span class="line"> <span class="keyword">return</span> sum(x2) - sum(x1<span class="number">-1</span>);</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, &m);</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"> update(i, a[i]);</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// for(int i=1;i<=n;i++){</span></span><br><span class="line"> <span class="comment">// printf("DEBUG sum(%d):%lld\n", i, sum(i));</span></span><br><span class="line"> <span class="comment">// }</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">int</span> t, l, r, v;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d %d"</span>, &t, &l, &r);</span><br><span class="line"> <span class="keyword">if</span>(t==<span class="number">2</span>){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%lld\n"</span>, getsum(l, r));</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &v);</span><br><span class="line"> <span class="keyword">if</span>(v==<span class="number">1</span>) <span class="keyword">continue</span>;<span class="comment">//除以1大小不变,如果没有这句同样会超时(50)分</span></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=l;j<=r;j++){</span><br><span class="line"> <span class="keyword">if</span>(a[j]>=v && a[j]%v==<span class="number">0</span> ){</span><br><span class="line"> update(j, a[j]/v-a[j]);</span><br><span class="line"> a[j] /= v;</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></pre></td></tr></table></figure><h2 id><a href="#" class="headerlink" title></a><a href="/2019/09/10/csp-intergrated/" title="csp题集汇总">csp题集汇总</a></h2><hr>]]></content>
<categories>
<category> csp </category>
</categories>
<tags>
<tag> csp </tag>
</tags>
</entry>
<entry>
<title>csp-201712</title>
<link href="/2019/09/10/csp-201712/"/>
<url>/2019/09/10/csp-201712/</url>
<content type="html"><![CDATA[<h2 id="201712-1-最小差值"><a href="#201712-1-最小差值" class="headerlink" title="201712-1 最小差值"></a>201712-1 最小差值</h2><figure class="highlight cpp"><table><tr><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="meta">#<span class="meta-keyword">define</span> uint unsigned int</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> uchar unsigned char</span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">define</span> abs(x) ((x)>=0 ? (x):-(x))</span></span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> a[<span class="number">1010</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="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">}</span><br><span class="line">sort(a, a+n);</span><br><span class="line"><span class="keyword">int</span> res = (<span class="keyword">int</span>)<span class="number">1e9</span>;</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">res = min(res, a[i+<span class="number">1</span>]-a[i]);</span><br><span class="line">}</span><br><span class="line"><span class="built_in">cout</span> << res << <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><h2 id="201712-2-游戏"><a href="#201712-2-游戏" class="headerlink" title="201712-2 游戏"></a>201712-2 游戏</h2><figure class="highlight plain"><table><tr><td class="code"><pre><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure><h2 id="201712-3-Crontab"><a href="#201712-3-Crontab" class="headerlink" title="201712-3 Crontab"></a>201712-3 Crontab</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">// map使用</span></span><br><span class="line"><span class="comment">// SplitString</span></span><br><span class="line"><span class="comment">// 闰年星期转换</span></span><br><span class="line"><span class="comment">// 闰月天数转换</span></span><br><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"><iostream></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><string></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"><vector></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"><map></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="function"><span class="keyword">void</span> <span class="title">SplitString</span><span class="params">(<span class="keyword">const</span> <span class="built_in">string</span>& s, <span class="built_in">vector</span><<span class="built_in">string</span>>& v, <span class="keyword">const</span> <span class="built_in">string</span>& c)</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">isnum</span><span class="params">(<span class="built_in">string</span> s)</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">CaculateWeekDay</span><span class="params">(<span class="keyword">int</span> y, <span class="keyword">int</span> m, <span class="keyword">int</span> d)</span></span>;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">CaculateMontDay</span><span class="params">(<span class="keyword">int</span> y, <span class="keyword">int</span> m)</span></span>;</span><br><span class="line"></span><br><span class="line"><span class="built_in">map</span> <<span class="built_in">string</span>, <span class="keyword">int</span>> dayweekmap;</span><br><span class="line"><span class="built_in">map</span> <<span class="built_in">string</span>, <span class="keyword">int</span>> monthmap;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">initmap</span><span class="params">()</span></span>{</span><br><span class="line">monthmap[<span class="string">"Jan"</span>] = <span class="number">0</span>;</span><br><span class="line">monthmap[<span class="string">"Feb"</span>] = <span class="number">1</span>;</span><br><span class="line">monthmap[<span class="string">"Mar"</span>] = <span class="number">2</span>;</span><br><span class="line">monthmap[<span class="string">"Apr"</span>] = <span class="number">3</span>;</span><br><span class="line">monthmap[<span class="string">"May"</span>] = <span class="number">4</span>;</span><br><span class="line">monthmap[<span class="string">"Jun"</span>] = <span class="number">5</span>;</span><br><span class="line">monthmap[<span class="string">"Jul"</span>] = <span class="number">6</span>;</span><br><span class="line">monthmap[<span class="string">"Aug"</span>] = <span class="number">7</span>;</span><br><span class="line">monthmap[<span class="string">"Sep"</span>] = <span class="number">8</span>;</span><br><span class="line">monthmap[<span class="string">"Oct"</span>] = <span class="number">9</span>;</span><br><span class="line">monthmap[<span class="string">"Nov"</span>] = <span class="number">10</span>;</span><br><span class="line">monthmap[<span class="string">"Dec"</span>] = <span class="number">11</span>;</span><br><span class="line"></span><br><span class="line">dayweekmap[<span class="string">"Sun"</span>] = <span class="number">0</span>;</span><br><span class="line">dayweekmap[<span class="string">"Mon"</span>] = <span class="number">1</span>;</span><br><span class="line">dayweekmap[<span class="string">"Tue"</span>] = <span class="number">2</span>;</span><br><span class="line">dayweekmap[<span class="string">"Wed"</span>] = <span class="number">3</span>;</span><br><span class="line">dayweekmap[<span class="string">"Thu"</span>] = <span class="number">4</span>;</span><br><span class="line">dayweekmap[<span class="string">"Fri"</span>] = <span class="number">5</span>;</span><br><span class="line">dayweekmap[<span class="string">"Sat"</span>] = <span class="number">6</span>;</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">CronRule</span>{</span></span><br><span class="line"><span class="keyword">bool</span> mins[<span class="number">60</span>];</span><br><span class="line"><span class="keyword">bool</span> hours[<span class="number">24</span>];</span><br><span class="line"><span class="keyword">bool</span> days[<span class="number">31</span>];</span><br><span class="line"><span class="keyword">bool</span> months[<span class="number">12</span>];</span><br><span class="line"><span class="keyword">bool</span> dayweek[<span class="number">7</span>];</span><br><span class="line"><span class="built_in">string</span> name;</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">Time</span>{</span></span><br><span class="line"><span class="keyword">int</span> year;</span><br><span class="line"><span class="keyword">int</span> month;</span><br><span class="line"><span class="keyword">int</span> day;</span><br><span class="line"><span class="keyword">int</span> hour;</span><br><span class="line"><span class="keyword">int</span> min;</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="function">Time <span class="title">parsetime</span><span class="params">(<span class="keyword">const</span> <span class="built_in">string</span> & a)</span></span>{</span><br><span class="line">Time res;</span><br><span class="line">res.year = stoi(a.substr(<span class="number">0</span>, <span class="number">4</span>));</span><br><span class="line">res.month = stoi(a.substr(<span class="number">4</span>, <span class="number">2</span>))<span class="number">-1</span>;</span><br><span class="line">res.day = stoi(a.substr(<span class="number">6</span>, <span class="number">2</span>))<span class="number">-1</span>;</span><br><span class="line">res.hour = stoi(a.substr(<span class="number">8</span>, <span class="number">2</span>));</span><br><span class="line">res.min = stoi(a.substr(<span class="number">10</span>, <span class="number">2</span>));</span><br><span class="line"><span class="keyword">return</span> res;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">enum</span> Process{</span><br><span class="line">MIN = <span class="number">0</span>,</span><br><span class="line">HOUR,</span><br><span class="line">DAY,</span><br><span class="line">MONTH,</span><br><span class="line">DAYWEEK</span><br><span class="line">};</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">parserule</span><span class="params">(CronRule & rule)</span></span>{</span><br><span class="line"><span class="built_in">string</span> tarstr;</span><br><span class="line"><span class="comment">// memset(&rule, 0, sizeof(rule));</span></span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> process =<span class="number">0</span>;process<=DAYWEEK;process++){</span><br><span class="line"><span class="built_in">cin</span> >> tarstr;</span><br><span class="line"><span class="comment">// cout << "DEBUG" << tarstr << endl;</span></span><br><span class="line"><span class="keyword">if</span>(tarstr == <span class="string">"*"</span>){</span><br><span class="line"><span class="keyword">switch</span>(process){</span><br><span class="line"><span class="keyword">case</span> MIN : <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<<span class="number">60</span>;i++) rule.mins[i] = <span class="number">1</span>;<span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">case</span> HOUR : <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<<span class="number">24</span>;i++) rule.hours[i] = <span class="number">1</span>;<span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">case</span> DAY : <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<<span class="number">31</span>;i++) rule.days[i] = <span class="number">1</span>;<span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">case</span> MONTH : <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<<span class="number">12</span>;i++) rule.months[i] = <span class="number">1</span>;<span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">case</span> DAYWEEK : <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<<span class="number">7</span>;i++) rule.dayweek[i] = <span class="number">1</span>;<span class="keyword">break</span>;</span><br><span class="line">}</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line"><span class="built_in">vector</span><<span class="built_in">string</span>> vs;</span><br><span class="line"><span class="keyword">if</span>(tarstr.find(<span class="string">","</span>) != <span class="built_in">string</span>::npos){</span><br><span class="line">SplitString(tarstr, vs, <span class="string">","</span>);</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line">vs.push_back(tarstr);</span><br><span class="line">}</span><br><span class="line"><span class="built_in">vector</span><<span class="built_in">string</span>>::iterator it;</span><br><span class="line"><span class="keyword">for</span>(it=vs.begin();it!=vs.end();it++){</span><br><span class="line"><span class="keyword">unsigned</span> pose;</span><br><span class="line"><span class="keyword">if</span>((pose=(*it).find(<span class="string">"-"</span>)) != <span class="built_in">string</span>::npos){</span><br><span class="line"><span class="built_in">string</span> a = (*it).substr(<span class="number">0</span>, pose), b = (*it).substr(pose+<span class="number">1</span>);</span><br><span class="line"><span class="comment">// printf("DE<span class="doctag">BUG:</span> a:%s, b:%s\n", a.c_str(), b.c_str());</span></span><br><span class="line"><span class="keyword">int</span> an,bn;</span><br><span class="line"><span class="keyword">switch</span>(process){</span><br><span class="line"><span class="keyword">case</span> MIN :{</span><br><span class="line">an = stoi(a), bn = stoi(b);</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> i=an;i<=bn;i++) rule.mins[i] = <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 class="keyword">case</span> HOUR :{</span><br><span class="line">an = stoi(a), bn = stoi(b);</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> i=an;i<=bn;i++) rule.hours[i] = <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 class="keyword">case</span> DAY :{</span><br><span class="line">an = stoi(a), bn = stoi(b);</span><br><span class="line">an--,bn--;</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> i=an;i<=bn;i++) rule.days[i] = <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 class="keyword">case</span> MONTH :{</span><br><span class="line"><span class="keyword">if</span>(isnum(a))</span><br><span class="line">an = stoi(a), bn = stoi(b);</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">an = monthmap[a], bn = monthmap[b];</span><br><span class="line">an--,bn--;</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> i=an;i<=bn;i++) rule.months[i] = <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 class="keyword">case</span> DAYWEEK :{</span><br><span class="line"><span class="keyword">if</span>(isnum(a))</span><br><span class="line">an = stoi(a), bn = stoi(b);</span><br><span class="line"><span class="keyword">else</span></span><br><span class="line">an = dayweekmap[a], bn = dayweekmap[b];</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> i=an;i<=bn;i++) rule.dayweek[i] = <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="comment">// printf("DEBUG over\n");</span></span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line"><span class="keyword">int</span> num;</span><br><span class="line"><span class="keyword">switch</span>(process){</span><br><span class="line"><span class="keyword">case</span> MIN : num=stoi(*it), rule.mins[num] = <span class="number">1</span>; <span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">case</span> HOUR :num=stoi(*it), rule.hours[num] = <span class="number">1</span>; <span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">case</span> DAY : num=stoi(*it), --num, rule.days[num] = <span class="number">1</span>; <span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">case</span> MONTH : num = isnum(*it)? stoi(*it) : monthmap[*it] , num--, rule.months[num] = <span class="number">1</span>;<span class="keyword">break</span>;</span><br><span class="line"><span class="keyword">case</span> DAYWEEK : num = isnum(*it)? stoi(*it) : dayweekmap[*it] , rule.dayweek[num] = <span class="number">1</span>;<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><br><span class="line">}</span><br><span class="line"><span class="built_in">cin</span> >> rule.name;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">Time tstart, tend;</span><br><span class="line"><span class="keyword">int</span> N;</span><br><span class="line"><span class="built_in">vector</span> <CronRule> rules;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">timecmpless</span><span class="params">(Time a, Time b)</span></span>{</span><br><span class="line"><span class="keyword">if</span>(a.year < b.year) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line"><span class="keyword">else</span> <span class="keyword">if</span>(a.year > b.year) <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line"><span class="keyword">if</span>(a.month < b.month) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line"><span class="keyword">else</span> <span class="keyword">if</span>(a.month > b.month) <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line"><span class="keyword">if</span>(a.day < b.day) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line"><span class="keyword">else</span> <span class="keyword">if</span>(a.day > b.day) <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line"><span class="keyword">if</span>(a.hour < b.hour) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line"><span class="keyword">else</span> <span class="keyword">if</span>(a.hour > b.hour) <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line"><span class="keyword">if</span>(a.min < b.min) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line"><span class="keyword">else</span> <span class="keyword">if</span>(a.min > b.min) <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line"><span class="keyword">return</span> <span class="literal">true</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">match</span><span class="params">(Time & a, CronRule & r)</span></span>{</span><br><span class="line"><span class="keyword">if</span>(<span class="keyword">not</span> r.months[a.month])<span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line"><span class="keyword">if</span>(<span class="keyword">not</span> r.days[a.day])<span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line"><span class="keyword">return</span> <span class="literal">true</span>;</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">initmap();</span><br><span class="line"></span><br><span class="line"><span class="built_in">string</span> tmp;</span><br><span class="line"><span class="built_in">cin</span> >> N;</span><br><span class="line"><span class="built_in">cin</span> >> tmp, tstart = parsetime(tmp);</span><br><span class="line"><span class="built_in">cin</span> >> tmp, tend = parsetime(tmp);</span><br><span class="line"></span><br><span class="line">rules.resize(N, {{<span class="number">0</span>},{<span class="number">0</span>},{<span class="number">0</span>},{<span class="number">0</span>},{<span class="number">0</span>},<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">parserule(rules[i]);</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line">Time & t = tstart;</span><br><span class="line"><span class="keyword">int</span> dayweek = (CaculateWeekDay(t.year, t.month, t.day)+<span class="number">5</span>)%<span class="number">7</span>;</span><br><span class="line"><span class="comment">// printf("%d\n", dayweek);</span></span><br><span class="line"><span class="keyword">while</span>(timecmpless(t, tend)){</span><br><span class="line"><span class="built_in">vector</span><CronRule>::iterator it;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span>(it=rules.begin();it!=rules.end();it++){</span><br><span class="line">CronRule & r = *it;</span><br><span class="line"><span class="keyword">if</span>(<span class="keyword">not</span> r.months[t.month])<span class="keyword">continue</span>;</span><br><span class="line"><span class="keyword">if</span>(<span class="keyword">not</span> r.days[t.day] || <span class="keyword">not</span> r.dayweek[dayweek])<span class="keyword">continue</span>;</span><br><span class="line"><span class="keyword">if</span>(<span class="keyword">not</span> r.hours[t.hour]) <span class="keyword">continue</span>;</span><br><span class="line"><span class="keyword">if</span>(<span class="keyword">not</span> r.mins[t.min]) <span class="keyword">continue</span>;</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"%04d%02d%02d%02d%02d %s\n"</span>, t.year,t.month+<span class="number">1</span>,t.day+<span class="number">1</span>,t.hour,t.min, r.name.c_str());</span><br><span class="line">}</span><br><span class="line">t.min++;</span><br><span class="line"><span class="keyword">if</span>(t.min==<span class="number">60</span>){</span><br><span class="line">t.hour++;</span><br><span class="line">t.min = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">if</span>(t.hour==<span class="number">24</span>){</span><br><span class="line">t.day++;</span><br><span class="line">dayweek = (dayweek+<span class="number">1</span>)%<span class="number">7</span>;</span><br><span class="line">t.hour = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">if</span>(t.day==CaculateMontDay(t.year, t.month)){</span><br><span class="line">t.month++;</span><br><span class="line">t.day = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">if</span>(t.month==<span class="number">12</span>){</span><br><span class="line">t.year++;</span><br><span class="line">t.month = <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><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><br><span class="line"><span class="comment">//字符串分割函数</span></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">SplitString</span><span class="params">(<span class="keyword">const</span> <span class="built_in">string</span>& s, <span class="built_in">vector</span><<span class="built_in">string</span>>& v, <span class="keyword">const</span> <span class="built_in">string</span>& c)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"><span class="built_in">string</span>::size_type pos1, pos2;</span><br><span class="line">pos2 = s.find(c);</span><br><span class="line">pos1 = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">while</span>(<span class="built_in">string</span>::npos != pos2)</span><br><span class="line">{</span><br><span class="line">v.push_back(s.substr(pos1, pos2-pos1));</span><br><span class="line">pos1 = pos2 + c.size();</span><br><span class="line">pos2 = s.find(c, pos1);</span><br><span class="line">}</span><br><span class="line"><span class="keyword">if</span>(pos1 != s.length())</span><br><span class="line">v.push_back(s.substr(pos1));</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">isnum</span><span class="params">(<span class="built_in">string</span> s)</span></span>{</span><br><span class="line"><span class="built_in">string</span>::iterator it;</span><br><span class="line"><span class="keyword">for</span>(it = s.begin();it!=s.end();it++){</span><br><span class="line"><span class="keyword">char</span> c = *it;</span><br><span class="line"><span class="keyword">if</span>(<span class="keyword">not</span> (c>=<span class="string">'0'</span> && c <=<span class="string">'9'</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 class="keyword">return</span> <span class="literal">true</span>;</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">CaculateMontDay</span><span class="params">(<span class="keyword">int</span> y, <span class="keyword">int</span> m)</span></span>{</span><br><span class="line"><span class="keyword">switch</span>(m){</span><br><span class="line"><span class="keyword">case</span> <span class="number">0</span> :<span class="keyword">return</span> <span class="number">31</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="number">1</span> :<span class="keyword">return</span> !(y%<span class="number">4</span>) && ((y%<span class="number">100</span>)||!(y%<span class="number">400</span>)) ? <span class="number">29</span>:<span class="number">28</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="number">2</span> :<span class="keyword">return</span> <span class="number">31</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="number">3</span> :<span class="keyword">return</span> <span class="number">30</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="number">4</span> :<span class="keyword">return</span> <span class="number">31</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="number">5</span> :<span class="keyword">return</span> <span class="number">30</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="number">6</span> :<span class="keyword">return</span> <span class="number">31</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="number">7</span> :<span class="keyword">return</span> <span class="number">31</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="number">8</span> :<span class="keyword">return</span> <span class="number">30</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="number">9</span> :<span class="keyword">return</span> <span class="number">31</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="number">10</span>:<span class="keyword">return</span> <span class="number">30</span>;</span><br><span class="line"><span class="keyword">case</span> <span class="number">11</span>:<span class="keyword">return</span> <span class="number">31</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">CaculateWeekDay</span><span class="params">(<span class="keyword">int</span> y, <span class="keyword">int</span> m, <span class="keyword">int</span> d)</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> <span class="keyword">if</span>(m==<span class="number">1</span>||m==<span class="number">2</span>) <span class="comment">//把一月和二月换算成上一年的十三月和是四月</span></span><br><span class="line"> {</span><br><span class="line"> m+=<span class="number">12</span>;</span><br><span class="line"> y--;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">int</span> Week= (d+<span class="number">2</span>*m+<span class="number">3</span>*(m+<span class="number">1</span>)/<span class="number">5</span>+y+y/<span class="number">4</span>-y/<span class="number">100</span>+y/<span class="number">400</span>)%<span class="number">7</span>;</span><br><span class="line"> <span class="keyword">return</span> Week;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="201712-4-行车路线"><a href="#201712-4-行车路线" class="headerlink" title="201712-4 行车路线"></a>201712-4 行车路线</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//暴力60分</span></span><br><span class="line"><span class="comment">//dijkstra 改进 80</span></span><br><span class="line"><span class="comment">//疏忽 边双倍</span></span><br><span class="line"></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">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">505</span>;</span><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> maxm = (<span class="number">1e5</span> + <span class="number">10</span>)*<span class="number">2</span>;</span><br><span class="line"><span class="keyword">int</span> head[maxn], cnt=<span class="number">0</span>;<span class="comment">//head用来表示以i为起点的第一条边存储的位置,cnt读入边的计数器</span></span><br><span class="line"><span class="keyword">int</span> n,m;</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="class">{</span></span><br><span class="line"> <span class="keyword">int</span> next; <span class="comment">//同一起点的上一条边的储存位置</span></span><br><span class="line"> <span class="keyword">int</span> to; <span class="comment">//第i条边的终点</span></span><br><span class="line"><span class="keyword">int</span> t;</span><br><span class="line"> ll w; <span class="comment">//第i条边权重</span></span><br><span class="line">};</span><br><span class="line"></span><br><span class="line">Edge edge[maxm];</span><br><span class="line"></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,ll w, <span class="keyword">int</span> t)</span> <span class="comment">//读入边</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> edge[cnt].w = w;</span><br><span class="line"> edge[cnt].to = v;</span><br><span class="line">edge[cnt].t = t;</span><br><span class="line"> edge[cnt].next = head[u];</span><br><span class="line"> head[u] = cnt++;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">read</span><span class="params">()</span> <span class="comment">//遍历所有边</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">0</span>; i<=n; i++)</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> j=head[i]; j!=<span class="number">-1</span>; j=edge[j].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"><span class="comment">// set <int> T;</span></span><br><span class="line"><span class="keyword">bool</span> visit[maxn];</span><br><span class="line">ll ans[maxn];</span><br><span class="line"></span><br><span class="line">ll trail[maxn];</span><br><span class="line"><span class="function"><span class="keyword">inline</span> ll <span class="title">D</span><span class="params">(ll x)</span> </span>{ <span class="keyword">return</span> x*x;}</span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">dijkstra</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<=n;i++) ans[i] = <span class="number">1e18</span>;</span><br><span class="line">ans[<span class="number">1</span>] = <span class="number">0</span>;</span><br><span class="line"><span class="keyword">int</span> tar=<span class="number">1</span>;</span><br><span class="line">visit[tar]=<span class="literal">true</span>;</span><br><span class="line"><span class="keyword">while</span>(<span class="number">1</span>){</span><br><span class="line"><span class="comment">// printf("DEBUG tar:%lld\n", tar);</span></span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> j=head[tar]; j!=<span class="number">-1</span>; j=edge[j].next){</span><br><span class="line"><span class="keyword">int</span> v = edge[j].to;</span><br><span class="line"><span class="keyword">int</span> t = edge[j].t;</span><br><span class="line">ll w = edge[j].w;</span><br><span class="line"><span class="keyword">if</span>(visit[v]) <span class="keyword">continue</span>;</span><br><span class="line"><span class="keyword">if</span>(t==<span class="number">1</span>){</span><br><span class="line"><span class="keyword">if</span>(ans[tar] - D(trail[tar]) + D(trail[tar]+w) < ans[v]){</span><br><span class="line">ans[v] = ans[tar] - D(trail[tar]) + D(trail[tar]+w);</span><br><span class="line">trail[v] = trail[tar]+w;</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>(ans[tar] + w < ans[v]){</span><br><span class="line">ans[v] = ans[tar]+w;</span><br><span class="line">trail[v] = <span class="number">0</span>;</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"><span class="comment">// printf("DE<span class="doctag">BUG:</span> %d %d\n", j, ans[j]);</span></span><br><span class="line">}</span><br><span class="line"><span class="keyword">bool</span> allvisit=<span class="literal">true</span>;</span><br><span class="line">ll MIN = <span class="number">1e18</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>(visit[i]) <span class="keyword">continue</span>;</span><br><span class="line">allvisit=<span class="literal">false</span>;</span><br><span class="line"><span class="keyword">if</span>(ans[i] < MIN){</span><br><span class="line">MIN = ans[i];</span><br><span class="line">tar = i;</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"><span class="comment">// printf("DEBUG2 tar:%d %lld\n", tar, ans[tar]);</span></span><br><span class="line"><span class="keyword">if</span>(allvisit) <span class="keyword">break</span>;</span><br><span class="line">visit[tar]=<span class="literal">true</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="built_in">memset</span>(head, <span class="number">-1</span>, <span class="keyword">sizeof</span>(head)); <span class="comment">//init important</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">0</span>;i<m;i++){</span><br><span class="line"><span class="keyword">int</span> t, u, v;</span><br><span class="line">ll w;</span><br><span class="line"><span class="built_in">scanf</span>(<span class="string">"%d %d %d %lld"</span>, &t, &u, &v, &w);</span><br><span class="line">add(u, v, w, t);</span><br><span class="line">add(v, u, w, t);</span><br><span class="line">}</span><br><span class="line">dijkstra();</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"%lld\n"</span>, ans[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><h2 id="201712-5-商路"><a href="#201712-5-商路" class="headerlink" title="201712-5 商路"></a>201712-5 商路</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//45分错误</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><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><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">int</span> maxm = <span class="number">1e5</span>+<span class="number">10</span>;</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="class">{</span></span><br><span class="line"> <span class="keyword">int</span> next; <span class="comment">//同一起点的上一条边的储存位置</span></span><br><span class="line"> <span class="keyword">int</span> to; <span class="comment">//第i条边的终点</span></span><br><span class="line"> <span class="keyword">int</span> w; <span class="comment">//第i条边权重</span></span><br><span class="line">};</span><br><span class="line"></span><br><span class="line">Edge edge[maxm];</span><br><span class="line"><span class="keyword">int</span> head[maxn], cnt;</span><br><span class="line">ll pv[maxn], pf[maxn];</span><br><span class="line"></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">int</span> w)</span> <span class="comment">//读入边</span></span></span><br><span class="line"><span class="function"></span>{</span><br><span class="line"> edge[cnt].w = w;</span><br><span class="line"> edge[cnt].to = v;</span><br><span class="line"> edge[cnt].next = head[u];</span><br><span class="line"> head[u] = cnt++;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">// void read() //遍历所有边</span></span><br><span class="line"><span class="comment">// {</span></span><br><span class="line"><span class="comment">// for(int i=0; i<=n; i++)</span></span><br><span class="line"><span class="comment">// for(int j=head[i]; j!=-1; j=edge[j].next){</span></span><br><span class="line"><span class="comment">// ;</span></span><br><span class="line"><span class="comment">// }</span></span><br><span class="line"><span class="comment">// }</span></span><br><span class="line"></span><br><span class="line">ll ans[maxn];</span><br><span class="line"><span class="keyword">bool</span> visit[maxn];</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">mix</span>{</span></span><br><span class="line"> <span class="keyword">int</span> tar;</span><br><span class="line"> <span class="keyword">int</span> dis;</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="function">ll <span class="title">cal</span><span class="params">(<span class="keyword">int</span> u, <span class="keyword">int</span> s)</span></span>{</span><br><span class="line"> <span class="keyword">return</span> pv[u] - (pf[u] - s)*(pf[u] - s);</span><br><span class="line">}</span><br><span class="line"></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> n)</span></span>{</span><br><span class="line"> <span class="built_in">deque</span> <mix> N;</span><br><span class="line"> N.push_back({n, <span class="number">0</span>});</span><br><span class="line"> <span class="keyword">while</span>(N.size()){</span><br><span class="line"> <span class="keyword">auto</span> m = N.front();</span><br><span class="line"> <span class="keyword">int</span> u = m.tar;</span><br><span class="line"> <span class="comment">// printf("n:%d u:%d\n", n, u);</span></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=head[u];i!=<span class="number">-1</span>;i=edge[i].next){</span><br><span class="line"> <span class="keyword">int</span> v = edge[i].to, w = edge[i].w;</span><br><span class="line"> <span class="keyword">int</span> dis = m.dis + w;</span><br><span class="line"> <span class="keyword">if</span>(<span class="keyword">not</span> visit[v]){</span><br><span class="line"> dfs(v);</span><br><span class="line"> }</span><br><span class="line"> ans[n] = max(ans[n], ans[v]+cal(n, dis));</span><br><span class="line"> N.push_back({v, dis});</span><br><span class="line"> }</span><br><span class="line"> N.pop_front();</span><br><span class="line"> }</span><br><span class="line"> visit[n]=<span class="literal">true</span>;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> T;</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"</span>, &T);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> t=<span class="number">1</span>;t<=T;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"> cnt = <span class="number">0</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">memset</span>(visit, <span class="number">0</span>, <span class="keyword">sizeof</span>(visit));</span><br><span class="line"> <span class="built_in">memset</span>(ans, <span class="number">0</span>, <span class="keyword">sizeof</span>(ans));</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> u,s;</span><br><span class="line"> ll v, f;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d %lld %lld"</span>,&u, &s, &v, &f);</span><br><span class="line"> <span class="keyword">if</span>(u!=<span class="number">0</span>){</span><br><span class="line"> add(u, i, s);</span><br><span class="line"> }</span><br><span class="line"> pv[i] = v;</span><br><span class="line"> pf[i] = f;</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">// for(int i=1; i<=n; i++){</span></span><br><span class="line"> <span class="comment">// printf("%d: %lld %lld ||", i, pv[i], pf[i]);</span></span><br><span class="line"> <span class="comment">// for(int j=head[i]; j!=-1; j=edge[j].next){</span></span><br><span class="line"> <span class="comment">// printf("%d ", edge[j].to);</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> <span class="comment">// putchar('\n');</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> </span><br><span class="line"> dfs(<span class="number">1</span>);</span><br><span class="line"> <span class="keyword">int</span> res=<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="comment">// printf("%d %lld\n", i, ans[i]);</span></span><br><span class="line"> res = (res+ans[i])%((<span class="keyword">long</span> <span class="keyword">long</span>)<span class="number">1e18</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%lld\n"</span>, res);</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><h2 id><a href="#" class="headerlink" title></a><a href="/2019/09/10/csp-intergrated/" title="csp题集汇总">csp题集汇总</a></h2><hr>]]></content>
<categories>
<category> csp </category>
</categories>
<tags>
<tag> csp </tag>
</tags>
</entry>
<entry>
<title>csp-201803</title>
<link href="/2019/09/10/csp-201803/"/>
<url>/2019/09/10/csp-201803/</url>
<content type="html"><![CDATA[<h2 id="201803-1-跳一跳"><a href="#201803-1-跳一跳" class="headerlink" title="201803-1 跳一跳"></a>201803-1 跳一跳</h2><figure class="highlight cpp"><table><tr><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"><iostream></span></span></span><br><span class="line"><span class="meta">#<span class="meta-keyword">include</span> <span class="meta-string"><string></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"><vector></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"><cmath></span></span></span><br><span class="line"></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> d;</span><br><span class="line"><span class="keyword">int</span> last=<span class="number">0</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">bool</span> start=<span class="literal">true</span>;</span><br><span class="line"><span class="keyword">while</span>(<span class="built_in">scanf</span>(<span class="string">"%d"</span>, &d), d){</span><br><span class="line"><span class="keyword">if</span>(d==<span class="number">1</span>){</span><br><span class="line">last=<span class="number">1</span>;</span><br><span class="line">sum+=<span class="number">1</span>;</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line"><span class="keyword">if</span>(last==<span class="number">1</span>||start){</span><br><span class="line">sum += <span class="number">2</span>;</span><br><span class="line">last = <span class="number">2</span>;</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line">last += <span class="number">2</span>;</span><br><span class="line">sum += last;</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line">start=<span class="literal">false</span>;</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 class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="201803-2-碰撞的小球"><a href="#201803-2-碰撞的小球" class="headerlink" title="201803-2 碰撞的小球"></a>201803-2 碰撞的小球</h2><h2 id="201803-3-URL映射"><a href="#201803-3-URL映射" class="headerlink" title="201803-3 URL映射"></a>201803-3 URL映射</h2><figure class="highlight cpp"><table><tr><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="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="built_in">string</span>> rules[MAXN];</span><br><span class="line"><span class="built_in">string</span> rulename[MAXN];</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">main</span><span class="params">()</span></span>{</span><br><span class="line"> <span class="keyword">char</span> c;</span><br><span class="line"> <span class="built_in">string</span> word;</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">" "</span>);</span><br><span class="line"> <span class="keyword">char</span> wb[<span class="number">101</span>];</span><br><span class="line"> <span class="built_in">cin</span> >> word;</span><br><span class="line"> <span class="function"><span class="built_in">stringstream</span> <span class="title">ss</span><span class="params">(word)</span></span>;</span><br><span class="line"> ss.get();</span><br><span class="line"> <span class="keyword">while</span>(ss){</span><br><span class="line"> ss.get(wb, <span class="number">101</span>, <span class="string">'/'</span>);</span><br><span class="line"> ss.get();</span><br><span class="line"> <span class="built_in">string</span> r = <span class="built_in">string</span>(wb);</span><br><span class="line"> <span class="keyword">if</span>(<span class="keyword">not</span> r.empty()){</span><br><span class="line"> rules[i].push_back(<span class="built_in">string</span>(wb));</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">cin</span> >> rulename[i];</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="comment">// for(int i=0;i<n;i++){</span></span><br><span class="line"> <span class="comment">// auto rule = rules[i];</span></span><br><span class="line"> <span class="comment">// cout << "DE<span class="doctag">BUG:</span>";</span></span><br><span class="line"> <span class="comment">// for(auto r:rule){</span></span><br><span class="line"> <span class="comment">// cout << r << ",";</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> <span class="comment">// cout << endl;</span></span><br><span class="line"> <span class="comment">// }</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">0</span>;i<m;i++){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">" "</span>);</span><br><span class="line"> <span class="built_in">string</span> line;</span><br><span class="line"> getline(<span class="built_in">cin</span>, line);</span><br><span class="line"> <span class="comment">// cout << "DEBUG line:" << line << endl;</span></span><br><span class="line"> <span class="keyword">bool</span> flag;</span><br><span class="line"> <span class="keyword">int</span> j;</span><br><span class="line"> <span class="built_in">vector</span> <<span class="built_in">string</span>> args;</span><br><span class="line"> <span class="keyword">for</span>(j=<span class="number">0</span>;j<n;j++){</span><br><span class="line"> args.clear();</span><br><span class="line"> <span class="function"><span class="built_in">stringstream</span> <span class="title">ss</span><span class="params">(line)</span></span>;</span><br><span class="line"> ss.get();</span><br><span class="line"> flag=<span class="literal">true</span>;</span><br><span class="line"> <span class="keyword">auto</span> rule = rules[j];</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">auto</span> r : rule){</span><br><span class="line"> <span class="keyword">if</span>(r==<span class="string">"<int>"</span>){</span><br><span class="line"> <span class="built_in">string</span> num;</span><br><span class="line"> <span class="keyword">bool</span> start=<span class="literal">true</span>;</span><br><span class="line"> <span class="keyword">char</span> wb[<span class="number">101</span>];</span><br><span class="line"> ss.get(wb, <span class="number">101</span>, <span class="string">'/'</span>);</span><br><span class="line"> ss.get();</span><br><span class="line"> <span class="comment">// assert(ss.get()=='/');</span></span><br><span class="line"> <span class="keyword">int</span> k=<span class="number">-1</span>;</span><br><span class="line"> <span class="keyword">while</span>(wb[++k]==<span class="string">'0'</span>);</span><br><span class="line"> num = <span class="built_in">string</span>(wb+k);</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">auto</span> wc:num)</span><br><span class="line"> <span class="keyword">if</span>(<span class="keyword">not</span> <span class="built_in">isdigit</span>(wc)){</span><br><span class="line"> flag=<span class="literal">false</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>(flag)</span><br><span class="line"> args.push_back(num);</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(r==<span class="string">"<str>"</span>){</span><br><span class="line"> <span class="built_in">string</span> str;</span><br><span class="line"> <span class="keyword">char</span> wb[<span class="number">101</span>];</span><br><span class="line"> ss.get(wb, <span class="number">101</span>, <span class="string">'/'</span>);</span><br><span class="line"> ss.get();</span><br><span class="line"> str = <span class="built_in">string</span>(wb);</span><br><span class="line"> <span class="keyword">if</span>(flag)</span><br><span class="line"> args.push_back(str);</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(r==<span class="string">"<path>"</span>){</span><br><span class="line"> <span class="built_in">string</span> path;</span><br><span class="line"> getline(ss, path);</span><br><span class="line"> <span class="keyword">if</span>(flag)</span><br><span class="line"> args.push_back(path);</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="built_in">string</span> str;</span><br><span class="line"> <span class="keyword">char</span> wb[<span class="number">101</span>];</span><br><span class="line"> ss.get(wb, <span class="number">101</span>, <span class="string">'/'</span>);</span><br><span class="line"> ss.get();</span><br><span class="line"> str = <span class="built_in">string</span>(wb);</span><br><span class="line"> <span class="keyword">if</span>(str!=r){</span><br><span class="line"> flag=<span class="literal">false</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(flag==<span class="literal">false</span>) <span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> ss >> c;</span><br><span class="line"> <span class="keyword">if</span>(<span class="keyword">not</span> ss.eof()) flag=<span class="literal">false</span>;</span><br><span class="line"> <span class="keyword">if</span>(flag==<span class="literal">true</span>) <span class="keyword">break</span>;</span><br><span class="line"> }<span class="keyword">if</span>(flag){</span><br><span class="line"> <span class="built_in">cout</span> << rulename[j] << <span class="string">" "</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">auto</span> s:args){</span><br><span class="line"> <span class="built_in">cout</span> << s << <span class="string">" "</span>;</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 class="keyword">else</span>{</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"404\n"</span>);</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><h2 id="201803-4-棋局评估"><a href="#201803-4-棋局评估" class="headerlink" title="201803-4 棋局评估"></a>201803-4 棋局评估</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//在if中写了等号没有察觉</span></span><br><span class="line"><span class="comment">//被memcpy坑了</span></span><br><span class="line"></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><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">vertex</span>{</span></span><br><span class="line"> <span class="keyword">int</span> x;</span><br><span class="line"> <span class="keyword">int</span> y;</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">judge</span><span class="params">(vertex v, <span class="keyword">int</span> who, <span class="keyword">int</span> board[<span class="number">3</span>][<span class="number">3</span>])</span></span>{</span><br><span class="line"> <span class="keyword">bool</span> row=<span class="literal">true</span>, col=<span class="literal">true</span>, xl=<span class="literal">true</span>, xr=<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">3</span>;i++){</span><br><span class="line"> <span class="keyword">if</span>(board[v.x][i]!=who)</span><br><span class="line"> row = <span class="literal">false</span>;</span><br><span class="line"> <span class="keyword">if</span>(board[i][v.y]!=who)</span><br><span class="line"> col = <span class="literal">false</span>;</span><br><span class="line"> <span class="keyword">if</span>(v.x==v.y){</span><br><span class="line"> <span class="keyword">if</span>(board[i][i]!=who){</span><br><span class="line"> xl=<span class="literal">false</span>;</span><br><span class="line"> }</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> xl=<span class="literal">false</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(v.x==<span class="number">2</span>-v.y){</span><br><span class="line"> <span class="keyword">if</span>(board[i][<span class="number">2</span>-i]!=who) xr=<span class="literal">false</span>;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> xr=<span class="literal">false</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> row || col || xl || xr;</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">dfs</span><span class="params">(<span class="keyword">int</span> board[<span class="number">3</span>][<span class="number">3</span>], <span class="built_in">vector</span><vertex> rem, <span class="keyword">int</span> who)</span></span>{</span><br><span class="line"> <span class="comment">// printf("DEBUG %d %d\n", who, rem.size());</span></span><br><span class="line"> <span class="keyword">if</span>(rem.size()==<span class="number">0</span>) <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line"> <span class="keyword">if</span>(who==<span class="number">1</span>){</span><br><span class="line"> <span class="keyword">int</span> ans=<span class="number">-10</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<rem.size();i++){</span><br><span class="line"> vertex v = rem[i];</span><br><span class="line"> <span class="keyword">int</span> nboard[<span class="number">3</span>][<span class="number">3</span>];</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">3</span>;j++){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> k=<span class="number">0</span>;k<<span class="number">3</span>;k++){</span><br><span class="line"> nboard[j][k] = board[j][k];</span><br><span class="line"> <span class="comment">// printf("%d ", nboard[j][k]);</span></span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// putchar('\n');</span></span><br><span class="line"> }</span><br><span class="line"> nboard[v.x][v.y] = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(judge(v, <span class="number">1</span>, nboard)){</span><br><span class="line"> ans = max(ans, (<span class="keyword">int</span>)rem.size());</span><br><span class="line"> <span class="comment">// printf("ans:%d\n", ans);</span></span><br><span class="line"> <span class="keyword">continue</span>;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="built_in">vector</span><vertex> nrem = rem; </span><br><span class="line"> nrem.erase(nrem.begin()+i);</span><br><span class="line"> ans = max(ans, dfs(nboard, nrem, <span class="number">2</span>));</span><br><span class="line"> <span class="comment">// printf("dfs ans:%d\n", ans);</span></span><br><span class="line"> }</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="keyword">if</span>(who==<span class="number">2</span>){</span><br><span class="line"> <span class="keyword">int</span> ans=<span class="number">10</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<rem.size();i++){</span><br><span class="line"> vertex v = rem[i];</span><br><span class="line"> <span class="keyword">int</span> nboard[<span class="number">3</span>][<span class="number">3</span>];</span><br><span class="line"> <span class="comment">// memcpy(nboard, board, sizeof(board));</span></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">3</span>;j++){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> k=<span class="number">0</span>;k<<span class="number">3</span>;k++){</span><br><span class="line"> nboard[j][k] = board[j][k];</span><br><span class="line"> <span class="comment">// printf("%d ", nboard[j][k]);</span></span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// putchar('\n');</span></span><br><span class="line"> }</span><br><span class="line"> nboard[v.x][v.y] = <span class="number">2</span>;</span><br><span class="line"> <span class="keyword">if</span>(judge(v, <span class="number">2</span>, nboard)){</span><br><span class="line"> ans = min(ans, -((<span class="keyword">int</span>)rem.size()));</span><br><span class="line"> <span class="keyword">continue</span>;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="built_in">vector</span><vertex> nrem = rem; </span><br><span class="line"> nrem.erase(nrem.begin()+i);</span><br><span class="line"> ans = min(ans, dfs(nboard, nrem, <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> ans;</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;</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">for</span>(<span class="keyword">int</span> t=<span class="number">0</span>;t<T;t++){</span><br><span class="line"> <span class="keyword">int</span> board[<span class="number">3</span>][<span class="number">3</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">3</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">3</span>;j++)</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &board[i][j]);</span><br><span class="line"> <span class="built_in">vector</span> <vertex> rem;</span><br><span class="line"> <span class="keyword">int</span> pre=<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<<span class="number">3</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">3</span>;j++){</span><br><span class="line"> <span class="keyword">if</span>(judge({i, j}, <span class="number">1</span>, board)) pre=<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">else</span> <span class="keyword">if</span>(judge({i, j}, <span class="number">2</span>, board)) pre=<span class="number">2</span>;</span><br><span class="line"> <span class="keyword">if</span>(board[i][j]==<span class="number">0</span>) rem.push_back({i, j});</span><br><span class="line"> <span class="comment">// printf("%d %d :%d\n", i, j, judge({i, j}, 2, board));</span></span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">int</span> ans;</span><br><span class="line"> <span class="keyword">if</span>(pre==<span class="number">1</span>){</span><br><span class="line"> ans = rem.size()+<span class="number">1</span>;</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(pre==<span class="number">2</span>){</span><br><span class="line"> ans = -(rem.size()+<span class="number">1</span>);</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> ans = dfs(board, rem, <span class="number">1</span>);</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><h2 id="201803-5"><a href="#201803-5" class="headerlink" title="201803-5"></a>201803-5</h2><h2 id><a href="#" class="headerlink" title></a><a href="/2019/09/10/csp-intergrated/" title="csp题集汇总">csp题集汇总</a></h2><hr>]]></content>
<categories>
<category> csp </category>
</categories>
<tags>
<tag> csp </tag>
</tags>
</entry>
<entry>
<title>csp-201809</title>
<link href="/2019/09/10/csp-201809/"/>
<url>/2019/09/10/csp-201809/</url>
<content type="html"><![CDATA[<h2 id="201809-1-卖菜"><a href="#201809-1-卖菜" class="headerlink" title="201809-1 卖菜"></a>201809-1 卖菜</h2><figure class="highlight cpp"><table><tr><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"><cstring></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="keyword">const</span> <span class="keyword">int</span> MAXN=<span class="number">1010</span>;</span><br><span class="line"><span class="keyword">int</span> a[MAXN];</span><br><span class="line"><span class="keyword">int</span> b[MAXN];</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> n;</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"</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">scanf</span>(<span class="string">"%d"</span>, &a[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><br><span class="line"><span class="keyword">if</span>(i==<span class="number">1</span>){</span><br><span class="line">b[i] = (a[<span class="number">1</span>]+a[<span class="number">2</span>])/<span class="number">2</span>;</span><br><span class="line">}<span class="keyword">else</span> <span class="keyword">if</span>(i==n){</span><br><span class="line">b[i] = (a[n] + a[n<span class="number">-1</span>])/<span class="number">2</span>;</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line">b[i] = (a[i]+a[i<span class="number">-1</span>]+a[i+<span class="number">1</span>])/<span class="number">3</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<=n;i++){</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">"%d"</span>, b[i]);</span><br><span class="line"><span class="keyword">if</span>(i==n){</span><br><span class="line"><span class="built_in">putchar</span>(<span class="string">'\n'</span>);</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line"><span class="built_in">putchar</span>(<span class="string">' '</span>);</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><h2 id="201809-2-买菜"><a href="#201809-2-买菜" class="headerlink" title="201809-2 买菜"></a>201809-2 买菜</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//简单模拟</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><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> MAXN=<span class="number">1000000</span> + <span class="number">10</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">bool</span> H[MAXN], W[MAXN];</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> n,ans;</span><br><span class="line"><span class="keyword">int</span> mmax=<span class="number">0</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">scanf</span>(<span class="string">"%d"</span>, &n);</span><br><span class="line"><span class="keyword">int</span> a,b;</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, &b);</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> j=a;j<b;j++) H[j] = <span class="literal">true</span>;</span><br><span class="line">}</span><br><span class="line">mmax = b;</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, &b);</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> j=a;j<b;j++) W[j] = <span class="literal">true</span>;</span><br><span class="line">}</span><br><span class="line">mmax = max(mmax, b);</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">0</span>;i<=mmax;i++)</span><br><span class="line"><span class="keyword">if</span>(H[i]&&W[i]) 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">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="201809-3-元素选择器"><a href="#201809-3-元素选择器" class="headerlink" title="201809-3 元素选择器"></a>201809-3 元素选择器</h2><figure class="highlight cpp"><table><tr><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="keyword">int</span> n,m;</span><br><span class="line"></span><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">Node_DEF</span>{</span></span><br><span class="line"><span class="built_in">string</span> tag;</span><br><span class="line"><span class="built_in">string</span> id;</span><br><span class="line">Node_DEF * fa;</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="built_in">deque</span> <Node_DEF> pool;</span><br><span class="line"><span class="built_in">stack</span> <Node_DEF *> stk;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">select</span><span class="params">(<span class="built_in">vector</span> <<span class="built_in">string</span>> sel, Node_DEF tar)</span></span>{</span><br><span class="line"><span class="keyword">if</span>(sel.size() == <span class="number">0</span>) <span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line"><span class="keyword">if</span>(tar.fa == <span class="literal">NULL</span>) <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line"><span class="built_in">string</span> cur = sel.back();</span><br><span class="line"><span class="comment">// cout << "DE<span class="doctag">BUG:</span>";</span></span><br><span class="line"><span class="comment">// for(auto s:sel) cout << s << "," ;</span></span><br><span class="line"><span class="comment">// cout << endl;</span></span><br><span class="line"><span class="comment">// cout << "DEBUG tar: " << tar.tag << " "<< tar.id << endl;</span></span><br><span class="line"><span class="keyword">if</span>(cur[<span class="number">0</span>] == <span class="string">'#'</span> ){</span><br><span class="line"><span class="keyword">if</span>(tar.id == cur.substr(<span class="number">1</span>)){</span><br><span class="line">sel.pop_back();</span><br><span class="line"><span class="keyword">return</span> select(sel, *(tar.fa));</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line"><span class="keyword">return</span> select(sel, *(tar.fa));</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>(tar.tag == cur){</span><br><span class="line">sel.pop_back();</span><br><span class="line"><span class="keyword">return</span> select(sel, *(tar.fa));</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line"><span class="keyword">return</span> select(sel, *(tar.fa));</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><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, &m);</span><br><span class="line"><span class="keyword">int</span> sdeep=<span class="number">-2</span>,deep=<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<n;i++){</span><br><span class="line"><span class="built_in">string</span> tag;</span><br><span class="line"><span class="built_in">string</span> id;</span><br><span class="line"><span class="keyword">while</span>(<span class="number">1</span>){</span><br><span class="line"><span class="keyword">char</span> c =getchar();</span><br><span class="line"><span class="keyword">if</span>(c==<span class="string">'.'</span>){</span><br><span class="line">deep=<span class="number">1</span>;</span><br><span class="line"><span class="keyword">while</span>(<span class="number">1</span>) {</span><br><span class="line">c = getchar();</span><br><span class="line"><span class="keyword">if</span>(c!=<span class="string">'.'</span>) <span class="keyword">break</span>;</span><br><span class="line">deep++;</span><br><span class="line">}</span><br><span class="line">}</span><br><span class="line"><span class="comment">// printf("deep: %d\n", deep);</span></span><br><span class="line"><span class="keyword">if</span>(c>=<span class="string">'A'</span> && c <=<span class="string">'Z'</span>) c = c-<span class="string">'A'</span>+<span class="string">'a'</span>;</span><br><span class="line">tag.push_back(c);</span><br><span class="line"><span class="keyword">while</span>(<span class="number">1</span>){</span><br><span class="line">c = getchar();</span><br><span class="line"><span class="keyword">if</span>(c==<span class="string">' '</span>||c==<span class="string">'\n'</span>) <span class="keyword">break</span>;</span><br><span class="line">tag.push_back(c);</span><br><span class="line">}</span><br><span class="line"><span class="keyword">if</span>(c==<span class="string">'\n'</span>) <span class="keyword">break</span>;</span><br><span class="line">c = getchar();</span><br><span class="line"><span class="built_in">cin</span> >> id;</span><br><span class="line"><span class="built_in">scanf</span>(<span class="string">" "</span>);</span><br><span class="line"><span class="keyword">break</span>;</span><br><span class="line">}</span><br><span class="line">Node_DEF node = {tag, id, <span class="literal">NULL</span>};</span><br><span class="line"><span class="keyword">if</span>(deep == sdeep + <span class="number">2</span>){</span><br><span class="line"><span class="keyword">if</span>(sdeep != <span class="number">-2</span>) node.fa = stk.top();</span><br><span class="line">pool.push_back(node);</span><br><span class="line">stk.push(&pool.back());</span><br><span class="line">}<span class="keyword">else</span> <span class="keyword">if</span>(deep == sdeep - <span class="number">2</span>){</span><br><span class="line">stk.pop();</span><br><span class="line">stk.pop();</span><br><span class="line"><span class="keyword">if</span>(sdeep != <span class="number">-2</span>) node.fa = stk.top();</span><br><span class="line">pool.push_back(node);</span><br><span class="line">stk.push(&pool.back());</span><br><span class="line">}<span class="keyword">else</span> <span class="keyword">if</span>(deep == sdeep){</span><br><span class="line">stk.pop();</span><br><span class="line"><span class="keyword">if</span>(sdeep != <span class="number">-2</span>) node.fa = stk.top();</span><br><span class="line">pool.push_back(node);</span><br><span class="line">stk.push(&pool.back());</span><br><span class="line">}</span><br><span class="line">sdeep = deep;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="comment">// for(auto it:pool){</span></span><br><span class="line"><span class="comment">// cout << "DEBUG tag:" << it.tag << " id:" << it.id;</span></span><br><span class="line"><span class="comment">// if(it.fa != NULL){</span></span><br><span class="line"><span class="comment">// printf(" father: %s %s", (*(it.fa)).tag.c_str(), (*(it.fa)).id.c_str());</span></span><br><span class="line"><span class="comment">// // printf("DEBUG it.fa:%p\n", it.fa);</span></span><br><span class="line"><span class="comment">// }</span></span><br><span class="line"><span class="comment">// putchar('\n');</span></span><br><span class="line"><span class="comment">// }</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">0</span>;i<m;i++){</span><br><span class="line"><span class="built_in">vector</span> <<span class="built_in">string</span>> sels;</span><br><span class="line"><span class="built_in">scanf</span>(<span class="string">" "</span>);</span><br><span class="line"></span><br><span class="line"><span class="keyword">while</span>(<span class="number">1</span>){</span><br><span class="line"><span class="keyword">char</span> sb[<span class="number">1000</span>];</span><br><span class="line"><span class="keyword">char</span> c;</span><br><span class="line"><span class="built_in">scanf</span>(<span class="string">"%s"</span>, sb);</span><br><span class="line"><span class="keyword">if</span>(sb[<span class="number">0</span>]!=<span class="string">'#'</span>)</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> k=<span class="number">0</span>;k<<span class="built_in">strlen</span>(sb);k++) <span class="keyword">if</span>(sb[k]>=<span class="string">'A'</span>&&sb[k]<=<span class="string">'Z'</span>) sb[k] = sb[k]-<span class="string">'A'</span>+<span class="string">'a'</span>;</span><br><span class="line">sels.push_back(<span class="built_in">string</span>(sb));</span><br><span class="line">c = getchar();</span><br><span class="line"><span class="comment">// cout << "DE<span class="doctag">BUG:</span>" << s << endl;</span></span><br><span class="line"><span class="comment">// printf("%d|%c\n", c, c);</span></span><br><span class="line"><span class="keyword">if</span>(c==<span class="string">'\n'</span>||c==<span class="number">-1</span>) <span class="keyword">break</span>;</span><br><span class="line">}</span><br><span class="line"><span class="comment">// cout << "DEBUG sels:";</span></span><br><span class="line"><span class="comment">// for(auto k:sels) cout << k << " ";</span></span><br><span class="line"><span class="comment">// cout << endl;</span></span><br><span class="line"><span class="built_in">vector</span> <<span class="keyword">int</span>> ans;</span><br><span class="line">ans.clear();</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> j=<span class="number">0</span>;j<pool.size();j++){</span><br><span class="line"><span class="keyword">auto</span> it = pool[j];</span><br><span class="line"><span class="built_in">string</span> cur = sels.back();</span><br><span class="line"><span class="comment">// cout << "DE<span class="doctag">BUG:</span>" << cur << endl;</span></span><br><span class="line"><span class="keyword">if</span>(cur[<span class="number">0</span>]==<span class="string">'#'</span> && it.id==cur.substr(<span class="number">1</span>) && select(sels, it)){</span><br><span class="line"><span class="comment">// printf("%d ", j);</span></span><br><span class="line">ans.push_back(j+<span class="number">1</span>);</span><br><span class="line">}<span class="keyword">else</span>{</span><br><span class="line"><span class="keyword">if</span>(it.tag==cur && select(sels, it))</span><br><span class="line"><span class="comment">// printf("%d ", j);</span></span><br><span class="line">ans.push_back(j+<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">"%d"</span>, ans.size());</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">auto</span> it:ans){</span><br><span class="line"><span class="built_in">printf</span>(<span class="string">" %d"</span>, it);</span><br><span class="line">}</span><br><span class="line"><span class="built_in">putchar</span>(<span class="string">'\n'</span>);</span><br><span class="line">}</span><br><span class="line"><span class="comment">// for(auto it:pool){</span></span><br><span class="line"><span class="comment">// cout << "DEBUG tag:" << it.tag << " id:" << it.id;</span></span><br><span class="line"><span class="comment">// if(it.fa != NULL){</span></span><br><span class="line"><span class="comment">// printf(" father: %s", (*(it.fa)).tag.c_str());</span></span><br><span class="line"><span class="comment">// // printf("DEBUG it.fa:%p\n", it.fa);</span></span><br><span class="line"><span class="comment">// }</span></span><br><span class="line"><span class="comment">// putchar('\n');</span></span><br><span class="line"><span class="comment">// }</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><h2 id="201809-4-再卖菜"><a href="#201809-4-再卖菜" class="headerlink" title="201809-4 再卖菜"></a>201809-4 再卖菜</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//if 构造出错</span></span><br><span class="line"><span class="comment">//没有看请注意 只有第二天的菜价不超过100;</span></span><br><span class="line"><span class="comment">//最基本的两个数的测试出错</span></span><br><span class="line"><span class="comment">//for循环 dfs没有考虑1</span></span><br><span class="line"><span class="comment">//超时</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><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> n;</span><br><span class="line"><span class="keyword">int</span> a[<span class="number">400</span>];</span><br><span class="line"><span class="keyword">int</span> b[<span class="number">400</span>];</span><br><span class="line"></span><br><span class="line"><span class="keyword">bool</span> ifans;</span><br><span class="line"><span class="keyword">int</span> ans[<span class="number">400</span>];</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">dfs</span><span class="params">(<span class="keyword">int</span> idx)</span></span>{</span><br><span class="line"><span class="keyword">if</span>(idx==n+<span class="number">1</span>){</span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> k=<span class="number">1</span>;k<=n;k++) ans[k] = a[k];</span><br><span class="line">ifans = <span class="literal">true</span>;</span><br><span class="line"><span class="comment">// printf("ans :\n");</span></span><br><span class="line"><span class="comment">// for(int k=1;k<=n;k++) printf("%d ", ans[k]);</span></span><br><span class="line"><span class="comment">// putchar('\n');</span></span><br><span class="line"><span class="keyword">return</span> <span class="literal">true</span>;</span><br><span class="line">}</span><br><span class="line"><span class="keyword">int</span> low=<span class="number">1</span>,high=<span class="number">300</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">if</span>(idx==<span class="number">1</span>){</span><br><span class="line">high = min(high, <span class="number">2</span>*b[<span class="number">1</span>]+<span class="number">2</span><span class="number">-1</span>);</span><br><span class="line">}<span class="keyword">else</span> <span class="keyword">if</span>(idx==<span class="number">2</span>){</span><br><span class="line"><span class="comment">// printf("DEBUG1: %d\n", (num+a[1])/2);</span></span><br><span class="line">low = max(low, <span class="number">2</span>*b[<span class="number">1</span>]-a[<span class="number">1</span>]);</span><br><span class="line">high = min(high, <span class="number">2</span>*b[<span class="number">1</span>]-a[<span class="number">1</span>]+<span class="number">2</span>);</span><br><span class="line">}<span class="keyword">else</span> {</span><br><span class="line">low = max(low, <span class="number">3</span>*b[idx<span class="number">-1</span>]-a[idx<span class="number">-1</span>]-a[idx<span class="number">-2</span>]);</span><br><span class="line">high = min(high, <span class="number">3</span>*b[idx<span class="number">-1</span>]-a[idx<span class="number">-1</span>]-a[idx<span class="number">-2</span>]+<span class="number">3</span>);</span><br><span class="line">}</span><br><span class="line"><span class="keyword">if</span>(idx==n){</span><br><span class="line">low = max(low, <span class="number">2</span>*b[n]-a[n<span class="number">-1</span>]);</span><br><span class="line">high = min(high, <span class="number">2</span>*b[n]-a[n<span class="number">-1</span>]+<span class="number">2</span>);</span><br><span class="line">}</span><br><span class="line"><span class="keyword">if</span>(high <= low) <span class="keyword">return</span> <span class="literal">false</span>;</span><br><span class="line"></span><br><span class="line"><span class="keyword">for</span>(<span class="keyword">int</span> i=low;i<high;i++){</span><br><span class="line">a[idx] = i;</span><br><span class="line"><span class="keyword">if</span>(dfs(idx+<span class="number">1</span>)) <span class="keyword">return</span> <span class="literal">true</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">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"</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>, &b[i]);</span><br><span class="line"></span><br><span class="line">dfs(<span class="number">1</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="built_in">printf</span>(<span class="string">"%d"</span>, ans[i]);</span><br><span class="line"><span class="keyword">if</span>(i==n) <span class="built_in">putchar</span>(<span class="string">'\n'</span>);</span><br><span class="line"><span class="keyword">else</span> <span class="built_in">putchar</span>(<span class="string">' '</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><h2 id="201809-5"><a href="#201809-5" class="headerlink" title="201809-5"></a>201809-5</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//大数的时候请仔细思考</span></span><br><span class="line"><span class="comment">// num += k %Q cmp num = (num + k)%Q</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><br><span class="line"><span class="keyword">const</span> <span class="keyword">int</span> MAXN=<span class="number">1e6</span>+<span class="number">10</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">ll Q = <span class="number">998244353</span>;</span><br><span class="line">ll k[MAXN];</span><br><span class="line">ll a[MAXN];</span><br><span class="line">ll m,l,r;</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 %d\n"</span>, &m, &l, &r);</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">"%llu"</span>, &k[i]);</span><br><span class="line"> }</span><br><span class="line"> a[<span class="number">0</span>] = <span class="number">1</span>;</span><br><span class="line"> ll n = <span class="number">1</span>;</span><br><span class="line"> <span class="keyword">while</span>(n<=r){</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=<span class="number">1</span>;i<=min(n, m);i++){</span><br><span class="line"> a[n] = (a[n] + (k[i]*a[n-i])%Q)%Q;</span><br><span class="line"> }</span><br><span class="line"> n++;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> i=l;i<=r;i++){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%llu\n"</span>, a[i]);</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><h2 id><a href="#" class="headerlink" title></a><a href="/2019/09/10/csp-intergrated/" title="csp题集汇总">csp题集汇总</a></h2><hr>]]></content>
<categories>
<category> csp </category>
</categories>
<tags>
<tag> csp </tag>
</tags>
</entry>
<entry>
<title>csp-201812</title>
<link href="/2019/09/10/csp-201812/"/>
<url>/2019/09/10/csp-201812/</url>
<content type="html"><![CDATA[<h2 id="201812-1-小明上学"><a href="#201812-1-小明上学" class="headerlink" title="201812-1 小明上学"></a>201812-1 小明上学</h2><figure class="highlight cpp"><table><tr><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="keyword">int</span> r,y,g;</span><br><span class="line"><span class="keyword">int</span> n;</span><br><span class="line"><span class="keyword">int</span> ans;</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 %d"</span>, &r, &y, &g);</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="keyword">int</span> k,t;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d"</span>, &k, &t);</span><br><span class="line"> <span class="keyword">switch</span>(k){</span><br><span class="line"> <span class="keyword">case</span> <span class="number">0</span>: ans+=t; <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">1</span>: ans+=t;<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">2</span>: ans+=(t+r);<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">3</span>: <span class="keyword">break</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">"%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><h2 id="201812-2-小明放学"><a href="#201812-2-小明放学" class="headerlink" title="201812-2 小明放学"></a>201812-2 小明放学</h2><figure class="highlight cpp"><table><tr><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="keyword">int</span> r,y,g;</span><br><span class="line"><span class="keyword">int</span> n;</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 ans;</span><br><span class="line"></span><br><span class="line"><span class="function">ll <span class="title">crosstime</span><span class="params">(<span class="keyword">int</span> k, <span class="keyword">int</span> t)</span></span>{</span><br><span class="line"> ll base;</span><br><span class="line"> <span class="keyword">switch</span>(k){</span><br><span class="line"> <span class="keyword">case</span> <span class="number">1</span>: base = (r-t+ans)%(r+y+g);<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">2</span>: base = (r+g+y-t+ans)%(r+y+g);<span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">case</span> <span class="number">3</span>: base = (r+g-t+ans)%(r+y+g);<span class="keyword">break</span>;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(base < r){</span><br><span class="line"> <span class="keyword">return</span> r-base;</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(base < r+g){</span><br><span class="line"> <span class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">return</span> r+g+y - base + r;</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 %d"</span>, &r, &y, &g);</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="keyword">int</span> k,t;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d"</span>, &k, &t);</span><br><span class="line"> <span class="keyword">if</span>(k==<span class="number">0</span>){</span><br><span class="line"> <span class="comment">// printf("DEBUG t:%d\n", t);</span></span><br><span class="line"> ans+=t;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">else</span>{</span><br><span class="line"> <span class="comment">// printf("DEBUG cros:%lld", crosstime(k, t));</span></span><br><span class="line"> ans+=crosstime(k, t);</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><h2 id="201812-3-CIDR合并"><a href="#201812-3-CIDR合并" class="headerlink" title="201812-3 CIDR合并"></a>201812-3 CIDR合并</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//BUG %d输入给一个字符造成溢出错误</span></span><br><span class="line"><span class="comment">//运算符优先级 & ==</span></span><br><span class="line"><span class="comment">//搞错了cmp的规则(糊涂)</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><br><span class="line"><span class="class"><span class="keyword">struct</span> <span class="title">IP_DEF</span>{</span></span><br><span class="line"> <span class="keyword">unsigned</span> <span class="keyword">int</span> ip;</span><br><span class="line"> <span class="keyword">int</span> len;</span><br><span class="line">};</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> n;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">bool</span> <span class="title">cmp</span><span class="params">(IP_DEF & a, IP_DEF & b)</span></span>{</span><br><span class="line"> <span class="keyword">if</span>(a.ip==b.ip) <span class="keyword">return</span> a.len < b.len;</span><br><span class="line"> <span class="keyword">return</span> a.ip < b.ip;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="built_in">deque</span> <IP_DEF> pool;</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"</span>, &n);</span><br><span class="line"> pool.resize(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="keyword">int</span> cnt=<span class="number">3</span>;</span><br><span class="line"> <span class="keyword">unsigned</span> <span class="keyword">char</span> * p = (<span class="keyword">unsigned</span> <span class="keyword">char</span> *) &(pool[i].ip);</span><br><span class="line"> <span class="keyword">while</span>(<span class="number">1</span>){</span><br><span class="line"> <span class="keyword">int</span> num;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">" %d"</span>, &num);</span><br><span class="line"> *(p+cnt) = num;</span><br><span class="line"> <span class="keyword">char</span> c = getchar();</span><br><span class="line"> <span class="comment">// printf("DEBUG c:%d|%c\n", c);</span></span><br><span class="line"> <span class="keyword">if</span>(c==<span class="string">'.'</span>){</span><br><span class="line"> cnt--;</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(c==<span class="string">'/'</span>){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d "</span>, &pool[i].len);</span><br><span class="line"> <span class="keyword">break</span>;</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(c==<span class="string">'\n'</span>||c==<span class="number">-1</span>){</span><br><span class="line"> pool[i].len = (<span class="number">4</span>-cnt)*<span class="number">8</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><br><span class="line"> </span><br><span class="line"> sort(pool.begin(), pool.end(), cmp);</span><br><span class="line"> </span><br><span class="line"> <span class="built_in">deque</span><IP_DEF>::iterator a = pool.begin(), b;</span><br><span class="line"></span><br><span class="line"> <span class="keyword">while</span>(<span class="number">1</span>){</span><br><span class="line"> b = a+<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(b==pool.end()) <span class="keyword">break</span>;</span><br><span class="line"> <span class="comment">//exile</span></span><br><span class="line"> <span class="keyword">if</span>((*a).len <= (*b).len){</span><br><span class="line"> <span class="keyword">int</span> shift = (*a).len;</span><br><span class="line"> <span class="keyword">unsigned</span> base = ~((<span class="keyword">unsigned</span>)<span class="number">-1</span>>>(shift));</span><br><span class="line"> <span class="keyword">if</span>((*a).ip & base == (*b).ip & base){</span><br><span class="line"> pool.erase(b);</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> a+=<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"> a+=<span class="number">1</span>;</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// printf("hhh\n");</span></span><br><span class="line"> a=pool.begin();</span><br><span class="line"> <span class="keyword">while</span>(<span class="number">1</span>){</span><br><span class="line"> b=a+<span class="number">1</span>;</span><br><span class="line"> <span class="keyword">if</span>(b==pool.end()) <span class="keyword">break</span>;</span><br><span class="line"> <span class="comment">//merge</span></span><br><span class="line"> <span class="keyword">if</span>((*a).len == (*b).len){</span><br><span class="line"> <span class="keyword">int</span> shift=(*a).len;</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">unsigned</span> base = ~((<span class="keyword">unsigned</span>)<span class="number">-1</span>>>(shift<span class="number">-1</span>));</span><br><span class="line"> <span class="keyword">unsigned</span> base2 = ((<span class="keyword">unsigned</span>)<span class="number">0x80000000</span>>>(shift<span class="number">-1</span>));</span><br><span class="line"> <span class="keyword">if</span>(((*a).ip & base) == ((*b).ip & base) && ((*a).ip & base2) ^ ((*b).ip & base2)){</span><br><span class="line"> (*a).ip = (*a).ip & ~base2;</span><br><span class="line"> (*a).len -= <span class="number">1</span>;</span><br><span class="line"> pool.erase(b);</span><br><span class="line"> <span class="keyword">if</span>(a>pool.begin()) a-=<span class="number">1</span>;</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> a++;</span><br><span class="line"> }</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> a++;</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">auto</span> it: pool){</span><br><span class="line"> <span class="keyword">int</span> cnt = <span class="number">3</span>;</span><br><span class="line"> <span class="keyword">unsigned</span> <span class="keyword">char</span> * p = (<span class="keyword">unsigned</span> <span class="keyword">char</span> *)&(it.ip);</span><br><span class="line"> <span class="keyword">while</span>(cnt>=<span class="number">0</span>){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%hhu"</span>, *(p+cnt));</span><br><span class="line"> <span class="keyword">if</span>(cnt==<span class="number">0</span>){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"/%d\n"</span>, it.len);</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="built_in">putchar</span>(<span class="string">'.'</span>);</span><br><span class="line"> }</span><br><span class="line"> cnt--;</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// printf("%08X : %d\n", pool[i].ip, pool[i].len);</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><h2 id="201812-4-数据中心"><a href="#201812-4-数据中心" class="headerlink" title="201812-4 数据中心"></a>201812-4 数据中心</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//简单最小生成树</span></span><br><span class="line"></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">const</span> <span class="keyword">int</span> N = <span class="number">1e5</span> + <span class="number">10</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="keyword">int</span> fa[N];</span><br><span class="line"></span><br><span class="line"><span class="keyword">int</span> n,m,root;</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">init</span><span class="params">(<span class="keyword">int</span> n)</span> </span>{ <span class="comment">// 不要忘记哦!!!</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"> fa[i] = i;</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">find</span><span class="params">(<span class="keyword">int</span> u)</span> </span>{</span><br><span class="line"> <span class="keyword">if</span> (fa[u] != u) {</span><br><span class="line"> fa[u] = find(fa[u]);</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">return</span> fa[u];</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="function"><span class="keyword">void</span> <span class="title">unin</span><span class="params">(<span class="keyword">int</span> u, <span class="keyword">int</span> v)</span> </span>{</span><br><span class="line"> <span class="keyword">int</span> fau = find(u);</span><br><span class="line"> <span class="keyword">int</span> fav = find(v);</span><br><span class="line"> <span class="keyword">if</span> (fau == fav) <span class="keyword">return</span>;</span><br><span class="line"> fa[fav] = fau;</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="class"><span class="keyword">struct</span> <span class="title">EDGE_DEF</span>{</span></span><br><span class="line"> <span class="keyword">int</span> u,v,w;</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">cmp</span><span class="params">(EDGE_DEF & a, EDGE_DEF & b)</span></span>{</span><br><span class="line"> <span class="keyword">return</span> a.w < b.w;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="built_in">deque</span> <EDGE_DEF> edges;</span><br><span class="line"><span class="built_in">deque</span> <EDGE_DEF> T;</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 %d"</span>, &n, &m, &root);</span><br><span class="line"> init(m);</span><br><span class="line"> edges.resize(m);</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<m;i++){</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d %d %d"</span>, &edges[i].u, &edges[i].v, &edges[i].w);</span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> </span><br><span class="line"> sort(edges.begin(), edges.end(), cmp);</span><br><span class="line"> <span class="comment">// for(auto e: edges){</span></span><br><span class="line"> <span class="comment">// printf("%d %d %d\n", e.u, e.v, e.w);</span></span><br><span class="line"> <span class="comment">// } </span></span><br><span class="line"></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">auto</span> e: edges){</span><br><span class="line"> <span class="keyword">if</span>(find(e.u) == find(e.v)){</span><br><span class="line"> <span class="keyword">continue</span>;</span><br><span class="line"> }</span><br><span class="line"> unin(e.u, e.v);</span><br><span class="line"> T.push_back(e);</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// for(auto e: T){</span></span><br><span class="line"> <span class="comment">// printf("%d %d %d\n", e.u, e.v, e.w);</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d\n"</span>, T.back().w);</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><h2 id="201812-5-管道清洁"><a href="#201812-5-管道清洁" class="headerlink" title="201812-5 管道清洁"></a>201812-5 管道清洁</h2><h2 id><a href="#" class="headerlink" title></a><a href="/2019/09/10/csp-intergrated/" title="csp题集汇总">csp题集汇总</a></h2><hr>]]></content>
<categories>
<category> csp </category>
</categories>
<tags>
<tag> csp </tag>
</tags>
</entry>
<entry>
<title>csp-201903</title>
<link href="/2019/09/10/csp-201903/"/>
<url>/2019/09/10/csp-201903/</url>
<content type="html"><![CDATA[<h2 id="201903-1-小中大"><a href="#201903-1-小中大" class="headerlink" title="201903-1 小中大"></a>201903-1 小中大</h2><figure class="highlight cpp"><table><tr><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="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> n;</span><br><span class="line"><span class="keyword">int</span> mmax = - <span class="number">1e7</span> - <span class="number">10</span>, mmin = <span class="number">1e7</span> + <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">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><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &a[i]);</span><br><span class="line"> mmax = max(a[i], mmax);</span><br><span class="line"> mmin = min(a[i], mmin);</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d "</span>, mmax);</span><br><span class="line"> <span class="keyword">if</span>(n%<span class="number">2</span>){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d "</span>, a[(n+<span class="number">1</span>)/<span class="number">2</span>]);</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="keyword">double</span> val = (a[n/<span class="number">2</span>]*<span class="number">1.0</span> + a[n/<span class="number">2</span>+<span class="number">1</span>])/<span class="number">2</span>;</span><br><span class="line"> <span class="keyword">if</span>(val - (<span class="keyword">int</span>)val != <span class="number">0.0</span>)</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%.1f "</span>, val);</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>, (<span class="keyword">int</span>)val);</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%d\n"</span>, mmin);</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><h2 id="201903-2-二十四点"><a href="#201903-2-二十四点" class="headerlink" title="201903-2 二十四点"></a>201903-2 二十四点</h2><figure class="highlight cpp"><table><tr><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><br><span class="line"><span class="keyword">int</span> n;</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> >> 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">string</span> tar;</span><br><span class="line"> <span class="built_in">cin</span> >> tar;</span><br><span class="line"> <span class="built_in">vector</span> <<span class="keyword">int</span>> num;</span><br><span class="line"> <span class="built_in">vector</span> <<span class="keyword">char</span>> op;</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">4</span>;j++)</span><br><span class="line"> num.push_back(tar[j*<span class="number">2</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> j=<span class="number">0</span>;j<<span class="number">3</span>;j++)</span><br><span class="line"> op.push_back(tar[j*<span class="number">2</span>+<span class="number">1</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> j=<span class="number">0</span>;j<op.size();j++){</span><br><span class="line"> <span class="keyword">if</span>(op[j]==<span class="string">'x'</span> || op[j]==<span class="string">'/'</span>){</span><br><span class="line"> <span class="keyword">if</span>(op[j]==<span class="string">'x'</span>)</span><br><span class="line"> num[j] = num[j] * num[j+<span class="number">1</span>];</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> num[j] = num[j] / num[j+<span class="number">1</span>];</span><br><span class="line"> num.erase(num.begin() + j + <span class="number">1</span>);</span><br><span class="line"> op.erase(op.begin() + j); </span><br><span class="line"> j--;</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=<span class="number">0</span>;j<op.size();j++){</span><br><span class="line"> <span class="keyword">if</span>(op[<span class="number">0</span>]==<span class="string">'+'</span>)</span><br><span class="line"> num[<span class="number">0</span>] = num[<span class="number">0</span>] + num[<span class="number">1</span>];</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> num[<span class="number">0</span>] = num[<span class="number">0</span>] - num[<span class="number">1</span>];</span><br><span class="line"> num.erase(num.begin() + <span class="number">1</span>);</span><br><span class="line"> op.erase(op.begin());</span><br><span class="line"> j--;</span><br><span class="line"> }</span><br><span class="line"> <span class="keyword">if</span>(num[<span class="number">0</span>] == <span class="number">24</span>) <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 class="keyword">return</span> <span class="number">0</span>;</span><br><span class="line">}</span><br></pre></td></tr></table></figure><h2 id="201903-3-损坏的RAID5"><a href="#201903-3-损坏的RAID5" class="headerlink" title="201903-3 损坏的RAID5"></a>201903-3 损坏的RAID5</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//运行超时</span></span><br><span class="line"><span class="comment">//卡时间</span></span><br><span class="line"><span class="comment">//不要将字母转换为数字再做</span></span><br><span class="line"><span class="comment">//直接使用一个int来做xor</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><br><span class="line"><span class="keyword">char</span> hards[<span class="number">1020</span>][<span class="number">85000</span>];</span><br><span class="line"><span class="keyword">bool</span> exists[<span class="number">1020</span>];</span><br><span class="line"><span class="keyword">int</span> n,s,l,m;</span><br><span class="line"><span class="keyword">int</span> hardsize;</span><br><span class="line"><span class="function"><span class="keyword">int</span> <span class="title">getk</span><span class="params">(<span class="keyword">int</span> idx)</span></span>{</span><br><span class="line"> <span class="keyword">return</span> idx/(n<span class="number">-1</span>);</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">gethardnum</span><span class="params">(<span class="keyword">int</span> idx)</span></span>{</span><br><span class="line"> <span class="keyword">return</span> (idx%(n<span class="number">-1</span>)-getk(idx)+n)%n;</span><br><span class="line">}</span><br><span class="line"></span><br><span class="line"><span class="keyword">char</span> _xor(<span class="keyword">char</span> a,<span class="keyword">char</span> b){</span><br><span class="line"> <span class="keyword">if</span>(a>=<span class="string">'A'</span>) a = a-<span class="string">'A'</span> + <span class="number">10</span>;</span><br><span class="line"> <span class="keyword">else</span> a = a-<span class="string">'0'</span>;</span><br><span class="line"> <span class="keyword">if</span>(b>=<span class="string">'A'</span>) b = b-<span class="string">'A'</span> + <span class="number">10</span>;</span><br><span class="line"> <span class="keyword">else</span> b = b - <span class="string">'0'</span>;</span><br><span class="line"> <span class="keyword">char</span> res = a^b;</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"a:%d b:%d res:%d\n"</span>, a, b, res);</span><br><span class="line"> <span class="keyword">return</span> res>=<span class="number">10</span> ? res<span class="number">-10</span>+<span class="string">'A'</span>: res+<span class="string">'0'</span>;</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 %d"</span>, &n, &s, &l);</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">int</span> num;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &num);</span><br><span class="line"> getchar();</span><br><span class="line"> exists[num] = <span class="literal">true</span>;</span><br><span class="line"> <span class="built_in">string</span> val;</span><br><span class="line"> <span class="comment">// cin >> val;</span></span><br><span class="line"> <span class="comment">// scanf("%s", val);</span></span><br><span class="line"> <span class="comment">// for(int j=0;j<val.size()/2;j++){</span></span><br><span class="line"> <span class="comment">// sscanf(val.substr(j*2, 2).c_str(), "%x", &hards[num][j]);</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"></span><br><span class="line"> hardsize = <span class="number">0</span>;</span><br><span class="line"> </span><br><span class="line"> <span class="comment">// while(1){</span></span><br><span class="line"> <span class="comment">// char val[3];</span></span><br><span class="line"> <span class="comment">// val[0] = getchar();</span></span><br><span class="line"> <span class="comment">// if(val[0] == 10) break;</span></span><br><span class="line"> <span class="comment">// val[1] = getchar();</span></span><br><span class="line"> <span class="comment">// sscanf(val, "%x", &hards[num][hardsize]);</span></span><br><span class="line"> <span class="comment">// hardsize++;</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> fgets(hards[num], <span class="number">85000</span>, <span class="built_in">stdin</span>);</span><br><span class="line"> <span class="keyword">int</span> bl = <span class="built_in">strlen</span>(hards[num]);</span><br><span class="line"> hardsize = bl/<span class="number">2</span>;</span><br><span class="line"> <span class="comment">// printf("hardsize:%d\n", hardsize);</span></span><br><span class="line"> }</span><br><span class="line"></span><br><span class="line"> <span class="comment">// int tar=0;</span></span><br><span class="line"> <span class="comment">// if(n==l+1){</span></span><br><span class="line"> <span class="comment">// while(exists[tar++]);</span></span><br><span class="line"> <span class="comment">// tar--;</span></span><br><span class="line"> <span class="comment">// // printf("tar:%d\n", tar);</span></span><br><span class="line"> <span class="comment">// for(int i=0;i<hardsize;i++){</span></span><br><span class="line"> <span class="comment">// unsigned char exam=0;</span></span><br><span class="line"> <span class="comment">// for(int j=0;j<n;j++){</span></span><br><span class="line"> <span class="comment">// if(j==tar) continue;</span></span><br><span class="line"> <span class="comment">// exam = exam ^ hards[j][i];</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> <span class="comment">// hards[tar][i] = exam;</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> <span class="comment">// exists[tar] = true;</span></span><br><span class="line"> <span class="comment">// // printf("DEBUG %d:", tar);</span></span><br><span class="line"> <span class="comment">// // for(int i=0;i<hardsize;i++){</span></span><br><span class="line"> <span class="comment">// // printf("%02X\n",hards[tar][i]);</span></span><br><span class="line"> <span class="comment">// // }</span></span><br><span class="line"> <span class="comment">// // putchar('\n');</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> </span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &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> bidx, sidx;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &bidx);</span><br><span class="line"> sidx = bidx/s;</span><br><span class="line"> <span class="keyword">int</span> boff = bidx%s;</span><br><span class="line"> <span class="keyword">int</span> hidx = gethardnum(sidx);</span><br><span class="line"> <span class="keyword">int</span> kidx = getk(sidx);</span><br><span class="line"> <span class="keyword">int</span> sb = s*<span class="number">4</span>;</span><br><span class="line"> <span class="comment">// printf("bidx:%d sidx:%d hidx:%d kidx:%d boff:%d\n",bidx, sidx, hidx, kidx, boff);</span></span><br><span class="line"> <span class="keyword">if</span>(kidx<hardsize/sb){</span><br><span class="line"> <span class="keyword">if</span>(exists[hidx]){</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">8</span>;j++){</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%c"</span>, hards[hidx][kidx*sb*<span class="number">2</span>+boff*<span class="number">4</span>*<span class="number">2</span>+j]);</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>(l==n<span class="number">-1</span>){</span><br><span class="line"> <span class="keyword">int</span> exam=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> k=<span class="number">0</span>;k<n;k++){</span><br><span class="line"> <span class="keyword">if</span>(k==hidx) <span class="keyword">continue</span>;</span><br><span class="line"> <span class="keyword">int</span> tmp;</span><br><span class="line"> <span class="built_in">sscanf</span>(hards[k]+kidx*sb*<span class="number">2</span>+boff*<span class="number">4</span>*<span class="number">2</span>, <span class="string">"%8X"</span>, &tmp);</span><br><span class="line"> exam = exam ^ tmp;</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"%8X"</span>, exam);</span><br><span class="line"> }<span class="keyword">else</span>{</span><br><span class="line"> <span class="built_in">printf</span>(<span class="string">"-"</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="built_in">printf</span>(<span class="string">"-"</span>);</span><br><span class="line"> }</span><br><span class="line"> <span class="built_in">putchar</span>(<span class="string">'\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><h2 id="201903-4-消息传递接口"><a href="#201903-4-消息传递接口" class="headerlink" title="201903-4 消息传递接口"></a>201903-4 消息传递接口</h2><figure class="highlight cpp"><table><tr><td class="code"><pre><span class="line"><span class="comment">//使用queue队列</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><br><span class="line"><span class="built_in">multiset</span> <<span class="keyword">int</span>> sending,recving;</span><br><span class="line"></span><br><span class="line"></span><br><span class="line"><span class="keyword">char</span> ins[<span class="number">10004</span>][<span class="number">9</span>];</span><br><span class="line"><span class="keyword">int</span> num[<span class="number">10004</span>][<span class="number">9</span>];</span><br><span class="line"><span class="keyword">int</span> icnt[<span class="number">10004</span>];</span><br><span class="line"><span class="keyword">int</span> ans;</span><br><span class="line"><span class="keyword">int</span> T,n;</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>, &T, &n);</span><br><span class="line"> <span class="comment">// printf("n:%d\n", n);</span></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">int</span> t=<span class="number">0</span>;t<T;t++){</span><br><span class="line"> <span class="built_in">memset</span>(ins, <span class="number">0</span>, <span class="keyword">sizeof</span>(ins));</span><br><span class="line"> <span class="built_in">memset</span>(num, <span class="number">0</span>, <span class="keyword">sizeof</span>(num));</span><br><span class="line"> <span class="built_in">memset</span>(icnt, <span class="number">0</span>, <span class="keyword">sizeof</span>(icnt));</span><br><span class="line"> ans = <span class="number">0</span>;</span><br><span class="line"> sending.clear();</span><br><span class="line"> recving.clear();</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">int</span> cnt=<span class="number">0</span>;</span><br><span class="line"> <span class="keyword">bool</span> start = <span class="literal">true</span>;</span><br><span class="line"> <span class="keyword">while</span>(<span class="number">1</span>){</span><br><span class="line"> <span class="keyword">char</span> c = getchar();</span><br><span class="line"> <span class="comment">// printf("%d:%c\n", c, c);</span></span><br><span class="line"> <span class="keyword">if</span>(c == <span class="string">'\n'</span> || c == <span class="number">-1</span>) <span class="keyword">break</span>;</span><br><span class="line"> <span class="keyword">if</span>(c == <span class="string">' '</span>) c = getchar();</span><br><span class="line"> <span class="keyword">int</span> tar;</span><br><span class="line"> <span class="built_in">scanf</span>(<span class="string">"%d"</span>, &tar);</span><br><span class="line"> <span class="comment">// printf("tar:%d\n", tar);</span></span><br><span class="line"> ins[i][cnt] = c; </span><br><span class="line"> num[i][cnt] = tar;</span><br><span class="line"> <span class="keyword">if</span>(start){</span><br><span class="line"> start=<span class="literal">false</span>;</span><br><span class="line"> <span class="keyword">if</span>(c==<span class="string">'S'</span>)</span><br><span class="line"> sending.insert(tar);</span><br><span class="line"> <span class="keyword">else</span></span><br><span class="line"> recving.insert(i);</span><br><span class="line"> }</span><br><span class="line"> cnt++;</span><br><span class="line"> }</span><br><span class="line"> ans+=cnt;</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// printf("ans2:%d\n", ans);</span></span><br><span class="line"> <span class="keyword">while</span>(<span class="number">1</span>){</span><br><span class="line"> <span class="built_in">multiset</span> <<span class="keyword">int</span>> res = <span class="built_in">multiset</span><<span class="keyword">int</span>> ();</span><br><span class="line"> set_intersection(sending.begin(), sending.end(), </span><br><span class="line"> recving.begin(), recving.end(), inserter(res, res.begin()));</span><br><span class="line"> <span class="keyword">if</span>(res.size() == <span class="number">0</span>) <span class="keyword">break</span>;</span><br><span class="line"> <span class="comment">// printf("res:%d\n", res.size());</span></span><br><span class="line"> <span class="keyword">for</span>(<span class="keyword">auto</span> rpos: res){</span><br><span class="line"> <span class="comment">// printf("%d,", rpos);</span></span><br><span class="line"> <span class="keyword">int</span> spos = num[rpos][icnt[rpos]];</span><br><span class="line"> icnt[rpos]++;</span><br><span class="line"> icnt[spos]++;</span><br><span class="line"> sending.erase(sending.find(rpos));</span><br><span class="line"> recving.erase(recving.find(rpos));</span><br><span class="line"> ans-=<span class="number">2</span>;</span><br><span class="line"> <span class="keyword">if</span>(ins[spos][icnt[spos]] == <span class="string">'S'</span>){</span><br><span class="line"> sending.insert(num[spos][icnt[spos]]);</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(ins[spos][icnt[spos]] == <span class="string">'R'</span>){</span><br><span class="line"> recving.insert(spos);</span><br><span class="line"> }</span><br><span class="line"> </span><br><span class="line"> <span class="keyword">if</span>(ins[rpos][icnt[rpos]] == <span class="string">'S'</span>){</span><br><span class="line"> sending.insert(num[rpos][icnt[rpos]]);</span><br><span class="line"> }<span class="keyword">else</span> <span class="keyword">if</span>(ins[rpos][icnt[rpos]] == <span class="string">'R'</span>){</span><br><span class="line"> recving.insert(rpos);</span><br><span class="line"> }</span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// printf("sending:");</span></span><br><span class="line"> <span class="comment">// for(auto it:sending){</span></span><br><span class="line"> <span class="comment">// printf("%d,", it);</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> <span class="comment">// putchar('\n');</span></span><br><span class="line"> <span class="comment">// printf("recving:");</span></span><br><span class="line"> <span class="comment">// for(auto it:recving){</span></span><br><span class="line"> <span class="comment">// printf("%d,", it);</span></span><br><span class="line"> <span class="comment">// }</span></span><br><span class="line"> <span class="comment">// putchar('\n');</span></span><br><span class="line"> }</span><br><span class="line"> <span class="comment">// printf("ans:%d\n", ans);</span></span><br><span class="line"> <span class="keyword">if</span>(ans==<span class="number">0</span>) <span class="built_in">printf</span>(<span class="string">"0\n"</span>);</span><br><span class="line"> <span class="keyword">else</span> <span class="built_in">printf</span>(<span class="string">"1\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><h2 id><a href="#" class="headerlink" title></a><a href="/2019/09/10/csp-intergrated/" title="csp题集汇总">csp题集汇总</a></h2><hr>]]></content>
<categories>
<category> csp </category>
</categories>
<tags>
<tag> csp </tag>
</tags>
</entry>
<entry>
<title>csp 题目汇总</title>
<link href="/2019/09/10/csp-intergrated/"/>
<url>/2019/09/10/csp-intergrated/</url>
<content type="html"><![CDATA[<table><thead><tr><th align="right">编号</th><th>标题</th><th>题解</th><th>分类</th><th>备注</th></tr></thead><tbody><tr><td align="right">201903-1</td><td>小中大</td><td><a href="/2019/09/10/csp-201903/" title="csp-201903">csp-201903</a></td><td>数组水题</td><td></td></tr><tr><td align="right">201903-2</td><td>二十四点</td><td><a href="/2019/09/10/csp-201903/" title="csp-201903">csp-201903</a></td><td>求解四则表达式</td><td></td></tr><tr><td align="right">201903-3</td><td>损坏的RAID5</td><td><a href="/2019/09/10/csp-201903/" title="csp-201903">csp-201903</a></td><td>字符串处理</td><td>字符串读取、数学归纳、16进制字符串异或运算</td></tr><tr><td align="right">201903-4</td><td>消息传递接口</td><td><a href="/2019/09/10/csp-201903/" title="csp-201903">csp-201903</a></td><td>复杂模拟</td><td></td></tr><tr><td align="right">201903-5</td><td>317号子任务</td><td></td><td></td><td></td></tr><tr><td align="right">201812-1</td><td>小明上学</td><td><a href="/2019/09/10/csp-201812/" title="csp-201812">csp-201812</a></td><td>水题</td><td></td></tr><tr><td align="right">201812-2</td><td>小明放学</td><td><a href="/2019/09/10/csp-201812/" title="csp-201812">csp-201812</a></td><td>简单模拟</td><td></td></tr><tr><td align="right">201812-3</td><td>CIDR合并</td><td><a href="/2019/09/10/csp-201812/" title="csp-201812">csp-201812</a></td><td>字符串处理</td><td></td></tr><tr><td align="right">201812-4</td><td>数据中心</td><td><a href="/2019/09/10/csp-201812/" title="csp-201812">csp-201812</a></td><td>图</td><td>最小生成树</td></tr><tr><td align="right">201812-5</td><td>管道清洁</td><td></td><td></td><td></td></tr><tr><td align="right">201809-1</td><td>卖菜</td><td><a href="/2019/09/10/csp-201809/" title="csp-201809">csp-201809</a></td><td>水题</td><td></td></tr><tr><td align="right">201809-2</td><td>买菜</td><td><a href="/2019/09/10/csp-201809/" title="csp-201809">csp-201809</a></td><td>简单模拟、暴力搜索</td><td></td></tr><tr><td align="right">201809-3</td><td>元素选择器</td><td><a href="/2019/09/10/csp-201809/" title="csp-201809">csp-201809</a></td><td>复杂模拟</td><td></td></tr><tr><td align="right">201809-4</td><td>再卖菜</td><td><a href="/2019/09/10/csp-201809/" title="csp-201809">csp-201809</a></td><td></td><td></td></tr><tr><td align="right">201809-5</td><td>线性递推式</td><td><a href="/2019/09/10/csp-201809/" title="csp-201809">csp-201809</a></td><td></td><td></td></tr><tr><td align="right">201803-1</td><td>跳一跳</td><td><a href="/2019/09/10/csp-201803/" title="csp-201803">csp-201803</a></td><td>简单模拟</td><td></td></tr><tr><td align="right">201803-2</td><td>碰撞的小球</td><td><a href="/2019/09/10/csp-201803/" title="csp-201803">csp-201803</a></td><td>中级模拟</td><td></td></tr><tr><td align="right">201803-3</td><td>URL映射</td><td><a href="/2019/09/10/csp-201803/" title="csp-201803">csp-201803</a></td><td>正则表达式</td><td></td></tr><tr><td align="right">201803-4</td><td>棋局评估</td><td><a href="/2019/09/10/csp-201803/" title="csp-201803">csp-201803</a></td><td></td><td></td></tr><tr><td align="right">201803-5</td><td>二次求和</td><td></td><td></td><td></td></tr><tr><td align="right">201712-1</td><td>最小差值</td><td><a href="/2019/09/10/csp-201712/" title="csp-201712">csp-201712</a></td><td>水题</td><td></td></tr><tr><td align="right">201712-2</td><td>游戏</td><td><a href="/2019/09/10/csp-201712/" title="csp-201712">csp-201712</a></td><td>中级模拟</td><td>队列应用</td></tr><tr><td align="right">201712-3</td><td>Crontab</td><td><a href="/2019/09/10/csp-201712/" title="csp-201712">csp-201712</a></td><td>复杂模拟、字符串处理、日期处理</td><td></td></tr><tr><td align="right">201712-4</td><td>行车路线</td><td><a href="/2019/09/10/csp-201712/" title="csp-201712">csp-201712</a></td><td></td><td></td></tr><tr><td align="right">201712-5</td><td>商路</td><td><a href="/2019/09/10/csp-201712/" title="csp-201712">csp-201712</a></td><td></td><td></td></tr><tr><td align="right">201709-1</td><td>打酱油</td><td><a href="/2019/09/10/csp-201709/" title="csp-201709">csp-201709</a></td><td>水题</td><td></td></tr><tr><td align="right">201709-2</td><td>公共钥匙盒</td><td><a href="/2019/09/10/csp-201709/" title="csp-201709">csp-201709</a></td><td>中级模拟</td><td>优先级队列应用</td></tr><tr><td align="right">201709-3</td><td>JSON查询</td><td><a href="/2019/09/10/csp-201709/" title="csp-201709">csp-201709</a></td><td>复杂模拟、正则表达式、字符串处理</td><td></td></tr><tr><td align="right">201709-4</td><td>通信网络</td><td><a href="/2019/09/10/csp-201709/" title="csp-201709">csp-201709</a></td><td>图</td><td>深度优先遍历</td></tr><tr><td align="right">201709-5</td><td>除法</td><td><a href="/2019/09/10/csp-201709/" title="csp-201709">csp-201709</a></td><td></td><td></td></tr><tr><td align="right">201703-1</td><td>分蛋糕</td><td><a href="/2019/09/10/csp-201703/" title="csp-201703">csp-201703</a></td><td>简单模拟</td><td></td></tr><tr><td align="right">201703-2</td><td>学生排队</td><td><a href="/2019/09/10/csp-201703/" title="csp-201703">csp-201703</a></td><td>中级模拟</td><td>list应用</td></tr><tr><td align="right">201703-3</td><td>Markdown</td><td><a href="/2019/09/10/csp-201703/" title="csp-201703">csp-201703</a></td><td>正则表达式</td><td></td></tr><tr><td align="right">201703-4</td><td>地铁修建</td><td><a href="/2019/09/10/csp-201703/" title="csp-201703">csp-201703</a></td><td>图</td><td>最小生成树</td></tr><tr><td align="right">201703-5</td><td>引水入城</td><td><a href="/2019/09/10/csp-201703/" title="csp-201703">csp-201703</a></td><td></td><td></td></tr><tr><td align="right">201612-1</td><td>中间数</td><td><a href="/2019/09/21/csp-201612/" title="csp-201612">csp-201612</a></td><td>水题</td><td></td></tr><tr><td align="right">201612-2</td><td>工资计算</td><td><a href="/2019/09/21/csp-201612/" title="csp-201612">csp-201612</a></td><td>简单模拟</td><td>打表</td></tr><tr><td align="right">201612-3</td><td>权限查询</td><td><a href="/2019/09/21/csp-201612/" title="csp-201612">csp-201612</a></td><td>常用stl</td><td></td></tr><tr><td align="right">201612-4</td><td>压缩编码</td><td><a href="/2019/09/21/csp-201612/" title="csp-201612">csp-201612</a></td><td></td><td></td></tr><tr><td align="right">201612-5</td><td>卡牌游戏</td><td><a href="/2019/09/21/csp-201612/" title="csp-201612">csp-201612</a></td><td></td><td></td></tr><tr><td align="right">201609-1</td><td>最大波动</td><td><a href="/2019/09/21/csp-201609/" title="csp-201609">csp-201609</a></td><td>水题</td><td></td></tr><tr><td align="right">201609-2</td><td>火车购票</td><td><a href="/2019/09/21/csp-201609/" title="csp-201609">csp-201609</a></td><td>简单模拟</td><td></td></tr><tr><td align="right">201609-3</td><td>炉石传说</td><td><a href="/2019/09/21/csp-201609/" title="csp-201609">csp-201609</a></td><td>中级模拟</td><td></td></tr><tr><td align="right">201609-4</td><td>交通规划</td><td><a href="/2019/09/21/csp-201609/" title="csp-201609">csp-201609</a></td><td>图</td><td>最短路径问题</td></tr><tr><td align="right">201609-5</td><td>祭坛</td><td></td><td></td><td></td></tr><tr><td align="right">201604-1</td><td>折点计数</td><td><a href="/2019/09/21/csp-201604/" title="csp-201604">csp-201604</a></td><td>水题</td><td></td></tr><tr><td align="right">201604-2</td><td>俄罗斯方块</td><td><a href="/2019/09/21/csp-201604/" title="csp-201604">csp-201604</a></td><td>中级模拟</td><td></td></tr><tr><td align="right">201604-3</td><td>路径解析</td><td><a href="/2019/09/21/csp-201604/" title="csp-201604">csp-201604</a></td><td>中级模拟</td><td></td></tr><tr><td align="right">201604-4</td><td>游戏</td><td><a href="/2019/09/21/csp-201604/" title="csp-201604">csp-201604</a></td><td>图</td><td>最短路径问题</td></tr><tr><td align="right">201604-5</td><td>网络连接</td><td></td><td></td><td></td></tr><tr><td align="right">201512-1</td><td>数位之和</td><td><a href="/2019/09/21/csp-201512/" title="csp-201512">csp-201512</a></td><td>水题</td><td></td></tr><tr><td align="right">201512-2</td><td>消除类游戏</td><td><a href="/2019/09/21/csp-201512/" title="csp-201512">csp-201512</a></td><td>简单模拟</td><td></td></tr><tr><td align="right">201512-3</td><td>画图</td><td><a href="/2019/09/21/csp-201512/" title="csp-201512">csp-201512</a></td><td>中级模拟</td><td></td></tr><tr><td align="right">201512-4</td><td>送货</td><td><a href="/2019/09/21/csp-201512/" title="csp-201512">csp-201512</a></td><td>图</td><td>欧拉路</td></tr><tr><td align="right">201512-5</td><td>矩阵</td><td><a href="/2019/09/21/csp-201512/" title="csp-201512">csp-201512</a></td><td></td><td></td></tr><tr><td align="right">201509-1</td><td>数列分段</td><td><a href="/2019/09/21/csp-201509/" title="csp-201509">csp-201509</a></td><td>水题</td><td></td></tr><tr><td align="right">201509-2</td><td>日期计算</td><td><a href="/2019/09/21/csp-201509/" title="csp-201509">csp-201509</a></td><td>简单模拟</td><td>打表</td></tr><tr><td align="right">201509-3</td><td>模板生成系统</td><td><a href="/2019/09/21/csp-201509/" title="csp-201509">csp-201509</a></td><td>正则表达式、字符串处理</td><td></td></tr><tr><td align="right">201509-4</td><td>高速公路</td><td><a href="/2019/09/21/csp-201509/" title="csp-201509">csp-201509</a></td><td>图</td><td>强连通分支</td></tr><tr><td align="right">201509-5</td><td>最佳文章</td><td></td><td></td><td></td></tr><tr><td align="right">201503-1</td><td>图像旋转</td><td><a href="/2019/09/13/csp-201503/" title="csp-201503">csp-201503</a></td><td>数组水题</td><td>模拟</td></tr><tr><td align="right">201503-2</td><td>数字排序</td><td><a href="/2019/09/13/csp-201503/" title="csp-201503">csp-201503</a></td><td>常用stl</td><td>排序</td></tr><tr><td align="right">201503-3</td><td>节日</td><td><a href="/2019/09/13/csp-201503/" title="csp-201503">csp-201503</a></td><td>日期处理</td><td>模拟 日期转换</td></tr><tr><td align="right">201503-4</td><td>网络延时</td><td><a href="/2019/09/13/csp-201503/" title="csp-201503">csp-201503</a></td><td>深度优先遍历、动态规划</td><td>树的最长路径(递归解法)</td></tr><tr><td align="right">201503-5</td><td>最小花费</td><td></td><td></td><td></td></tr><tr><td align="right">201412-1</td><td>门禁系统</td><td><a href="/2019/09/13/csp-201412/" title="csp-201412">csp-201412</a></td><td>数组水题</td><td>模拟</td></tr><tr><td align="right">201412-2</td><td>Z字形扫描</td><td><a href="/2019/09/13/csp-201412/" title="csp-201412">csp-201412</a></td><td>中级模拟</td><td>注意边界条件</td></tr><tr><td align="right">201412-3</td><td>集合竞价</td><td><a href="/2019/09/13/csp-201412/" title="csp-201412">csp-201412</a></td><td>stl排序</td><td>分析出枚举买方价</td></tr><tr><td align="right">201412-4</td><td>最优灌溉</td><td><a href="/2019/09/13/csp-201412/" title="csp-201412">csp-201412</a></td><td>图</td><td>最小生成树</td></tr><tr><td align="right">201412-5</td><td>货物调度</td><td></td><td></td><td></td></tr><tr><td align="right">201409-1</td><td>相邻数对</td><td><a href="/2019/09/13/csp-201409/" title="csp-201409">csp-201409</a></td><td>数组水题</td><td>状态机,模拟</td></tr><tr><td align="right">201409-2</td><td>画图</td><td><a href="/2019/09/13/csp-201409/" title="csp-201409">csp-201409</a></td><td>水题</td><td>模拟</td></tr><tr><td align="right">201409-3</td><td>字符串匹配</td><td><a href="/2019/09/13/csp-201409/" title="csp-201409">csp-201409</a></td><td>字符串处理</td><td>变小写 rfind</td></tr><tr><td align="right">201409-4</td><td>最优配餐</td><td><a href="/2019/09/13/csp-201409/" title="csp-201409">csp-201409</a></td><td>图</td><td>最短路 bfs</td></tr><tr><td align="right">201409-5</td><td>拼图</td><td></td><td></td><td></td></tr><tr><td align="right">201403-1</td><td>相反数</td><td><a href="/2019/09/13/csp-201403/" title="csp-201403">csp-201403</a></td><td>数组水题</td><td>模拟</td></tr><tr><td align="right">201403-2</td><td>窗口</td><td><a href="/2019/09/13/csp-201403/" title="csp-201403">csp-201403</a></td><td>中级模拟</td><td>deque/list应用</td></tr><tr><td align="right">201403-3</td><td>命令行选项</td><td><a href="/2019/09/13/csp-201403/" title="csp-201403">csp-201403</a></td><td>字符串处理</td><td>状态机,map应用</td></tr><tr><td align="right">201403-4</td><td>无线网络</td><td><a href="/2019/09/13/csp-201403/" title="csp-201403">csp-201403</a></td><td>图</td><td>bfs + dp</td></tr><tr><td align="right">201403-5</td><td>任务调度</td><td></td><td></td><td></td></tr><tr><td align="right">201312-1</td><td>出现次数最多的数</td><td><a href="/2019/09/13/csp-201312/" title="csp-201312">csp-201312</a></td><td>数组水题</td><td>模拟</td></tr><tr><td align="right">201312-2</td><td>ISBN号码</td><td><a href="/2019/09/13/csp-201312/" title="csp-201312">csp-201312</a></td><td>字符串处理</td><td>模拟</td></tr><tr><td align="right">201312-3</td><td>最大的矩形</td><td><a href="/2019/09/13/csp-201312/" title="csp-201312">csp-201312</a></td><td>动态规划</td><td>动态规划</td></tr><tr><td align="right">201312-4</td><td>有趣的数</td><td><a href="/2019/09/13/csp-201312/" title="csp-201312">csp-201312</a></td><td>动态规划</td><td>排列组合迭代公式</td></tr><tr><td align="right">201312-5</td><td>I’m stuck</td><td><a href="/2019/09/13/csp-201312/" title="csp-201312">csp-201312</a></td><td>DFS</td><td>复杂模拟</td></tr></tbody></table>]]></content>
<categories>
<category> csp </category>
</categories>
<tags>
<tag> csp </tag>
</tags>
</entry>
<entry>
<title><<认知迭代>> 读书笔记</title>
<link href="/2019/09/08/reading-%E8%AE%A4%E7%9F%A5%E8%BF%AD%E4%BB%A3/"/>
<url>/2019/09/08/reading-%E8%AE%A4%E7%9F%A5%E8%BF%AD%E4%BB%A3/</url>
<content type="html"><![CDATA[<h2 id="观感"><a href="#观感" class="headerlink" title="观感"></a>观感</h2><p><<认知迭代>>是一本非常不同的心理书籍,在我读到的书籍中虽然作者都会引用心理学实验来增强其论述观点的合理性,本书中作者亲身去探索和体验了不同的实验,这种感觉非常奇妙。</p><p> 本书作者卡罗琳是一位科学编辑,我将其想象成接近记者一类的工作,需要更多创造力而非逻辑性,从其描述中可以看出,卡罗琳也经历着和我们一样的普通人的焦虑和烦恼,并且拥有一种探索自我的特质,这非常吸引我。</p><p> 尽管现在我仍然对认知领域的实验的科学性保留态度,但我已经接受了一些基本的假设。本书虽然大多数情况都是作者的单人实验,实验没有采取科学的统计和双盲测试,使得这些实验没有科学性而言,但是通过类似经颅磁刺激训练让我了解到了脑的再可塑性,加深了我对于神经科学的理解。卡罗琳的旅途无疑为我对于人的自我探索这一富有挑战的命题添加了更多的科学武器。</p><p> 读书笔记尝试在构建本书脉络的同时记录一些我的想法。</p><p>卡罗琳选择探索了:</p><ol><li>注意力——能够坚持专注于眼前的任务,抵制干扰。</li><li>控制焦虑——想办法减轻压力。</li><li>创造力——学会根据需要产生新的创意。</li><li>导航力——增加我迫切需要的方向感。</li><li>时间感知——想办法享受每一刻,并能够打发无聊时间。</li><li>数字感——尝试获得“数学头脑”,学会逻辑思考。</li></ol><h2 id="读书笔记"><a href="#读书笔记" class="headerlink" title="读书笔记"></a>读书笔记</h2><ol><li><h3 id><a href="#" class="headerlink" title></a><strong></strong></h3></li></ol>]]></content>
<categories>
<category> 读书 </category>
<category> 认知迭代 </category>
</categories>
<tags>
<tag> 读书 </tag>
</tags>
</entry>
<entry>
<title><<认知迭代>> 第一章 读书笔记</title>
<link href="/2019/09/08/reading-%E8%AE%A4%E7%9F%A5%E8%BF%AD%E4%BB%A3-1/"/>
<url>/2019/09/08/reading-%E8%AE%A4%E7%9F%A5%E8%BF%AD%E4%BB%A3-1/</url>
<content type="html"><![CDATA[<h3 id="第一章-注意力陷阱"><a href="#第一章-注意力陷阱" class="headerlink" title="第一章 注意力陷阱"></a>第一章 注意力陷阱</h3><p><em>专注是一切更高能力的根源。 ——李小龙(Bruce Lee)</em></p><hr><h4 id="卡罗琳的注意力烦恼"><a href="#卡罗琳的注意力烦恼" class="headerlink" title="卡罗琳的注意力烦恼"></a><strong>卡罗琳的注意力烦恼</strong></h4><blockquote><p>我把行李落在机场恰恰印证了我有“神游”的倾向,也正因为如此,我从8岁起就被大家戏称为“蝴蝶脑”。如今,类似的事情在我的生活中仍时有发生。最近一次,我在城里的大街上走着,忽然看到一位朋友在马路对面大笑不止,她对我说:“你看上去就像是个疯女人,望着天空,漫无目的地徘徊!”有意思,但她说得没错:在“走神”的时候,我的神志可是真的不知道出走到哪里去了。</p><p>当需要完成工作时,这样的走神并没有给我带来任何好处。我独自在家工作,但却养了一只非常闹人的狗,在我儿子去上学的时候,它总是吵个不停。只在极少数情况下,这样的工作方式才显得非常完美——忙碌一天下来,感觉自己就像女超人一样全能高效。但更普遍的情况是,我一整天都在不同事情之间换来换去,到头来什么有用的事情都没做成——虽然我每天的工作就是读几篇科学论文、发几封电子邮件,但就连这些我都没法顺利完成。忙活了几个小时之后,我压力倍增,也非常沮丧,因为第二天我要完成更多的事情。</p></blockquote><p>卡罗琳从小时候起就注意到了对于自己注意力缺失的病症,并且受此困扰,已经影响到了工作和生活。</p><blockquote><p>那天,我的心情十分沮丧,不停地用头撞着桌子,我突然想到了哈佛大学的神经科学家乔·德古提斯(Joe De Gutis),几年前我在写一篇文章时和他聊过。我知道他的专长是认知训练,特别是专注训练,所以给他发了一封邮件,看他能否帮助我解决问题。他和波士顿大学的麦克·艾斯特曼(Mike Esterman)一直在研究一种计算机辅助训练和脑磁刺激——又叫经颅磁刺激(Transcranial Magnetic Stimulation,简称TMS)——相结合的解决方案,帮助人们更好地集中注意力。到目前为止,他们的方案确实有助于提高专注能力。像大多数的神经科学研究一样,他们只在有着严重问题的人身上进行试验,包括脑损伤、中风、创伤后应激障碍(PTSD)和注意力缺陷多动障碍(ADHD)等患者,我很想知道这种方法对我来说是否有效。</p></blockquote><p>哈佛大学的神经科学家乔·德古提斯和波士顿大学的麦克·艾斯特曼为其尝试了一种非侵入式的计算机辅助训练,经颅磁刺激术。</p><h4 id="整个训练过程如下:"><a href="#整个训练过程如下:" class="headerlink" title="整个训练过程如下:"></a><strong>整个训练过程如下:</strong></h4><ol><li><p>接受测试并且量化注意力。</p><blockquote><p>他们发来了一个链接,让我做一个线上注意力测试,同时发来了几份问卷,用以了解一些基本情况,比如我因为注意力不集中而犯下愚蠢错误的频率(经常)。此外,我还需要填写一个“走神”量表,衡量我发呆时神游的指数(非常高)。</p><p>我做完了所有的测试和问卷,并将结果回复给他们,第二天便在收件箱里得到了残酷的事实——我在注意力测试中的得分率只有51%,比平均水平整整低了20%.</p></blockquote></li><li><p>接受两小时的评估获得技能水平作为测试基准线。</p><blockquote><p>首先进行的是我之前在家做过的在线测试的完整版本——麦克亲切地称之为“<u>别碰贝蒂</u>”(Don’t Touch Betty)。我的任务就是在一连串的男性面孔中找到唯一的女性面孔(贝蒂),每张面孔都会显示约一秒,然后渐渐消失,换成下一张脸。当出现男性面孔时,我需要按下按钮,而贝蒂的脸出现时则不需要按钮。这听起来很容易,但其实不然,因为所有出现的面孔都是黑白的,而且都处于山川、城市等黑白的复杂场景中,在面孔变换的同时,画面的背景也在不断变化着。</p><p>…</p><p>接下来还有几个测试,每一项测试都侧重于注意力的不同方面。在一项叫作“转瞬即逝”的测试中,屏幕上会以最快的速度闪过一串字母,而我则需要辨别出夹杂在这一串字母中的两个数字。这项测试主要针对的是大脑效率,旨在测试我的注意力网络重置已有规律并发现新事物的速度。我猜我的结果应该是“并不快”,因为很多次我报出来的第二个数字基本上是凭空瞎猜。</p><p>最后一项是测试我的视觉专注能力。它主要衡量我有多容易被周边视野中的其他事物分散注意力,比如屏幕上弹出的新邮件通知,或者窗外飞过的一只小鸟。我觉得自己的表现还可以,但却有点疲倦,我坐在桌前,将脸埋在双手中。那时已经是傍晚了,或许我躺下来进行半个小时的脑部扫描是个不错的主意——即使是躺在嘈杂的核磁共振成像扫描仪中。</p></blockquote></li><li><p>进行脑部扫描,绘制出想要刺激的大脑区域。</p><blockquote><p>扫描的目的不是要追踪我的大脑活动,而是要获取我的大脑的3D图像,以此来确定涉及注意力的脑区,便于使用经颅磁刺激机器。他们主要感兴趣的区域叫作“背侧注意网络”(dorsal attention network),它负责将眼睛后侧的思维区域与顶叶皮层(parietal cortex)相连。顶叶皮层位于耳朵上部偏后,相当于各种感官的交换总机。<br>虽然大脑两侧都有类似的系统,但实时成像研究表明,在普通人中,右脑的那一部分承担了主要的工作。相反,有注意力集中障碍的人通常在效率较低的左脑有着更多的活动。</p></blockquote></li><li><p>使用经颅磁刺激仪暂时麻痹注意网络中的左侧的活动,使测试者不得不使用右侧网络活动。</p><blockquote><p>后来麦克和乔告诉我,他们的计划是用经颅磁刺激机器暂时麻痹我注意网络中左侧的活动,让我不得不使用右侧的注意网络。这样做类似于绑住我经常使用的那只手,迫使我用另一只手。然而,由于大脑总会通过最简单的路径传递信息,一旦更有效率的系统开始正常运行,日后它将有望随时为我所用。</p><p>…</p><p>我们来到了有着巨大椅子的房间,看到了我的大脑活灵活现地出现在屏幕上。虽然不知道我之前的期待是怎样,但我的大脑看起来相当正常,所有该凸起的地方都有凸起,也没有什么不应该出现的明显的洞。麦克将一张背侧注意网络的图片叠在我的大脑图像上,在“额叶眼动区”(frontal eye field)标记了记号——这就是他准备进行刺激的区域。</p><p>我本以为他们会刺激我的大脑,从而让它更好地运作,但实际上恰恰相反:他们用针对性磁脉冲麻痹我左侧注意网络的部分活动,以迫使我使用右侧注意网络——也就是正常情况下本该使用的那一侧。磁刺激的影响几分钟后就会消失,因此我需要在被刺激之后立刻进行训练,之后再将这个过程重复进行两次。</p></blockquote></li><li><p>在大脑刺激之后立即做认知训练,每天两次,每次完成三组长达12分钟的训练。</p><blockquote><p>计划的另一部分则是训练——乔在这方面十分擅长。我需要完成三组长达12分钟的训练,每天两次,持续一周,此外,在大脑刺激后的两天里,还有额外的训练。</p><p>说实话,虽然这些训练可能对我有帮助,但它们实在是太无聊了。就像“别碰贝蒂”测试一样,屏幕上会出现目标图像——比如棕色桌子上的白色杯子,见到这个图像时就不能按钮,但出现其他颜色的杯子或桌子时则可以按钮。第一次尝试,在所有不许按钮的图像中,我的正确率只有11%。虽然没有什么基准可以比较,但这个分数看起来挺糟糕的。后来他们告诉我,需要将测试调整到我能答对50%的水平,只有这样,他们才有可能提高我的能力。这显然还有很多工作要做,尤其是在这么短的时间里——四天后,我就要飞回英国了。但现在我能做的只有睡觉。</p></blockquote></li></ol><h4 id="训练的结果如下:"><a href="#训练的结果如下:" class="headerlink" title="训练的结果如下:"></a><strong>训练的结果如下:</strong></h4><blockquote><p>电磁刺激之后,我紧接着进行了乔的训练。但我们很快就发现,无论是否受过刺激,经过休息恢复后,训练结果仍然令人沮丧。我可以看到自己的手缓慢地移向空格键,但就是没法阻止它按下去。<br>经过第一次刺激之后,我在测试中的表现甚至更糟糕了,我也能看出来麦克有些不安。他没有多说什么,但似乎希望我在经过短暂的刺激之后,能够表现得好一些。但乔说,可能是因为我平时太依赖左侧的网络,所以在它被麻痹后根本无法完成任务。如果是这样的话,那么通过训练我应该能逐渐改善这个现状。<br>然而事实并非如此,到了第三天,我还是没有丝毫进步。我沮丧极了,每次错按空格时,我都想大声叫出来。我觉得自己很蠢——事实上,我几乎一眼就能轻松地辨认出目标,但似乎就算拿枪指着我,我也没法控制自己不去按空格键。麦克和乔看起来比我还要沮丧,也有些担心。乔后来承认,他担心我回家之后会在书里评价他的训练是“最愚蠢的事”。</p><p>但是在第三天训练间歇的某个时刻,事情突然发生了转变。我的“不按按钮”正确率从11%和30%一下提高到了50%-70%。更令人惊奇的是,我开始享受这项测试起来。当不小心犯错的时候,我能感觉到自己的思绪去了哪里——这是一种非常陌生的感觉。比如,我意识到有一次按错键是因为我在想儿子正在家里干什么。又比如,我会想训练结束后是喝红酒还是啤酒。又过了一天,我已经可以单手完成测试,另一只手则随意地拿着茶杯。更重要的是,之前我的脑海里只有白噪音,我根本无法知道自己的思想在做什么,而现在我能感到如禅定般的平静,只有少数一些令我分心的波动。</p><p>乔对此似乎很兴奋,他告诉我这可能是一个重大进步。在心理学中,<strong>知道自己的想法被称作“元意识”,而如果你需要发现自己神游,以阻止自己的思维别飘走太远,元意识十分重要。</strong>他说:“受过该项训练帮助的人都会进入这样一个阶段,他们发现自己比以前更具有元意识,他们会在完成任务的时候看到自己在想着其他的事。”</p><p>虽然这可能只是我的想象,但我感觉平静了许多。通常,我会在工作的时候拖延,结果弄得自己在本该放松的时间仍然在工作,并且十分焦虑。但这一个星期,我就好像是一名新闻忍者:在指定的时间里完成了所有的工作,然后与我在波士顿的好友们好好叙旧,共度美好时光,享受着回归我最喜爱的城市生活,完全没有因工作未完成而产生压力和愧疚。这听起来也许没什么,但对我来说,这是一个启示——原来生活可以不用充满压力。<br>我还注意到了一些工作之外的微妙变化。在波士顿的第二天,我搬离酒店,到朋友家度过这周剩下的几天。这件事本来会让我回到原来的状态——即使是在亲朋好友家做客,我也会感到十分焦虑。我无法放松,因为我总觉得自己碍人家的事,应该更多地帮忙做饭和打扫卫生,或者更好地跟他们聊天。然后我又担心自己的焦虑会给所有人带来压力。但是,这周我并不是这样,一切都是那么美好。</p><p>…</p><p>这些训练与刺激真的对我的大脑起到作用了吗?简单来说,似乎是的。在“别碰贝蒂”测试中,我的得分表现有了大幅飞跃,错误率从训练前的53%(比他们测试的所有健康的人都要糟糕),降到了训练之后的9.6%(几乎赶上了这项研究中健康人的最高水平)。</p></blockquote><p><img src="/1567946666609.png" alt></p><h4 id="结果的解释:"><a href="#结果的解释:" class="headerlink" title="结果的解释:"></a><strong>结果的解释:</strong></h4><blockquote><p>但是,有没有可能只是因为我能更好地控制自己的手部动作,从而阻止了自己按下按键呢?毕竟,训练的内容跟最终的“别碰贝蒂”测试十分相似。我把这个想法告诉了乔,但他告诉我,根据他们基于此训练的其他研究,<u>单凭反复练习只能获得4%的提升</u>,而我的进步幅度相当于这个数字的十几倍。除此之外,在“转瞬即逝”的测试中——测试大脑在分心后多久可以重新专注——我的准确度也有相应的提升,从训练前的46%提高到了87%。“这是巨大的进步。”乔说。“转瞬即逝”测试不仅不需要按按键,而且它并不是像“别碰贝蒂”测试那样单凭反复练习就能提升的测试。</p><p>好吧,看来训练的结果是真的,那么他们究竟对我做了什么?在短短一周的时间里,通过四个小时无聊且简单的大脑训练和刺激,我的大脑真的发生了改变吗?<br>“<u>生理结构并没有什么变化</u>,”麦克和乔不约而同地说,他们试图让我摆脱“他们已经重塑了我的大脑回路”的想法,麦克说,“<u>但从功能上看,你运用大脑的方式发生了变化。</u>”这意味着,虽然我可能并没有得到新的大脑回路,但现有的回路可能会更加高效地运作。</p><p>从某种程度来说,这更令人兴奋,因为这意味着,<u>你不需要对大脑做出巨大的结构调整,就可以从根本上改变它的运作方式</u>——更重要的是,改变你体验生活的方式。只需要在正确的方向上稍作努力,一切就都会有所变化。<br>但这也意味着,我们无法准确地指出我的大脑究竟发生了什么变化,因为我们在训练过程中并没有对大脑进行扫描,而且没有进行训练前后的核磁共振成像扫描对比。这并不是因为他们忘记这么做了,而是因为<u>核磁共振成像只能提供脑部的大致图像,在短短几天的训练之后,大脑各处的连接所发生的变化非常微小,不可能在图像中体现出来</u>。因此,我们只能从其他研究以及他们早前让我进行的心理测试结果进行推断。科学通常都是这样:把全新的结果与已经存在的知识体系进行比较,从而推断出造成此结果的可能原因。</p><p>乔的测试中所体现的变化,以及我个人所感受到的变化,归根结底是因为这项训练的设计原理。训练内容首要是无聊的——唯有如此,它才会消耗你的注意力。在一项试点研究中,另一组研究人员试图让训练内容对儿童而言更加有趣,但这样也失去了无聊训练所具备的种种优点。乔告诉我,无聊的事会调动我们的“强力关注”——我们可以将其描述为一种持续的“就绪”状态,让你一直关注着目标何时会出现。而不可预测的目标则会利用到“阶段性关注”,或者说间歇的警觉波动。对于捕获目标图像来说,头脑的最佳状态是你通过“强力关注”持续留意,同时能在目标出现时足够警觉地做出反应。<br>换言之,你必须让自己进入“状态”:在这个难以捉摸的点上,一切感觉都不是很难,但同时具有一定的挑战性。也正因为如此,麦克和乔之前才会一直试图将测试调整到50%的正确率,并以此作为训练的基准:这就是每个人的“状态”,一旦进入状态,就可以慢慢提高难度,逐渐提高技能。他们花了很长时间来寻找我最合适的状态,当他们在第三天终于找到它时,我便根据这一基础,让它成为在我需要大脑保持专注时可以达到的状态。</p></blockquote><h4 id="尝试找到神经学证据"><a href="#尝试找到神经学证据" class="headerlink" title="尝试找到神经学证据"></a><strong>尝试找到神经学证据</strong></h4><blockquote><p>显然,现在我似乎已经可以达到这个状态,但这一“状态”究竟是什么?多年来,神经科学家一直试图回答这个问题,他们或成功,或失败。但麦克认为,在这样的状态下,背侧注意网络和另一个被称作“默认模式网络”(default mode network)的大脑回路之间达到了完美平衡。当我们进行创意思考、走神或者什么都不想时,激活的便是默认模式网络。<br>波士顿团队在最近的一系列实验中发现,当走神活动达到最高水平时,人们会更有可能在“别碰贝蒂”测试中犯错;而当注意力网络活动增加时,这一现象便会得到改善。不过,注意力网络过于活跃也会适得其反:两个网络不管哪一边的活动过多,都会导致人不能长时间专注于眼前的任务。</p></blockquote><hr><h4 id="有意思的语录"><a href="#有意思的语录" class="headerlink" title="有意思的语录"></a>有意思的语录</h4><blockquote><p>我这几天新体验到的冷静状态几乎不可能持续,除非我采取措施让它得到保持。显然,成年人的大脑训练就有这样的缺点。就像锻炼身体一样,你必须一直坚持,否则身体就会变得和从前一样松弛。</p></blockquote><blockquote><p>也许我一直为自己是怀疑论者而感到骄傲。我愿意相信一切说法都是垃圾,并在此基础上质疑任何事物,直到确定自己没有被蛊惑为止。</p></blockquote><blockquote><p>正念冥想改变了默认模式(走神)网络与执行控制网络的连接方式,起到了与乔的训练类似的作用——或者说,如果长期坚持,一定会有效果。</p></blockquote>]]></content>
<categories>
<category> 读书 </category>
<category> 认知迭代 </category>
</categories>
<tags>
<tag> 读书 </tag>
</tags>
</entry>
<entry>
<title>linux命令学习笔记1 使用命令帮助</title>
<link href="/2019/07/21/linux-command-tutorial1/"/>
<url>/2019/07/21/linux-command-tutorial1/</url>
<content type="html"><![CDATA[<h1 id="Linux-命令学习笔记"><a href="#Linux-命令学习笔记" class="headerlink" title="Linux 命令学习笔记"></a>Linux 命令学习笔记</h1><p>对linux命令的熟悉是操作linux系统的基础中的基础。<br>作为刚开始上手linux的新手,对基本命令应该谙熟于心,使<br>用的时候才能高效地使用。</p><h1 id="第一章-学会使用命令帮助"><a href="#第一章-学会使用命令帮助" class="headerlink" title="第一章 学会使用命令帮助"></a>第一章 学会使用命令帮助</h1><h2 id="1-1-回忆命令"><a href="#1-1-回忆命令" class="headerlink" title="1.1 回忆命令"></a>1.1 回忆命令</h2><p>在linux终端,面对命令不知道怎么用,或者不记得命令的拼写及参数时,我们需要求助于系统的帮助文档;<br>linux系统内置的帮助文档很详细,通常能解决我们的问题,我们需要掌握如何正确的去使用它们。</p><ul><li><p>只记得部分命令的场合,我们可以用 man -k 来搜索(-k keyword),搜索的结果</p><pre><code>$ man -k printf0dprintf (3) - formatted output conversionfprintf (3) - formatted output conversion...</code></pre></li><li><p>需要知道某个命令的简要说明可以使用whatis(非常方便):</p><pre><code>$ whatis aptapt (8) - command-line interface</code></pre></li></ul><ol><li><strong>whatis能显示出命令所在的 *文档类别*(在下面man命令中介绍)并给出它们简要的描述</strong></li></ol><ul><li>如果只记得命令的部分,可以用正则匹配的办法搜索:<pre><code>$ whatis -w "loca*"locale (1) - get locale-specific informationlocale (5) - describes a locale definition filelocale (7) - description of multilanguage supportlocale-gen (8) - generates localisation files from template...</code></pre></li></ul><hr><ul><li>如果想要知道命令的具体参数和使用方法,我们需要用到强大的man<pre><code>$ man dateDATE(1)NAMEdate - print or set the system date and timeSYNOPSISdate [OPTION]... [+FORMAT]date [-u|--utc|--universal] [MMDDhhmm[[CC]YY][.ss]]DESCRIPTION...</code></pre></li></ul><ol><li><strong>使用f,b上下翻页;j,k 上下移动一行。;使用q退出帮助手册。</strong></li><li><strong>man的帮助手册中,将帮助文档分为了9个类别,有的关键字存在多个类别中,我们就需要制定特定的类别来查看;(一般我们查询bash命令,归类在第一类中。</strong><blockquote><p>(1)、用户可以操作的命令或者是可执行文件<br> (2)、系统核心可调用的函数与工具等<br> (3)、一些常用的函数与数据库<br> (4)、设备文件的说明<br> (5)、设置文件或者某些文件的格式<br> (6)、游戏<br> (7)、惯例与协议等。例如Linux标准文件系统、网络协议、ASCⅡ,码等说明内容<br> (8)、系统管理员可用的管理条令<br> (9)、与内核有关的文件</p></blockquote></li></ol><hr><ul><li>而更详细的介绍,则可使用info命令<pre><code>info apt...</code></pre></li></ul><hr><h2 id="1-2-简要查看路径"><a href="#1-2-简要查看路径" class="headerlink" title="1.2 简要查看路径"></a>1.2 简要查看路径</h2><ul><li><p>查看程序的binary文件所在路径</p><pre><code>$ which make/usr/bin/make</code></pre></li><li><p>查看程序的搜索路径:</p><pre><code>$ whereis pythonpython: /usr/bin/python3.5 /usr/bin/python3.5-config /usr/bin/python3.5m /usr/bin/python2.7 /usr/bin/python2.7-config /usr/bin/python /usr/bin/python3.5m-config /usr/lib/python3.5 /usr/lib/python3.6 /usr/lib/python2.7 /etc/python3.5 /etc/python /etc/python2.7 /usr/local/lib/python3.5 /usr/local/lib/python2.7 /usr/include/python3.5 /usr/include/python3.5m /usr/include/python2.7 /usr/share/python /usr/share/man/man1/python.1.gz</code></pre></li><li><p>总结</p><pre><code>whatis info man which whereis</code></pre></li></ul>]]></content>
<categories>
<category> linux </category>
<category> command </category>
</categories>
<tags>
<tag> linux </tag>
<tag> ubuntu </tag>
</tags>
</entry>
<entry>
<title>linux命令学习笔记3 文本处理</title>
<link href="/2017/04/29/linux-command-tutorial3/"/>
<url>/2017/04/29/linux-command-tutorial3/</url>
<content type="html"><![CDATA[<h1 id="第三章-文本处理"><a href="#第三章-文本处理" class="headerlink" title="第三章 文本处理"></a>第三章 文本处理</h1><p><strong>本节介绍linux下使用Shell处理文本时最常用的工具: find, grep, xargs, sort, uniq, tr, cut, paste, wc, sed, awk;提供的例子和参数都是常用的;我对shell脚本使用的原则是命令单行书写,尽量不要超过2行;如果有更为复杂的任务需求,还是考虑使用python吧。(逃)</strong></p><h2 id="3-1-find-文件查找"><a href="#3-1-find-文件查找" class="headerlink" title="3.1 find 文件查找"></a>3.1 find 文件查找</h2><ul><li>find的格式<pre><code>find [path...] [expression]expression = [Options] [Tests] [Actions]组成find会查找path下的每一个文件,将其带入expression运算的出真值,值为真则执行指定的动作,否则则不执行。</code></pre></li><li>find的主要选项<pre><code>$ find . -name pattern //将路径前面的目录名去掉后做匹配$ find . -path pattern//保留路径名做匹配$ find . -mmin n//对文件数据的修改是在n分钟之前的文件$ find . -mtime n//对文件数据的修改是在n*24小时之前的文件$ find . -perm mode文件的权限位恰好是mode$ find . -regex pattern//对整个路径名做正则匹配$ find . -type c//文件是c类型的 类型主要有(d 目录| f 普通文件| l 符号链接)</code></pre></li><li>组合应用<pre><code>//找出当前目录下的.txt或者.pdf后缀形式的文件并输出文件大小(利用-printf参数你甚至可以自己写一个ls命令)$ find .\( -name "*.txt" -o -name "*.pdf" \) -printf '%f\t%k\n'//正则方式查找.txt和.pdf(要注意转义符号的应用)$ find . -regex ".*\(\.txt\|\.pdf\)$"// 否定参数,查找锁哟非txt文本:$ find . ! -name "*.txt" -print// 忽略大小写的查找,可查找test.c和Test.c$ find . -iname "test.c"指定搜索深度,打印出当前目录的文件(深度为1)$ find . maxdepth 1 -type f</code></pre></li><li>定制搜索<pre><code>//按类型搜索,只列出所有目录$ find . -type d//按时间搜索,一天前访问过的的文件$ find . -atime 1//最近7天访问过的所有文件$ find . -atime -7 type f -print//按文件大小搜索$ find . -type f -size +2k//查找具有可执行权限的所有文件$ find . -type f -perm 644 -print//查找用户lsz所拥有的文件$ find . -type f -user weber -print</code></pre></li><li>对匹配到的文件做后续处理<pre><code>//删除当前目录下所有的swap文件$ find . -type f -name "*.swap" -delete//另一种语法$ find . -type f -name "*.swap" | xargs rm//使用强大的-exec将当前目录下的所有权变更为lsz({}会将匹配到的文件替换掉)$ find . -type f -user root -exec chown lsz {} \;//将找到的文件copy到另一个目录$ find . -type f -mtime +10 -name "*.txt" -exec cp {} OLD \;//如果需要后续执行多个命令,可以将多个命令写成一个脚本。然后-exec执行脚本即可$ find . -type f -mtime +10 -name "*.txt" -exec ./commands.sh {} ;//默认使用’\n‘为文件的定界符</code></pre></li></ul><hr><h2 id="3-2-grep-文本搜索"><a href="#3-2-grep-文本搜索" class="headerlink" title="3.2 grep 文本搜索"></a>3.2 grep 文本搜索</h2><ul><li><p>简述<br> Linux系统中grep命令是一种强大的文本搜索工具,它能使用正则表达式搜索文本,并把匹 配的行打印出来。grep全称是Global Regular Expression Print,表示全局正则表达式版本,它的使用权限是所有用户。使用grep对于?, +, |, {, (, )需要用\转义,而egrep可直接使用。</p></li><li><p>使用格式</p><pre><code>grep [options] PATTERN [FILE]</code></pre></li><li><p>主要选项</p><pre><code>-c:只输出匹配行的计数。-I:不区分大 小写(只适用于单字符)。-h:查询多文件时不显示文件名。-l:查询多文件时只输出包含匹配字符的文件名。-n:显示匹配行及 行号。-s:不显示不存在或无匹配文本的错误信息。-v:显示不包含匹配文本的所有行。pattern正则表达式主要参数:\: 忽略正则表达式中特殊字符的原有含义。^:匹配正则表达式的开始行。$: 匹配正则表达式的结束行。\<:从匹配正则表达 式的行开始。\>:到匹配正则表达式的行结束。[ ]:单个字符,如[A]即A符合要求 。[ - ]:范围,如[A-Z],即A、B、C一直到Z都符合要求 。。:所有的单个字符。* :有字符,长度可以为0。</code></pre></li><li><p>使用简单实例</p><pre><code>//以test开头的所有文件为搜索范围,匹配’python‘字符$ egrep 'python' test*//在多级目录中对文本递归搜索$ grep "class" . -R -n//匹配多个模式$ grep -e 'class' -e 'vitural; file//显示至少包含5个连续小写字母的行$ egrep '[a-z]{5,}' test//如果west被匹配,则es就被存储到内存中,并标记为1,然后搜索任意个字符(.*),这些字符后面紧跟着 另外一个es(\1),找到就显示该行。如果用egrep或grep -E,就不用”\”号进行转义,直接写成’w(es)t.*\1′就可以了。$ egrep 'w(es)t.*\1' file</code></pre></li><li><p>使用复杂实例</p><pre><code>//假设您正在’/usr/src/Linux/Doc’目录下搜索带字符 串’magic’的文件//需要递归查找所有的文件$ egrep -r magic './'//只查找当前目录,并且转到less阅读$ egrep -d skip magic ./* | less'//将日志中的带有所有where条件的sql查找出来$ cat LOG.* | tr a-z A-Z|grep "FROM" | grep "WHERE" > b//中文查找示例,如果要查找的文字是’中文‘查找到他的utf-8编码和gb2312编码分别是 E4B8ADE69687和D6D0CEC4$ grep -P '\xE4\xB8\xAD\xE6\x96\x87|\xD6\xD0\CE\xC4' ./*</code></pre></li><li><p>下面还有一些有意思的命令行参数:</p><pre><code>grep -i pattern files :不区分大小写地搜索。默认情况区分大小写,grep -l pattern files :只列出匹配的文件名,grep -L pattern files :列出不匹配的文件名,grep -w pattern files :只匹配整个单词,而不是字符串的一部分(如匹配’magic’,而不是’magical’),grep -C number pattern files :匹配的上下文分别显示[number]行,grep pattern1 | pattern2 files :显示匹配 pattern1 或 pattern2 的行,grep pattern1 files | grep pattern2 :显示既匹配 pattern1 又匹配 pattern2 的行。grep -n pattern files 即可显示行号信息grep -c pattern files 即可查找总行数</code></pre></li><li><p>这里还有些用于搜索的特殊符号:</p><pre><code>\< 和 \> 分别标注单词的开始与结尾。例如:grep man * 会匹配 ‘Batman’、’manic’、’man’等,grep ‘\<man’ * 匹配’manic’和’man’,但不是’Batman’,grep ‘\<man\>’ 只匹配’man’,而不是’Batman’或’manic’等其他的字符串。‘^’:指匹配的字符串在行首,‘$’:指匹配的字符串在行 尾,</code></pre></li></ul><hr><h2 id="3-3-xargs命令行参数转换"><a href="#3-3-xargs命令行参数转换" class="headerlink" title="3.3 xargs命令行参数转换"></a>3.3 xargs命令行参数转换</h2><ul><li>简述<br> xargs命令是给其他命令传递参数的一个过滤器,也是组合多个命令的一个工具。它擅长将标准输入数据转换成命令行参数,xargs能够处理管道或者stdin并将其转换成特定命令的命令参数。xargs也可以将单行或多行文本输入转换为其他格式,例如多行变单行,单行变多行。xargs的默认命令是echo,空格是默认定界符。这意味着通过管道传递给xargs的输入将会包含换行和空白,不过通过xargs的处理,换行和空白将被空格取代。xargs是构建单行*命令的重要组件之一。</li><li>用法<pre><code>xargs [options] [command]</code></pre></li><li>重要选项<pre><code>-d 定义定界符-n 指定输出为多行-I {} 指定替换字符串, 这个字符串会在xargs拓展时被替换掉,用于待执行命令需要多个参数时-0 指定null(0)为输入定界符,与find的print0可串联使用</code></pre></li><li>简单实例<pre><code>//将多行输出转化为单行输出$ cat file.txt | xargs //将单行转化为多行 以每行3个字段显示$ cat file.txt | xargs -n 3//统计程序行数$ cat file.txt | xargs -I {} ./command.sh -p {} -1//计算所有的文件的行数(有些相当与python里面的map)$ find ./ -name '*test[AB].c' | sort| xargs -I {} wc -l {}</code></pre></li></ul><hr><h2 id="3-4-sort排序"><a href="#3-4-sort排序" class="headerlink" title="3.4 sort排序"></a>3.4 sort排序</h2><ul><li>简述<br> sort命令是在Linux里非常有用,它将文件进行排序,并将排序结果标准输出。sort命令既可以从特定的文件,也可以从stdin中获取输入。</li><li>语法<pre><code>sort [Option]... [File]...</code></pre></li><li>重要选项<br> -b:忽略每行前面开始出的空格字符;<br> -c:检查文件是否已经按照顺序排序;<br> -d:排序时,处理英文字母、数字及空格字符外,忽略其他的字符;<br> -f:排序时,将小写字母视为大写字母;<br> -i:排序时,除了040至176之间的ASCII字符外,忽略其他的字符;<br> -m:将几个排序号的文件进行合并;<br> -M:将前面3个字母依照月份的缩写进行排序;<br> -n:依照数值的大小排序;<br> -o<输出文件>:将排序后的结果存入制定的文件;<br> -r:以相反的顺序来排序;<br> -t<分隔字符>:指定排序时所用的栏位分隔字符;<br> +<起始栏位>-<结束栏位>:以指定的栏位来排序,范围由起始栏位到结束栏位的前一栏位。</li><li>简单实例<pre><code>cat sort.txt ;printf '*********\n'; sort sort.txtaaa:10:1.1ccc:30:3.3ddd:40:4.4bbb:20:2.2eee:50:5.5eee:50:5.5*********aaa:10:1.1bbb:20:2.2ccc:30:3.3ddd:40:4.4eee:50:5.5eee:50:5.5//忽略相同行$ cat -u sort.txtaaa:10:1.1bbb:20:2.2ccc:30:3.3ddd:40:4.4eee:50:5.5//使用 -n -r -k -t$ cat sort.txtAAA:BB:CCaaa:30:1.6ccc:50:3.3ddd:20:4.2bbb:10:2.5eee:40:5.4eee:60:5.1// 按字符串数值比较大小(ASCII码)$ sort sort.txt -n// 按照BB列的数字大小排序$ sort -nrk 2 -t: sort.txteee:60:5.1ccc:50:3.3eee:40:5.4aaa:30:1.6ddd:20:4.2bbb:10:2.5AAA:BB:CC</code></pre></li><li>-k 复杂用法实例<br> -k选项的语法格式:<br> FStart.CStart<br> Modifie,FEnd.CEnd Modifier<br> ——-Start——–,——-End——–<br> FStart.CStart 选项 , FEnd.CEnd<br> 选项<br> 这个语法格式可以被其中的逗号,分为两大部分,Start部分和End部分。Start部分也由三部分组成,其中的Modifier部分就是我们之前说过的类似n和r的选项部分。我们重点说说Start部分的FStart和C.Start。C.Start也是可以省略的,省略的话就表示从本域的开头部分开始。FStart.CStart,其中FStart就是表示使用的域,而CStart则表示在FStart域中从第几个字符开始算“排序首字符”。同理,在End部分中,你可以设定FEnd.CEnd,如果你省略.CEnd,则表示结尾到“域尾”,即本域的最后一个字符。或者,如果你将CEnd设定为0(零),也是表示结尾到“域尾”。<br> 从公司英文名称的第二个字母开始进行排序:<pre><code>$ sort -t -k 1.2 facebook.txtbaidu 100 5000sohu 100 4500google 110 5000guge 50 3000</code></pre> 使用了-k 1.2,表示对第一个域的第二个字符开始到本域的最后一个字符为止的字符串进行排序。你会发现baidu因为第二个字母是a而名列榜首。sohu和 google第二个字符都是o,但sohu的h在google的o前面,所以两者分别排在第二和第三。guge只能屈居第四了。<br> 只针对公司英文名称的第二个字母进行排序,如果相同的按照员工工资进行降序排序:<pre><code>$ sort -t -k 1.2,1.2 -nrk 3,3 facebook.txtbaidu 100 5000google 110 5000sohu 100 4500guge 50 3000</code></pre> 由于只对第二个字母进行排序,所以我们使用了-k 1.2,1.2的表示方式,表示我们“只”对第二个字母进行排序。(如果你问“我使用-k 1.2怎么不行?”,当然不行,因为你省略了End部分,这就意味着你将对从第二个字母起到本域最后一个字符为止的字符串进行排序)。对于员工工资进行排序,我们也使用了-k 3,3,这是最准确的表述,表示我们“只”对本域进行排序,因为如果你省略了后面的3,就变成了我们“对第3个域开始到最后一个域位置的内容进行排序”了。</li></ul><hr><h2 id="3-5-uniq消除重复行"><a href="#3-5-uniq消除重复行" class="headerlink" title="3.5 uniq消除重复行"></a>3.5 uniq消除重复行</h2><ul><li>简述<br> 文本中的重复行,基本上不是我们所要的,所以就要去除掉。linux下有其他命令可以去除重复行,但是我觉得uniq还是比较方便的一个。使用uniq的时候要注意以下二点<br> 1,对文本操作时,它一般会和sort命令进行组合使用,因为uniq 不会检查重复的行,除非它们是相邻的行。如果您想先对输入排序,使用sort -u。<br> 2,对文本操作时,若域中为先空字符(通常包括空格以及制表符),然后非空字符,域中字符前的空字符将被跳过</li><li>语法<pre><code>uniq [Option] [Input[Output]]</code></pre></li><li>主要参数<pre><code>-c, --count //在每行前加上表示相应行目出现次数的前缀编号-d, --repeated //只输出重复的行-D, --all-repeated //只输出重复的行,不过有几行输出几行-f, --skip-fields=N //-f 忽略的段数,-f 1 忽略第一段-i, --ignore-case //不区分大小写-s, --skip-chars=N //根-f有点像,不过-s是忽略,后面多少个字符 -s 5就忽略后面5个字符-u, --unique //去除重复的后,全部显示出来,根mysql的distinct功能上有点像-z, --zero-terminated end lines with 0 byte, not newline-w, --check-chars=N //对每行第N 个字符以后的内容不作对照--help //显示此帮助信息并退出--version //显示版本信息并退出</code></pre></li><li>主要用法<pre><code>//统计各行在文件中出现的次数 sort unsort.txt | uniq -c//找出重复行sort unsort.txt | uniq -d</code></pre></li></ul><hr><h2 id="3-6-用tr进行转换"><a href="#3-6-用tr进行转换" class="headerlink" title="3.6 用tr进行转换"></a>3.6 用tr进行转换</h2><ul><li>简述<br> tr用来从标准输入中通过替换或删除操作进行字符转换。tr主要用于删除文件中控制字符或进行字符转换。使用tr时要转换两个字符串:字符串1用于查询,字符串2用于处理各种转换。tr刚执行时,字符串1中的字符被映射到字符串2中的字符,然后转换操作开始。</li><li>用法<pre><code>tr [Option]... SET1 [SET2]//tr -c -d -s ["string1_to_translate_from"]["string2_to_translate_to"] < input-file</code></pre></li><li>主要选项<pre><code>-c 用字符串1中字符集的补集替换此字符集,要求字符集为ASCII。-d 删除字符串1中所有输入字符。-s 删除所有重复出现字符序列,只保留第一个;即将重复出现字符串压缩为一个字符串。</code></pre></li><li>字符范围<pre><code>指定字符串1或字符串2的内容时,只能使用单字符或字符串范围或列表。[a-z] a-z内的字符组成的字符串。[A-Z] A-Z内的字符组成的字符串。[0-9] 数字串。\octal 一个三位的八进制数,对应有效的ASCII字符。[O*n] 表示字符O重复出现指定次数n。因此[O*2]匹配OO的字符串。tr中特定控制字符的不同表达方式速记符含义八进制方式\a Ctrl-G 铃声\007\b Ctrl-H 退格符\010\f Ctrl-L 走行换页\014\n Ctrl-J 新行\012\r Ctrl-M 回车\015\t Ctrl-I tab键\011\v Ctrl-X \030</code></pre></li><li>应用实例<pre><code>//将文件file中的出现的'a' 'b' 'c'换为'x' 'y' 'z'$ cat file | tr 'abc' 'xyz' > new_file//使用tr命令统一大小写$ cat file | tr [a-z] [A-Z] > file$ cat file | tr [A-Z] [a-z] > file //删除文件中的snail字符【注意】这里,凡是在file文件中出现的'S','n','a','i','l'字符都会被删除!而不是紧紧删除出现的"Snail”字符串。$ cat file | tr -d 'snail' > file //删除文件file中出现的换行'\n'、制表'\t'字符$ cat file | tr -d "\n\t" > newfile//删除“连续着的”重复字母,只保留第一个$ cat file | tr -s [a-z][A-Z] > newfile 删除空行$ cat file | tr -s "\n" > new_file//删除Windows文件“造成”的'^M'字符$ cat file | tr -d "\r" > new_file$ cat file | tr -s "\r" "\n" > new_file</code></pre></li></ul><hr><h2 id="3-7-cut按行切分文本"><a href="#3-7-cut按行切分文本" class="headerlink" title="3.7 cut按行切分文本"></a>3.7 cut按行切分文本</h2><ul><li>简述<br> cut是一个选取命令,就是将一段数据经过分析,取出我们想要的。一般来说,选取信息通常是针对“行”来进行分析的,并不是整篇信息分析的。在 每个文件FILE的各列中,把提取的片断显示在标准输出.</li><li>用法<pre><code>cut [Option]... [File]...</code></pre></li><li>主要参数<pre><code>-b, --bytes=LIST 输出 这些 字节, 以字节定位-c, --characters=LIST 输出 这些 字符, 以字符定位-d, --delimiter=DELIM 使用 DELIM 取代 TAB 做 字段(field) 分隔符-f, --fields=LIST 输出 这些 字段, 以字段定位-s, --only-delimited 不显示 没有 分隔符 的 行--output-delimiter=STRING 使用 STRING 作为 输出分隔符, 缺省 (的 输出分隔符) 为 输入分隔符LIST:N 第 N 个 字节, 字符 或 字段, 从 1 计数 起N- 从 第 N 个 字节, 字符 或 字段 直至 行尾N-M 从 第 N 到 第 M (并包括 第M) 个 字节, 字符 或 字段-M 从 第 1 到 第 M (并包括 第M) 个 字节, 字符 或 字段如果 没有 指定 文件 FILE, 或 FILE 是 -, 就从 标准输入 读取 数据.</code></pre></li><li>简单用法<pre><code>//截取who命令的第1-3个字节和第8个字节$ who | cut -b 1-3,8//提取每列的第1,3,9-15,个字符$ who | cut -c 1,3,9-15//对于非标准形式排列的文件,我们可以人为规定字段做切割//比如以冒号做切割得到文件的第1,3列$ cut -d ':' -f 1,3 /etc/password//显示文件除了第3列之外的所有列$ cut -f 3 --complement filename</code></pre></li></ul><hr><h2 id="3-8-paste-按列拼接文本"><a href="#3-8-paste-按列拼接文本" class="headerlink" title="3.8 paste 按列拼接文本"></a>3.8 paste 按列拼接文本</h2><ul><li>简述<br> 连续 依次 从 各个 文件 FILE 中 读取 一列 然后 合并成 新列, 中间 用 TAB 隔开, 新行 写到 标准输出. 如果 文件 FILE 不存在, 或者 FILE 是 ‘-‘, 就从 标准输入 读取 数据.</li><li>用法<pre><code>paste [Option].. [File]...</code></pre></li><li>主要参数<pre><code>-d, --delimiters=LIST 循环使用 LIST 中 的 字符 取代 TAB -s, --serial 一次 粘贴 一个 文件, 而不是 并行 粘贴</code></pre></li><li>简单实例<pre><code>//将file1和file2用逗号连接在一起$ paste file1 file2 -d ','//串行粘贴$ paste file1 file2 -s</code></pre></li></ul><hr><h2 id="3-9-wc-统计行的字符的工具"><a href="#3-9-wc-统计行的字符的工具" class="headerlink" title="3.9 wc 统计行的字符的工具"></a>3.9 wc 统计行的字符的工具</h2><ul><li>简述<br> 对每个文件输出行、单词、和字节统计数,如果指定了多于一个文件则还有一 个行数的总计。没有指定文件或指定的文件是 -,则读取标准输入。</li><li>用法<pre><code>wc [Option]... [File]...</code></pre></li><li>主要参数<pre><code>-c, --bytes, --chars 输出字节统计数。-l, --lines 输出换行符统计数。-L, --max-line-length 输出最长的行的长度。-w, --words 输出单词统计数。</code></pre></li><li>简单实例<pre><code>//统计行数$ wc -l file//统计单词数$ wc -w file//统计字符数$ wc -c file</code></pre></li></ul><hr><h2 id="3-10-sed文本替换利器"><a href="#3-10-sed文本替换利器" class="headerlink" title="3.10 sed文本替换利器"></a>3.10 sed文本替换利器</h2><ul><li><p>简述<br> sed 是一种文件流编辑器,它一次处理一行内容。处理时,把当前处理的行存储在临时缓冲区中,称为“模式空间”(pattern space),接着用sed命令处理缓冲区中的内容,处理完成后,把缓冲区的内容送往屏幕。接着处理下一行,这样不断重复,直到文件末尾。文件内容并没有 改变,除非你使用重定向存储输出。Sed主要用来自动编辑一个或多个文件;简化对文件的反复操作;编写转换程序等。</p></li><li><p>用法</p><pre><code>sed [OPTION]... {script-only-if-no-other-script} [input-file]...</code></pre></li><li><p>主要参数</p><pre><code>-n :使用安静(silent)模式。在一般 sed 的用法中,所有来自 STDIN 的数据一般都会被列出到终端上。但如果加上 -n 参数后,则只有经过sed 特殊处理的那一行(或者动作)才会被列出来。-e :直接在命令列模式上进行 sed 的动作编辑;-f :直接将 sed 的动作写在一个文件内, -f filename 则可以运行 filename 内的 sed 动作;-r :sed 的动作支持的是延伸型正规表示法的语法。(默认是基础正规表示法语法)-i :直接修改读取的文件内容,而不是输出到终端。动作说明: [n1[,n2]]functionn1, n2 :不见得会存在,一般代表『选择进行动作的行数』,举例来说,如果我的动作是需要在 10 到 20 行之间进行的,则『 10,20[动作行为] 』function:a :新增, a 的后面可以接字串,而这些字串会在新的一行出现(目前的下一行)~c :取代, c 的后面可以接字串,这些字串可以取代 n1,n2 之间的行!d :删除,因为是删除啊,所以 d 后面通常不接任何咚咚;i :插入, i 的后面可以接字串,而这些字串会在新的一行出现(目前的上一行);p :列印,亦即将某个选择的数据印出。通常 p 会与参数 sed -n 一起运行~s :取代,可以直接进行取代的工作哩!通常这个 s 的动作可以搭配正规表示法!例如 1,20s/old/new/g 就是啦!</code></pre></li><li><p>简单实例</p><pre><code>//将 /etc/passwd 的内容列出并且列印行号,同时,请将第 2~5 行删除!$ nl /etc/passwd | sed '2,5d'//在第2行后添加hello world$ nl /etc/passwd | sed '2a hellow world'//在第2行前添加hello world$ nl /etc/passwd | sed '2i hellow world' //将第2-5行替换为hello world$ nl /etc/passwd | sed '2,5c hellow world'// 仅列出2-7行$ nl /etc/passwd | sed -n '2,7p'//搜索/etc/passwd有root关键字的行,使用-n只打印包含模板的行$ nl -n /etc/passwd | sed '/root/p'//删除/etc/passwd所有包含root的行$ nl /etc/passwd | sed '/root/d'//数据的搜寻并执行命令nl /etc/passwd | sed -n '/root/{s/bash/blueshell/;p}'//如果只替换/etc/passwd的第一个bash关键字为blueshell,就退出$ nl /etc/passwd | sed -n '/bash/{s/bash/blueshell/;p;q}'//移除空白行$ sed '/^$/d' file//第一个匹配的括号内容使用标记1来引用$ nl /etc/passwd | sed -n 's/hello\([0-9]\)/\1'//使用双引号求职 $ sed 's/$var/HLLOE/'//字符串插入字符/,将文本中的每行内容(ABCDEF)转换为ABC/DEF$ sed 's/^.\{3\}/&\//g' file</code></pre></li></ul><hr><h2 id="3-11-awk数据流处理工具"><a href="#3-11-awk数据流处理工具" class="headerlink" title="3.11 awk数据流处理工具"></a>3.11 awk数据流处理工具</h2><ul><li>简介<br> awk是一个强大的文本分析工具,相对于grep的查找,sed的编辑,awk在其对数据分析并生成报告时,显得尤为强大。简单来说awk就是把文件逐行的读入,以空格为默认分隔符将每行切片,切开的部分再进行各种分析处理。</li><li>用法<br> mawk [-W option] [-F value] [-v var=value] [–] ‘program text’ [file …]<br> mawk [-W option] [-F value] [-v var=value] [-f program-file] [–] [file …]</li></ul><p>$$<br> \begin{matrix}<br> 1 & 2 & 3 \<br> 4 & 5 & 6 \<br> 7 & 8 & 9<br> \end{matrix} \tag{1}<br>$$</p>]]></content>
<categories>
<category> linux </category>
<category> command </category>
</categories>
<tags>
<tag> linux </tag>
<tag> ubuntu </tag>
</tags>
</entry>
<entry>
<title>linux命令学习笔记2 文件及目录管理</title>
<link href="/2017/04/27/linux-command-tutorial2/"/>
<url>/2017/04/27/linux-command-tutorial2/</url>
<content type="html"><![CDATA[<h1 id="第二章-文件及目录管理"><a href="#第二章-文件及目录管理" class="headerlink" title="第二章 文件及目录管理"></a>第二章 文件及目录管理</h1><h2 id="2-0-概述"><a href="#2-0-概述" class="headerlink" title="2.0 概述"></a>2.0 概述</h2><p>文件管理不外乎文件或目录的创建,删除,查询,移动。有<code>mkdir/rm/mv</code>。<br>文件查询是重点,用<code>find</code>来进行查询;<code>find</code>参数丰富,非常强大。<br>查看文件内容是个大的话题,文本的处理有很多工具供我们使用。在本章中只是点到即止。<br>有时候我们需要给文件备份,或者创建一个别名,我们需要用到<code>ln</code>。</p><h2 id="2-1-创建和删除"><a href="#2-1-创建和删除" class="headerlink" title="2.1 创建和删除"></a>2.1 创建和删除</h2><ul><li>目录的创建<pre><code>$ mkdir dir</code></pre></li><li>目录的删除(只能删除空目录)<pre><code>$ rmdir dir</code></pre></li><li>删除非空目录(如果去掉f参数每个删除都会提示y/n)<pre><code>$ rm -rf file 目录</code></pre></li><li>删除日志<pre><code>$ rm *log(等价: $ find ./ -name "*log" -exec rm {} \;)</code></pre></li><li>移动或重命名<pre><code>$ mv source_dir dest_dir</code></pre></li><li>复制<pre><code>$ cp -r source_dir dest_dir</code></pre></li></ul><h2 id="2-2-目录切换"><a href="#2-2-目录切换" class="headerlink" title="2.2 目录切换"></a>2.2 目录切换</h2><ul><li>切换目录<pre><code>$ cd destination</code></pre></li><li>切换到上一个工作目录<pre><code>$ cd -</code></pre></li><li>切换到home目录<pre><code>$ cd or cd ~</code></pre></li><li>显示当前路径<pre><code>$ pwd</code></pre></li><li>更改当前工作路径为 path<pre><code>cd path</code></pre></li></ul><h2 id="2-3-列出目录项"><a href="#2-3-列出目录项" class="headerlink" title="2.3 列出目录项"></a>2.3 列出目录项</h2><ul><li>显示当前目录下的文件<pre><code>$ ls</code></pre></li><li>按时间排序,以列表的方式显示目录项<pre><code>$ ls -lrt</code></pre></li><li>显示索引,显示全部文件,以列表显示,以文件大小排序<pre><code>$ ls -sail</code></pre></li></ul><blockquote><p>在.bashrc中设置命令别名<br>alias lsl=’ls -lrt’<br>alisa lm=’ls -a|more’<br>这样使用lsl,就可以显示按照修改时间排序,以列表显示<br>给每项文件前面增加一个id编号<br>ls | cat -n</p></blockquote><h2 id="2-4-查找目录及文件"><a href="#2-4-查找目录及文件" class="headerlink" title="2.4 查找目录及文件"></a>2.4 查找目录及文件</h2><ul><li>在此我们将使用强大的<code>find</code>命令和<code>locate</code>命令</li><li>搜寻文件或目录(xargs 命令解释文件)<pre><code>$ find ./ -name "python*" | xargs file</code></pre></li><li>注意到 <code>-name</code> 参数后面可跟一个正则表达式字符串。<pre><code>$ find ./ -name "task[12345].c"</code></pre></li><li>配合 <code>-exec</code> 参数产生强大的效果,比如删除所有c文件<pre><code>$ find ./ -name "*.c" -exec rm {} \;</code></pre></li><li>find是实时查找,如果需要更快的查询,可以试试<code>locate</code><pre><code>$ locate python</code></pre></li><li>locate会为文件系统建立索引数据库,如果有文件更新,需要定期执行更新命令来更新索引库<pre><code>$updatedb</code></pre></li></ul><h2 id="2-5-查看文件内容"><a href="#2-5-查看文件内容" class="headerlink" title="2.5 查看文件内容"></a>2.5 查看文件内容</h2><ul><li>查看文件命令: cat vi head tail more</li><li>显示时同时显示行号<pre><code>$ cat -n</code></pre></li><li>按页显示列表内容<pre><code>$ ls -al| more</code></pre></li><li>只看前10行<pre><code>$ head -10 file</code></pre></li><li>显示文件的第一行<pre><code>$ head -1 file</code></pre></li><li>显示文件倒数第五行<pre><code>$ tail -5 file</code></pre></li><li>查看两个文件之间的区别<pre><code>$ diff file1 file2</code></pre></li><li>动态显示文本最新信息<pre><code>$ tail -f file.log</code></pre></li></ul><h2 id="2-6-查找文件内容"><a href="#2-6-查找文件内容" class="headerlink" title="2.6 查找文件内容"></a>2.6 查找文件内容</h2><ul><li>使用<code>egrep</code>查询文件内容<pre><code>$ egrep 'expression' file</code></pre></li></ul><p>2.7 文件于目录权限修改</p><ul><li>改变文件的拥有者 chown<pre><code>$ sudo chown user file</code></pre></li><li>改变文件读,写,执行等属性 <pre><code>$ chmod +rwx file</code></pre></li><li>递归子目录修改<pre><code>$ chmod -R dir/</code></pre></li><li>增加脚本可执行权限<pre><code>$ chmod a+x script</code></pre></li></ul><h2 id="2-8-给文件增加别名"><a href="#2-8-给文件增加别名" class="headerlink" title="2.8 给文件增加别名"></a>2.8 给文件增加别名</h2><ul><li>创建硬链接,硬链接保存了指向源文件的位置和信息也保存了源文件的数据,引用硬链接相当于引用源文件<pre><code>$ cp -l source link$ ln source link</code></pre></li><li>创建软链接,软链接只保存了源文件的位置和信息<pre><code>$ cp -s source link $ link -s source link</code></pre></li></ul><h2 id="2-9-管道和重定向"><a href="#2-9-管道和重定向" class="headerlink" title="2.9 管道和重定向"></a>2.9 管道和重定向</h2><ul><li>批处理命令连接执行,使用|,下一个命令的参数是上一个命令的返回结果<pre><code>$ cat file | grep "python"</code></pre></li><li>串联使用命令:使用分号<pre><code>$ ls ; cd</code></pre></li><li>如果前面执行的命令成功,则执行后面一条,否则则不执行<pre><code>$ cmd1 && cmd2</code></pre></li><li>前面成功则执行命令1,失败则执行命令2<pre><code>$ cmd && cmd1 || cmd 2</code></pre></li></ul><hr><ul><li><p>重定向</p><blockquote><p>有时候你想要把一个命令的输出信息保存在一个文件里而不是在显示器上显示它,你就会用到重定向。重定向可以把一个文件用到某个命令的输出上,也可以用在输出上。</p></blockquote><pre><code>$ cmd > outputfile$ date > output.log</code></pre></li><li><p>清空文件</p><pre><code>$ > file</code></pre></li><li><p>如果要在文件后面追加内容而不删除原来的内容,可以使用</p><pre><code>$ cmd >> file</code></pre></li></ul><hr><ul><li><p>输入重定向</p><blockquote><p>输入重定向将文件的内容定向到命令。</p></blockquote><pre><code>$ cmd < inputfile$ wc < inputfile</code></pre><blockquote><p>wc 命令提供了对文本中的行数次数和字节数的计数</p></blockquote></li><li><p>内联输入重定向</p><blockquote><p>你会在命令行中输入数据直到输入EOF这个制定的关键字</p></blockquote><pre><code>$ wc << EOF</code></pre></li></ul><h2 id="2-10-设置环境变量"><a href="#2-10-设置环境变量" class="headerlink" title="2.10 设置环境变量"></a>2.10 设置环境变量</h2><blockquote><p>启动帐号后自动执行的文件是<code>.profile</code>,通过这个文件可以设置自己的环境变量<br>安装的软件路径一般都要加入到path中</p></blockquote><h2 id="2-11-bash快捷输入或删除"><a href="#2-11-bash快捷输入或删除" class="headerlink" title="2.11 bash快捷输入或删除"></a>2.11 bash快捷输入或删除</h2><blockquote><p>快捷键Ctl-U 删除光标到行首的所有字符,在某些设置下,删除全行<br>Ctl-W 删除当前光标到前边的最近一个空格之间的字符<br>Ctl-H backspace,删除光标前边的字符<br>Ctl-R 匹配最相近的一个文件,然后输<br>Ctl-U 删除光标到行首的所有字符,在某些设置下,删除全行</p></blockquote><pre><code>综合应用:查找record.log中包含AAA,但不包含BBB的记录的总数cat -v revord.log|grep AAA|grep -v BBB|wc -l</code></pre>]]></content>
<categories>
<category> linux </category>
<category> command </category>
</categories>
<tags>
<tag> linux </tag>
<tag> ubuntu </tag>
</tags>
</entry>
</search>