-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.xml
3325 lines (3116 loc) · 404 KB
/
index.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
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom">
<channel>
<title>洛舒luosuu的小站</title>
<link>https://luosuu.github.io/</link>
<description>Recent content on 洛舒luosuu的小站</description>
<generator>Hugo -- gohugo.io</generator>
<language>zh-cn</language>
<copyright>Copyright © 2020</copyright>
<lastBuildDate>Wed, 07 Oct 2020 14:46:45 +0800</lastBuildDate>
<atom:link href="https://luosuu.github.io/index.xml" rel="self" type="application/rss+xml" />
<item>
<title>Use Git to Collaborate</title>
<link>https://luosuu.github.io/post/use-git-to-collaborate/</link>
<pubDate>Wed, 07 Oct 2020 14:46:45 +0800</pubDate>
<guid>https://luosuu.github.io/post/use-git-to-collaborate/</guid>
<description><p>在项目开发的过程中,合作是必不可少的,许多开发人员会同时开发一个项目,这意味着他们需要一个合适的方法来帮助他们协作,Git就是世界上最常用的版本控制软件,Github是世界上最大的代码托管平台。你会在下面的Microsoft Learn路径了解版本控制的必要性,与git和GitHub的基础使用方法,并顺便学会Markdown这一非常常用的标记语言工具。</p>
<p>俱乐部有一些新生也可以积极参与的项目,学习git和GitHub是参与其中的必要一步。</p>
<p><strong>Tips</strong>:Git与GitHub只是一种工具,你可以边参与开发边学习如何使用它,就像你从未系统学习过如何使用Microsoft Word,每次你需要使用到它的一些功能时你都会现查现学,本质是需要用起来学。不过跟随Microsoft Learn的路径进行互动式学习先了解一下也不失为一种好方法。</p>
<h2 id="了解并使用git">了解并使用Git</h2>
<p>有关版本控制与 Git 结合使用的简介</p>
<p><a href="https://docs.microsoft.com/zh-cn/learn/paths/intro-to-vc-git/">https://docs.microsoft.com/zh-cn/learn/paths/intro-to-vc-git/</a></p>
<p>Git 是领先的版本控制工具,对开发人员至关重要。 了解如何利用 Git 跟踪自己的更改并与他人协作。</p>
<h2 id="markdown与github-pages">Markdown与Github pages</h2>
<p>使用 Markdown 和 GitHub Pages 与他人协作</p>
<p><a href="https://docs.microsoft.com/zh-cn/learn/paths/collaborate-markdown-github-pages/">https://docs.microsoft.com/zh-cn/learn/paths/collaborate-markdown-github-pages/</a></p>
<p>了解如何使用 Markdown 就 GitHub 问题、拉取请求、评论和文档有效地与他人协作。 然后,学习如何使用 GitHub Pages 构建项目网站和博客文章来推广你的项目。</p>
<p>在此学习路径下,你将学习如何:</p>
<ul>
<li>使用 Markdown 通过代码、图像、列表和表格来整理你的想法。</li>
<li>使用 GitHub 风格的 Markdown (GFM) 来突出显示常用编程语言的语法并关联找到问题、拉取请求和提交内容。</li>
<li>使用 GitHub Pages 创建包含自定义主题的项目页面和博客文章。</li>
</ul>
<p><strong>Tips</strong>:你需要注册一个GitHub账户</p>
<h2 id="源代码管理">源代码管理</h2>
<p>在GitHub的使用过程中,一个核心的步骤是合并代码并解决冲突。</p>
<p>在 GitHub 上使用合并冲突解决来解决竞争提交</p>
<p><a href="https://docs.microsoft.com/zh-cn/learn/modules/resolve-merge-conflicts-github/">https://docs.microsoft.com/zh-cn/learn/modules/resolve-merge-conflicts-github/</a></p>
<p>了解如何使用合并冲突解决来解决分支中的重叠提交。</p>
<p>学习目标
在本模块中,你将学习以下内容:</p>
<ul>
<li>了解合并的发生方式以及导致合并冲突的原因</li>
<li>轻松解决简单和复杂的合并冲突</li>
<li>与团队共享最佳做法以减少合并冲突</li>
</ul>
<h2 id="实践一下">实践一下</h2>
<p>访问俱乐部组织下的名字为“2020-mebmers”的仓库,fork并clone到本地,按照提示修改内容,然后提交pull request。</p>
<p><a href="https://github.com/uestc-msc/2020-members">https://github.com/uestc-msc/2020-members</a></p>
<p>可以私聊我然后拉你进GitHub的俱乐部组织。</p>
<h2 id="github自动化">Github自动化</h2>
<p><em>这个部分并不是必要的,但自动工作流是一个很强大的工具,可以省去很多重复性的工作,如果你在GitHub pages上发布自己的博客,那么学习GitHub Actions可以让你每次更新博客时少一些本地操作的步骤</em></p>
<p>使用 GitHub Actions 自动执行工作流</p>
<p><a href="https://docs.microsoft.com/zh-cn/learn/paths/automate-workflow-github-actions/">https://docs.microsoft.com/zh-cn/learn/paths/automate-workflow-github-actions/</a></p>
<p>在此学习路径下,你将:</p>
<ul>
<li>GitHub Actions 工作流将软件开发生命周期自动化。</li>
<li>使用 GitHub Actions 自动构建应用程序。</li>
<li>使用 GitHub Actions 实现到 Microsoft Azure 的部署。</li>
<li>使用 GitHub 脚本与 GitHub API 交互。</li>
</ul>
<p>Tips:部署到Azure的相关部分可以不看</p>
<h2 id="其他资料">其他资料</h2>
<p>实际上Github官网有QuickStart教程</p>
<p><a href="https://docs.github.com/en/free-pro-team@latest/github/getting-started-with-github/quickstart">https://docs.github.com/en/free-pro-team@latest/github/getting-started-with-github/quickstart</a></p>
<p>也有Git教程</p>
<p><a href="https://docs.github.com/en/free-pro-team@latest/github/using-git">https://docs.github.com/en/free-pro-team@latest/github/using-git</a></p>
<p>GitHub pages教程</p>
<p><a href="https://docs.github.com/en/free-pro-team@latest/github/working-with-github-pages">https://docs.github.com/en/free-pro-team@latest/github/working-with-github-pages</a></p>
<p>在仓库中管理文件</p>
<p><a href="https://docs.github.com/en/free-pro-team@latest/github/managing-files-in-a-repository">https://docs.github.com/en/free-pro-team@latest/github/managing-files-in-a-repository</a></p>
</description>
</item>
<item>
<title>Microsoft Learn Python Path</title>
<link>https://luosuu.github.io/post/microsoft-learn-python-path/</link>
<pubDate>Sat, 03 Oct 2020 23:10:38 +0800</pubDate>
<guid>https://luosuu.github.io/post/microsoft-learn-python-path/</guid>
<description><p>这里是成电微软学生俱乐部2020年度Python学习Guideline,将主要通过利用Microsoft Learn这个交互式引导学习平台,引导俱乐部新生入门并学习使用Python,甚至掌握一些基础的人工智能及数据科学的概念。</p>
<p>我们希望你最终能够自己通过python编程实现一些有趣的小功能,并在2020年12月下旬的俱乐部年会做一些集中的展示,我们为你们的每一步都设置了奖励,如果你在年会上展示你自己编写的程序,我们会给你丰厚的奖励(无论你哪个年级,在年会上展示自己的程序都会获得奖励)。</p>
<p>在学习过程中的任何问题,随时都十分欢迎在俱乐部大群里讨论交流。</p>
<h2 id="入门python编程">入门Python编程</h2>
<p>使用Python迈出第一步</p>
<p><a href="https://docs.microsoft.com/zh-cn/learn/paths/python-first-steps/?WT.mc_id=learntv-video-learn">https://docs.microsoft.com/zh-cn/learn/paths/python-first-steps/?WT.mc_id=learntv-video-learn</a></p>
<p>想学习编程语言,但不知从何处着手? 从此处开始! 了解使用 Python 构建简单应用程序所需的基本语法和预期过程。</p>
<p>在此学习路径下,你将:</p>
<ul>
<li>编写第一批 Python 代码</li>
<li>存储和操作数据以修改其类型和外观</li>
<li>执行代码库中提供的内置功能</li>
<li>向代码添加逻辑以实现复杂的业务功能</li>
<li>完成此学习路径后,你将为后续的 Python 学习路径提供坚实的基础。</li>
</ul>
<p>建议完成时间:2020/10/08 前</p>
<h2 id="了解python如何发挥作用">了解Python如何发挥作用</h2>
<p>了解 Python 在太空探索中扮演的角色</p>
<p><a href="https://docs.microsoft.com/zh-cn/learn/paths/introduction-python-space-exploration-nasa/">https://docs.microsoft.com/zh-cn/learn/paths/introduction-python-space-exploration-nasa/</a></p>
<p>此学习路径介绍了 Python 的世界。 但目标不是学习 Python,而是了解 Python 如何在 NASA 创建的创新型解决方案中发挥作用。 该学习路径通过太空探索镜头来激发持之以恒地学习、探索和创建的热情,让你有一天也能帮助我们所有人更多地了解一点外太空。</p>
<p>通过这些模板,你将:</p>
<ul>
<li>了解和安装学习编程所需的工具</li>
<li>了解核心编程概念并在实际的 NASA 问题中运用它们</li>
<li>了解机器学习和人工智能等领先技术</li>
<li>观看真实的 NASA 员工谈论他们的工作并给出建议</li>
</ul>
<p>建议完成时间:2020/10/16 前</p>
<h2 id="开始了解面向数据的python">开始了解面向数据的Python</h2>
<p>使用 Python 和人工智能对太空岩石进行分类</p>
<p><a href="https://docs.microsoft.com/zh-cn/learn/paths/classify-space-rocks-artificial-intelligence-nasa/">https://docs.microsoft.com/zh-cn/learn/paths/classify-space-rocks-artificial-intelligence-nasa/</a></p>
<p>通过此学习路径,你可了解 AI 和太空的世界。 了解如何创建可对随机照片中的太空岩石的类型进行分类的 AI 模型。</p>
<p>建议完成时间:2020/11/XX/</p>
<p><strong>Tips</strong>:从这里开始你将学习一些实际的操作,但你可能现在还不太了解面向数据的Python等,我们计划你们开始这部分的学习时做一期Python相关的沙龙,来帮助你们更好的学习后续的内容。不过我们不会讨论Python的一些基础语法,因为这些你都可以在网上轻松的学习到,我们主要会讨论Python的一些常见的小问题,如Python的包管理器(pip和anaconda)并交流你们在学习Python的时候遇到的一些问题,然后在沙龙上我们会带领大家自己通过编写Python来画一个词云(WordCloud)。</p>
<p>有关词云,可以自己先了解同济子豪兄的教程:</p>
<p><a href="https://zhuanlan.zhihu.com/p/66931750">https://zhuanlan.zhihu.com/p/66931750</a></p>
<p>同济的张子豪同学是同济大学微软学生俱乐部的优秀成员,如今已经是一个分享了非常多技术干货的技术网红。</p>
<p>他的很多文章都很有价值,且有很多新手入门向的教程。他的知乎专栏地址如下:</p>
<p><a href="https://www.zhihu.com/people/zhang-zi-hao-64-2/posts?page=1">https://www.zhihu.com/people/zhang-zi-hao-64-2/posts?page=1</a></p>
<p>对人工智能原理感兴趣的同学可以阅读他专栏下的<a href="https://zhuanlan.zhihu.com/p/49184702">“大白话讲解卷积神经网络工作原理”</a></p>
<p>他对于如何安装和配置Python也有新手向的教程:https://zhuanlan.zhihu.com/p/58790338</p>
<h3 id="关于人工智能的相关概念的入门">关于人工智能的相关概念的入门</h3>
<p>Azure上的人工智能入门</p>
<p><a href="https://docs.microsoft.com/zh-cn/learn/paths/get-started-with-artificial-intelligence-on-azure/">https://docs.microsoft.com/zh-cn/learn/paths/get-started-with-artificial-intelligence-on-azure/</a></p>
<p><strong>Tips</strong>:你可以只了解人工智能的相关概念,比如什么是机器学习,什么是计算机视觉,什么是自然语言处理等等。但如果条件允许,你也可以通过路径里的链接快速自己尝试一下相关的功能,里面有一些demo展示。</p>
<p><em>注意路径里的链接里多了个中文句号,访问的时候把这个句号删掉就可以了,否则你可能会得到一个空白页或404 Not Found</em>。</p>
<h3 id="关于数据科学的入门">关于数据科学的入门</h3>
<p>数据科学基础知识</p>
<p><a href="https://docs.microsoft.com/zh-cn/learn/paths/foundations-data-science/">https://docs.microsoft.com/zh-cn/learn/paths/foundations-data-science/</a></p>
<p>加州大学伯克利分校的数据科学基础课程将三个方面结合在了一起:推理思维、计算思维和实际相关性。 假设数据来自某种实际现象,如何分析该数据才能了解该现象? 本课程教授计算机编程和统计推理的重要概念和技能,并结合对实际数据集的动手分析,其中包括经济数据、文档集合、地理数据和社交网络。 该课程会深入研究有关数据分析的社交问题,例如隐私和设计。</p>
<p>与加州大学伯克利分校联合制作 - Ani Adhikari 和 John Denero,同时还有 David Wagner 参与编写<a href="https://www.inferentialthinking.com/chapters/intro.html">计算思维和推理思维</a>。</p>
<p><strong>Tips</strong>:这是一个较为系统讲解如何学习数据科学的相关基础概念、方法以及使用Python实操的路径,内容较多,但也配备了完整的教材。学习完这个路径后你会掌握一些基础但非常实用的Python数据处理的能力,并建立数据科学的概念。</p>
<h2 id="使用python做一些机器学习">使用Python做一些机器学习</h2>
<p>通过机器学习预测火箭发射延迟</p>
<p><a href="https://docs.microsoft.com/zh-cn/learn/paths/machine-learning-predict-launch-delay-nasa/">https://docs.microsoft.com/zh-cn/learn/paths/machine-learning-predict-launch-delay-nasa/</a></p>
<p>此学习路径介绍了机器学习的世界。 你将应对 NASA 面临的实际问题并应用机器学习来解决它。 学习目标是调动学生的积极性和好奇心,使其去发现机器学习可如何帮助解决太空探索及生活其他方面的其他问题。</p>
</description>
</item>
<item>
<title>AtABC173D-环上的贪心</title>
<link>https://luosuu.github.io/post/atabc173d/</link>
<pubDate>Sat, 08 Aug 2020 22:49:34 +0800</pubDate>
<guid>https://luosuu.github.io/post/atabc173d/</guid>
<description><p>题面:https://atcoder.jp/contests/abc173/tasks/abc173_d</p>
<p>为了让每个值最大效用化,我们肯定是从大到小的插入,所以首先我们需要对输入的友好值序列排序。</p>
<p>在插入值的过程中,为了让某个较大的值物尽其用,肯定是在它的顺时针方向旁边插一个,逆时针方向插一个,由于新插入的值肯定小于等于它,所以每个插入的值最多被感受两次友好值。事实上,除了第一个插入的数,都可以被感受两次达到物尽其用。都可以顺时针方向邻接插一个,逆时针方向邻接插一个。</p>
<p>对于长度为n的友好值序列,会插值n次,也就是感受值序列也是长度为n。</p>
<p>对于友好值序列</p>
<pre><code>5 4 3 2 1
</code></pre><p>它的感受值序列为</p>
<pre><code>0 5 4 4 3
</code></pre><p>那么我们只需要特殊处理第1个和第2个感受值,剩下的在n长度范围内将友好值第二高开始都计算两次,直到计算总次数达到n(包含特殊处理的第一次和第二次)。</p>
<p>以下是C++代码</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-C++" data-lang="C++"><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;iostream&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e">#include</span> <span style="color:#75715e">&#34;algorithm&#34;</span><span style="color:#75715e">
</span><span style="color:#75715e"></span><span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;
<span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {
<span style="color:#66d9ef">int</span> N;
cin <span style="color:#f92672">&gt;&gt;</span> N;
<span style="color:#66d9ef">long</span> <span style="color:#66d9ef">long</span> <span style="color:#66d9ef">int</span> A[N];
<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i <span style="color:#f92672">&lt;</span> N; <span style="color:#f92672">++</span>i) {
cin <span style="color:#f92672">&gt;&gt;</span> A[i];
}
sort(A,A<span style="color:#f92672">+</span>N);
<span style="color:#66d9ef">long</span> <span style="color:#66d9ef">long</span> <span style="color:#66d9ef">int</span> res <span style="color:#f92672">=</span> A[N<span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>];
<span style="color:#66d9ef">int</span> number <span style="color:#f92672">=</span> <span style="color:#ae81ff">2</span>;
<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> N<span style="color:#f92672">-</span><span style="color:#ae81ff">2</span>; number<span style="color:#f92672">&lt;</span>N ; i<span style="color:#f92672">--</span> ) {
<span style="color:#66d9ef">if</span>(number<span style="color:#f92672">+</span><span style="color:#ae81ff">2</span><span style="color:#f92672">&lt;=</span>N) {
res <span style="color:#f92672">=</span> res <span style="color:#f92672">+</span> <span style="color:#ae81ff">2</span> <span style="color:#f92672">*</span> A[i];
number<span style="color:#f92672">+=</span><span style="color:#ae81ff">2</span>;
}<span style="color:#66d9ef">else</span>{
res <span style="color:#f92672">=</span> res <span style="color:#f92672">+</span> A[i];
number<span style="color:#f92672">++</span>;
}
}
cout <span style="color:#f92672">&lt;&lt;</span> res;
<span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
}
</code></pre></div></description>
</item>
<item>
<title>AtABC173C-状态压缩</title>
<link>https://luosuu.github.io/post/atabc173c/</link>
<pubDate>Sat, 08 Aug 2020 20:52:39 +0800</pubDate>
<guid>https://luosuu.github.io/post/atabc173c/</guid>
<description><p>题面:https://atcoder.jp/contests/abc173/tasks/abc173_c</p>
<p>用题解的方式来理解,对于每一行是否被涂成红色,可以用一个二进制数来表示,假如有三行,以下可以做示例。</p>
<p><code>No,No,No</code>-<code>0,0,0</code>,</p>
<p><code>Yes,No,No</code>-<code>0,0,1</code>,</p>
<p><code>No,Yes,No</code>-<code>0,1,0</code>,</p>
<p><code>Yes,Yes,No</code>-<code>0,1,1</code></p>
<p>虽然看起来是位置反过来了,其实是说第一行被涂成红色了,那二进制数的第一位就是1。</p>
<p>我们就可以枚举所有行和列的状态,对于三行四列来说,行有$2^3$个状态(0-7),列有$2^4$个状态(0-15),共有$2^3 \cdot 2^4=2^{3+4}$个状态。</p>
<p>对于每一个状态,我们可以检查黑色区域的数量,对于第i行第j列的区域,我们可以检查这个区域是否被涂成红色的行或列覆盖,与它本身是不是黑色。</p>
<p>检查某个区域是不是被涂成红色的行或列覆盖的方法,就是通过将代表行状态的二进制数,右移i位并与1做与运算,判断结果是不是为0,如果是0,说明没有被覆盖。</p>
<p>这是因为右移i位后,第i位就变成了第1位,与1做与运算,如果原本第i位是1(该行被涂成红色),结果就会是1,否则就是0。列同理。</p>
<p>C++代码如下:</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-c++" data-lang="c++"><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;iostream&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e">#include</span> <span style="color:#75715e">&#34;string&#34;</span><span style="color:#75715e">
</span><span style="color:#75715e"></span>
<span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;
<span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {
<span style="color:#66d9ef">int</span> H,W,K;
cin <span style="color:#f92672">&gt;&gt;</span> H <span style="color:#f92672">&gt;&gt;</span> W <span style="color:#f92672">&gt;&gt;</span> K;
<span style="color:#66d9ef">char</span> map[H][W];
<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i <span style="color:#f92672">&lt;</span> H; <span style="color:#f92672">++</span>i) {
scanf(<span style="color:#e6db74">&#34;%s&#34;</span>,map[i]);
}
<span style="color:#66d9ef">int</span> solutions <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i <span style="color:#f92672">&lt;</span> (<span style="color:#ae81ff">1</span> <span style="color:#f92672">&lt;&lt;</span> H) <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>; <span style="color:#f92672">++</span>i) {
<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> j <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; j <span style="color:#f92672">&lt;</span> (<span style="color:#ae81ff">1</span> <span style="color:#f92672">&lt;&lt;</span> W) <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>; <span style="color:#f92672">++</span>j) {
<span style="color:#66d9ef">int</span> black <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> k <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; k <span style="color:#f92672">&lt;</span> H; <span style="color:#f92672">++</span>k) {
<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> l <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; l <span style="color:#f92672">&lt;</span> W; <span style="color:#f92672">++</span>l) {
<span style="color:#66d9ef">if</span>( ( (i<span style="color:#f92672">&gt;&gt;</span>k)<span style="color:#f92672">&amp;</span><span style="color:#ae81ff">1</span> )<span style="color:#f92672">==</span><span style="color:#ae81ff">0</span><span style="color:#f92672">&amp;&amp;</span>((j<span style="color:#f92672">&gt;&gt;</span>l)<span style="color:#f92672">&amp;</span><span style="color:#ae81ff">1</span>)<span style="color:#f92672">==</span><span style="color:#ae81ff">0</span><span style="color:#f92672">&amp;&amp;</span>map[k][l]<span style="color:#f92672">==</span><span style="color:#e6db74">&#39;#&#39;</span> ){
black<span style="color:#f92672">++</span>;
}
}
}
<span style="color:#66d9ef">if</span>(black<span style="color:#f92672">==</span>K){
solutions<span style="color:#f92672">++</span>;
}
}
}
cout <span style="color:#f92672">&lt;&lt;</span> solutions;
<span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
}
</code></pre></div></description>
</item>
<item>
<title>STsheet</title>
<link>https://luosuu.github.io/post/stsheet/</link>
<pubDate>Sat, 08 Aug 2020 14:34:53 +0800</pubDate>
<guid>https://luosuu.github.io/post/stsheet/</guid>
<description><p>《浅谈ST表》完整请参考:https://www.luogu.com.cn/blog/zhouziheng666/qian-tan-st-biao</p>
<p>核心要素</p>
<ol>
<li>查询操作可以重叠,如max操作<code>max(a,b,c)=max(max(a,b),max(b,c))</code></li>
<li>采用倍增的方法构建,如果用$f(i,j)$代表从第i个数开始,共$2^j$个数的最大值,那么就有:</li>
</ol>
<p>$$
f(i,j)=max(f(i,j-1),f(i+2^{j-1},j-1))
$$</p>
<ol start="3">
<li>
<p>自然,$f(i,0)=a[i]$</p>
</li>
<li>
<p>由于查询的时候,查询的长度可能是小于等于N的任何一个整数,设该查询的长度是<code>len</code>,查询的数组的第一个数是整个数组的第<code>r</code>个数。我们可以用$max[r,r+len]$来代表被查询的数组的最大值,以上面的函数的定义,可以用
$$
f(r,log_{2}(len))
$$
来表示。在输入数组总长度N后,我们需要对1到N的所有数求对数,提前存储好所有可能要用的<code>log(len)</code>。</p>
</li>
<li>
<p>对于某个从第<code>r</code>个数开始的被查询的长度为<code>len</code>数组,$f(r,log_{2}(len))$的实际来源为</p>
<p>$$f(r,1)=max(f(r,1-1),f(r+2^{1-1},1-1))$$
$$f(r,2)=max(f(r,2-1),f(r+2^{2-1},2-1)) $$
$$f(r,3)=max(f(r,3-1),f(r+2^{3-1},3-1)) $$
$$&hellip;$$
$$f(,log_{2}len)=max(f(r,log_{2}len-1),f(r+2^{log_{2}len-1},log_{2}len-1))$$</p>
<p>在获取数组长度和数组内容后,实际上是用所有的$f(i,0)$获得了所有的$f(i,1)$,然后再用$f(i,1)$得到所有的$f(i,2)$(这个过程要保证$i+2^j$不超过N,否则会越界),一直到获得$f(0,log_{2}N)$。这样查询时,对于任意一个$f(r,log_{2}len)$都能立刻查询到,查询的复杂度为$O(1)$。</p>
</li>
<li>
<p>如果查询的数组长<code>len</code>,$[log_{2}len]$代表<code>len</code>对2取对数的向下取整,那么一次这种函数的构建最多能包含$2^{[log_{2}len]}$个数,如果<code>len</code>不是2的倍数,那么就会有数不会被包括进去,所以实际上为了求该数组的最大值,是从左端和右边分别构建一个函数($2^{[log_{2}len]}$肯定大于$len/2$),取这两个函数的最大值:
$$
max[r,r+len]=max(f(r,log(len)), f(r-log(len)+1,log(len)))
$$</p>
</li>
<li>
<p>对于任何可以重叠的查询操作,都可以使用ST表这种方法,无非是从$f(i,0)$开始向上构建时采用的方法不同。但构建逻辑和数据结构是一样的。</p>
</li>
</ol>
</description>
</item>
<item>
<title>2020shanghai B - 缓冲区结算、括号嵌套的递归</title>
<link>https://luosuu.github.io/post/2020shanghai-b/</link>
<pubDate>Thu, 06 Aug 2020 11:13:49 +0800</pubDate>
<guid>https://luosuu.github.io/post/2020shanghai-b/</guid>
<description><p>题面:https://ac.nowcoder.com/acm/contest/6871/B</p>
<h2 id="分析">分析</h2>
<p>典型的字符串处理,而且出题人强调了没有括号嵌套(真亚撒西嘤嘤嘤)。</p>
<p>因为分子式不同部分的计算方式是不一样的,可以用缓冲的思想来解决这个问题。</p>
<p>在不考虑括号嵌套的情况下</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-c++" data-lang="c++"><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;iostream&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e">#include</span> <span style="color:#75715e">&#34;string&#34;</span><span style="color:#75715e">
</span><span style="color:#75715e"></span><span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;
<span style="color:#66d9ef">typedef</span> <span style="color:#66d9ef">long</span> <span style="color:#66d9ef">long</span> ll;
string a;
<span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>(){
cin<span style="color:#f92672">&gt;&gt;</span>a;
ll ans<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>,cnt<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>,res<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>,sum<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>;
<span style="color:#66d9ef">int</span> len<span style="color:#f92672">=</span>a.length();
<span style="color:#66d9ef">for</span>(<span style="color:#66d9ef">int</span> i<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>;i<span style="color:#f92672">&lt;</span>a.length();)
{
<span style="color:#66d9ef">if</span>(a[i]<span style="color:#f92672">==</span><span style="color:#e6db74">&#39;C&#39;</span><span style="color:#f92672">||</span>a[i]<span style="color:#f92672">==</span><span style="color:#e6db74">&#39;H&#39;</span><span style="color:#f92672">||</span>a[i]<span style="color:#f92672">==</span><span style="color:#e6db74">&#39;O&#39;</span>){
<span style="color:#66d9ef">if</span>(a[i]<span style="color:#f92672">==</span><span style="color:#e6db74">&#39;C&#39;</span>)cnt<span style="color:#f92672">=</span><span style="color:#ae81ff">13</span>;
<span style="color:#66d9ef">if</span>(a[i]<span style="color:#f92672">==</span><span style="color:#e6db74">&#39;H&#39;</span>)cnt<span style="color:#f92672">=</span><span style="color:#ae81ff">1</span>;
<span style="color:#66d9ef">if</span>(a[i]<span style="color:#f92672">==</span><span style="color:#e6db74">&#39;O&#39;</span>)cnt<span style="color:#f92672">=</span><span style="color:#ae81ff">17</span>;
i<span style="color:#f92672">++</span>;
res<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>;
<span style="color:#66d9ef">while</span>(i<span style="color:#f92672">&lt;</span>len<span style="color:#f92672">&amp;&amp;</span>a[i]<span style="color:#f92672">&gt;=</span><span style="color:#e6db74">&#39;0&#39;</span><span style="color:#f92672">&amp;&amp;</span>a[i]<span style="color:#f92672">&lt;=</span><span style="color:#e6db74">&#39;9&#39;</span>){
res<span style="color:#f92672">=</span>res<span style="color:#f92672">*</span><span style="color:#ae81ff">10</span><span style="color:#f92672">+</span>a[i]<span style="color:#f92672">-</span><span style="color:#e6db74">&#39;0&#39;</span>;
i<span style="color:#f92672">++</span>;
}
<span style="color:#66d9ef">if</span>(<span style="color:#f92672">!</span>res)ans<span style="color:#f92672">+=</span>cnt;
<span style="color:#66d9ef">else</span> ans<span style="color:#f92672">+=</span>cnt<span style="color:#f92672">*</span>res;
}
<span style="color:#75715e">//遇到左括号,就先把未加进最终结果的非括号内元素们算入结果,清空缓冲区,准备计算括号内的分子式
</span><span style="color:#75715e"></span> <span style="color:#66d9ef">if</span>(a[i]<span style="color:#f92672">==</span><span style="color:#e6db74">&#39;(&#39;</span><span style="color:#f92672">&amp;&amp;</span>i<span style="color:#f92672">&lt;</span>len){
sum<span style="color:#f92672">+=</span>ans;
ans<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>;
i<span style="color:#f92672">++</span>;
}
<span style="color:#75715e">//遇到右括号,结算括号内部的
</span><span style="color:#75715e"></span> <span style="color:#66d9ef">if</span>(a[i]<span style="color:#f92672">==</span><span style="color:#e6db74">&#39;)&#39;</span><span style="color:#f92672">&amp;&amp;</span>i<span style="color:#f92672">&lt;</span>len){
i<span style="color:#f92672">++</span>;
res<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>;
<span style="color:#66d9ef">while</span>(i<span style="color:#f92672">&lt;</span>len<span style="color:#f92672">&amp;&amp;</span>a[i]<span style="color:#f92672">&gt;=</span><span style="color:#e6db74">&#39;0&#39;</span><span style="color:#f92672">&amp;&amp;</span>a[i]<span style="color:#f92672">&lt;=</span><span style="color:#e6db74">&#39;9&#39;</span>){
res<span style="color:#f92672">=</span>res<span style="color:#f92672">*</span><span style="color:#ae81ff">10</span><span style="color:#f92672">+</span>a[i]<span style="color:#f92672">-</span><span style="color:#e6db74">&#39;0&#39;</span>;
i<span style="color:#f92672">++</span>;
}
<span style="color:#66d9ef">if</span>(<span style="color:#f92672">!</span>res)sum<span style="color:#f92672">+=</span>ans;
<span style="color:#66d9ef">else</span> sum<span style="color:#f92672">+=</span>ans<span style="color:#f92672">*</span>res;
ans<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>;
}
}
sum<span style="color:#f92672">+=</span>ans;
printf(<span style="color:#e6db74">&#34;%lld&#34;</span>,sum);
}
</code></pre></div><h3 id="用递归的方式处理括号嵌套">用递归的方式处理括号嵌套</h3>
<p>如果要考虑括号内部的嵌套,就需要用到递归的方法了。</p>
<p>先说缓冲区的部分,遇到常规字符<code>C</code>,<code>H</code>,<code>O</code>,将缓冲区算入结果,将常规字符的值读入缓冲区,以处理后面可能会出现的数字,括号等情况。</p>
<p>遇到左括号,也是先将缓冲区算入结果,然后进入下一层函数,计算括号内部的分子式,遇到右括号时内部分子式返回来。如果内部还有括号,同理,会进入再下一层函数。最后将括号内的值读入缓冲区。</p>
<p>遇到数字,就会继续往下读,直到把整个数字段都读出来(这个过程会转换为具体的数字<code>times</code>)。然后将缓冲区内的值乘以times算入结果,清空缓冲区(这里清空缓冲区是必要的,虽然读入下一个数据的时候会覆盖它,但是如果已经是最后一个数据,就会跳出循环,执行最后的缓冲区内数据算入结果,如果不清空会多算一次)。</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-c++" data-lang="c++"><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;cstdio&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e">#include</span> <span style="color:#75715e">&#34;string&#34;</span><span style="color:#75715e">
</span><span style="color:#75715e">#define ll long long
</span><span style="color:#75715e"></span><span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;
<span style="color:#66d9ef">char</span> in[<span style="color:#ae81ff">1000050</span>];
<span style="color:#66d9ef">int</span> len;
ll <span style="color:#a6e22e">cal</span>(<span style="color:#66d9ef">int</span> <span style="color:#f92672">&amp;</span>now){
ll tmp<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>,sum<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>,times<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>;
<span style="color:#66d9ef">for</span>(now;now<span style="color:#f92672">&lt;</span>len;){
<span style="color:#66d9ef">if</span>(in[now]<span style="color:#f92672">&gt;=</span><span style="color:#e6db74">&#39;0&#39;</span><span style="color:#f92672">&amp;&amp;</span>in[now]<span style="color:#f92672">&lt;=</span><span style="color:#e6db74">&#39;9&#39;</span>){
times<span style="color:#f92672">=</span>(in[now]<span style="color:#f92672">-</span><span style="color:#e6db74">&#39;0&#39;</span>);
now<span style="color:#f92672">++</span>;
<span style="color:#66d9ef">while</span>(in[now]<span style="color:#f92672">&gt;=</span><span style="color:#e6db74">&#39;0&#39;</span><span style="color:#f92672">&amp;&amp;</span>in[now]<span style="color:#f92672">&lt;=</span><span style="color:#e6db74">&#39;9&#39;</span>){
times<span style="color:#f92672">*=</span><span style="color:#ae81ff">10</span>;
times<span style="color:#f92672">+=</span>(in[now]<span style="color:#f92672">-</span><span style="color:#e6db74">&#39;0&#39;</span>);
now<span style="color:#f92672">++</span>;
}
sum<span style="color:#f92672">+=</span>tmp<span style="color:#f92672">*</span>times;
tmp<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>;
<span style="color:#66d9ef">continue</span>;
}
<span style="color:#75715e">//遇到左括号时,先将缓冲区内部加入结果,然后进入下一层函数,计算内部分子式,遇到右括号再返回来
</span><span style="color:#75715e"></span> <span style="color:#66d9ef">if</span>(in[now]<span style="color:#f92672">==</span><span style="color:#e6db74">&#39;(&#39;</span>){
sum<span style="color:#f92672">+=</span>tmp;
now<span style="color:#f92672">++</span>;
tmp<span style="color:#f92672">=</span>cal(now);
}
<span style="color:#66d9ef">else</span> <span style="color:#66d9ef">if</span>(in[now]<span style="color:#f92672">==</span><span style="color:#e6db74">&#39;)&#39;</span>){
sum<span style="color:#f92672">+=</span>tmp;
now<span style="color:#f92672">++</span>;
<span style="color:#66d9ef">return</span> sum;
}
<span style="color:#75715e">//遇到常规字符也是把上一个缓冲区的内容加入结果,把当前的加入缓冲区,以处理后面可能会出现的数字
</span><span style="color:#75715e"></span> <span style="color:#66d9ef">if</span>(in[now]<span style="color:#f92672">==</span><span style="color:#e6db74">&#39;C&#39;</span>){
sum<span style="color:#f92672">+=</span>tmp;
tmp<span style="color:#f92672">=</span><span style="color:#ae81ff">13</span>;
now<span style="color:#f92672">++</span>;
}<span style="color:#66d9ef">else</span> <span style="color:#66d9ef">if</span>(in[now]<span style="color:#f92672">==</span><span style="color:#e6db74">&#39;H&#39;</span>){
sum<span style="color:#f92672">+=</span>tmp;
tmp<span style="color:#f92672">=</span><span style="color:#ae81ff">1</span>;
now<span style="color:#f92672">++</span>;
}<span style="color:#66d9ef">else</span> <span style="color:#66d9ef">if</span>(in[now]<span style="color:#f92672">==</span><span style="color:#e6db74">&#39;O&#39;</span>){
sum<span style="color:#f92672">+=</span>tmp;
tmp<span style="color:#f92672">=</span><span style="color:#ae81ff">17</span>;
now<span style="color:#f92672">++</span>;
}
}
sum<span style="color:#f92672">+=</span>tmp;
<span style="color:#66d9ef">return</span> sum;
}
<span style="color:#66d9ef">void</span> <span style="color:#a6e22e">solve</span>(<span style="color:#66d9ef">int</span> T){
scanf(<span style="color:#e6db74">&#34;%s&#34;</span>,in);
len<span style="color:#f92672">=</span>strlen(in);
<span style="color:#66d9ef">int</span> now<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>;
printf(<span style="color:#e6db74">&#34;%lld&#34;</span>,cal(now));
}
<span style="color:#66d9ef">signed</span> <span style="color:#a6e22e">main</span>(){
<span style="color:#66d9ef">int</span> t<span style="color:#f92672">=</span><span style="color:#ae81ff">1</span>;
<span style="color:#75715e">//scanf(&#34;%d&#34;,&amp;t);
</span><span style="color:#75715e"></span> <span style="color:#66d9ef">for</span>(<span style="color:#66d9ef">int</span> i<span style="color:#f92672">=</span><span style="color:#ae81ff">1</span>;i<span style="color:#f92672">&lt;=</span>t;i<span style="color:#f92672">++</span>){
solve(i);
}
}
</code></pre></div></description>
</item>
<item>
<title>AtABC174 E-二分查找</title>
<link>https://luosuu.github.io/post/atabc174-e/</link>
<pubDate>Thu, 06 Aug 2020 10:04:10 +0800</pubDate>
<guid>https://luosuu.github.io/post/atabc174-e/</guid>
<description><p>题面:https://atcoder.jp/contests/abc174/tasks/abc174_e</p>
<h2 id="分析">分析</h2>
<p>输入N个有长度<code>A[n]</code>的原木,现在要一共对这些木头切至多K刀,求切K刀后所有木材最长的木材的最短值。即让切K刀后的所有木材的最长值尽量短。</p>
<p>检验一个木材最长值<code>len</code>是否符合切K刀的条件是简单的,只需要每个原木的长度除以<code>len</code>向上取整再减一,然后取和,就能检验是否符合切K刀的条件。</p>
<p>这类找出 “最长值的最短”“最小值的最大”一类,也就是<code>max(min(len))</code>或<code>min(max(len))</code>一般是使用二分查找方法的提示。</p>
<p>在寻找最长木材的最小值的过程中,我们可以先用1做开头,原木中最长值<code>max_len</code>做结尾,然后以这俩为首位进行二分查找。有三种情况</p>
<ol>
<li>
<p>当中值<code>mid</code>的切割次数小于K次,说明<code>mid</code>取的太长了,将<code>mid</code>作为新的结尾;</p>
</li>
<li>
<p>如果<code>mid</code>的切割次数大于K次,说明取的太短了,应该把<code>mid</code>作为新的开头;</p>
</li>
<li>
<p>当<code>mid</code>的切割次数恰好等于K次,说明<code>mid&gt;=最长木材的最小值</code>,应该继续往下探,将<code>mid</code>作为新的结尾。</p>
</li>
</ol>
<p>代码如下</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-c++" data-lang="c++"><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;iostream&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e"></span><span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;
<span style="color:#66d9ef">long</span> <span style="color:#66d9ef">long</span> <span style="color:#a6e22e">cut_times</span>(<span style="color:#66d9ef">long</span> <span style="color:#66d9ef">long</span> <span style="color:#f92672">*</span>logs, <span style="color:#66d9ef">long</span> <span style="color:#66d9ef">long</span> cut_len, <span style="color:#66d9ef">int</span> log_num);
<span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {
<span style="color:#66d9ef">int</span> N,K;
cin <span style="color:#f92672">&gt;&gt;</span> N <span style="color:#f92672">&gt;&gt;</span> K;
<span style="color:#66d9ef">long</span> <span style="color:#66d9ef">long</span> logs[N];
<span style="color:#66d9ef">long</span> <span style="color:#66d9ef">long</span> max_long <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
<span style="color:#66d9ef">for</span>(<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;i<span style="color:#f92672">&lt;</span>N;i<span style="color:#f92672">++</span>){
cin <span style="color:#f92672">&gt;&gt;</span> logs[i];
<span style="color:#66d9ef">if</span>(logs[i] <span style="color:#f92672">&gt;</span> max_long) {
max_long <span style="color:#f92672">=</span> logs[i];
}
}
<span style="color:#66d9ef">if</span>(K<span style="color:#f92672">==</span><span style="color:#ae81ff">0</span>){
cout <span style="color:#f92672">&lt;&lt;</span> max_long;
<span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
}
<span style="color:#66d9ef">long</span> <span style="color:#66d9ef">long</span> start <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>;
<span style="color:#66d9ef">long</span> <span style="color:#66d9ef">long</span> end <span style="color:#f92672">=</span> max_long;
<span style="color:#66d9ef">long</span> <span style="color:#66d9ef">long</span> mid;
<span style="color:#75715e">//binary search
</span><span style="color:#75715e"></span> <span style="color:#66d9ef">while</span>(start<span style="color:#f92672">&lt;</span>end){
mid <span style="color:#f92672">=</span> (start <span style="color:#f92672">+</span> end)<span style="color:#f92672">/</span><span style="color:#ae81ff">2</span>;
<span style="color:#66d9ef">if</span>(cut_times(logs, mid, N)<span style="color:#f92672">&lt;=</span>K){<span style="color:#75715e">//cut times equals to k, still need to try a smaller one
</span><span style="color:#75715e"></span> end <span style="color:#f92672">=</span> mid;
}<span style="color:#66d9ef">else</span> <span style="color:#66d9ef">if</span>(cut_times(logs, mid, N)<span style="color:#f92672">&gt;</span>K){
start <span style="color:#f92672">=</span> mid<span style="color:#f92672">+</span><span style="color:#ae81ff">1</span>;
}
}
cout <span style="color:#f92672">&lt;&lt;</span> start;
}
<span style="color:#75715e">// Given max cut length, get needed cut times
</span><span style="color:#75715e"></span><span style="color:#66d9ef">long</span> <span style="color:#66d9ef">long</span> <span style="color:#a6e22e">cut_times</span>(<span style="color:#66d9ef">long</span> <span style="color:#66d9ef">long</span> <span style="color:#f92672">*</span>logs, <span style="color:#66d9ef">long</span> <span style="color:#66d9ef">long</span> cut_len, <span style="color:#66d9ef">int</span> log_num){
<span style="color:#66d9ef">long</span> <span style="color:#66d9ef">long</span> need_times <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
<span style="color:#66d9ef">for</span>(<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;i<span style="color:#f92672">&lt;</span>log_num;i<span style="color:#f92672">++</span>){
<span style="color:#66d9ef">if</span>(<span style="color:#f92672">*</span>logs<span style="color:#f92672">%</span>cut_len<span style="color:#f92672">==</span><span style="color:#ae81ff">0</span>){
need_times <span style="color:#f92672">+=</span> <span style="color:#f92672">*</span>logs<span style="color:#f92672">/</span>cut_len<span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>;
}<span style="color:#66d9ef">else</span>{
need_times <span style="color:#f92672">+=</span> <span style="color:#f92672">*</span>logs<span style="color:#f92672">/</span>cut_len;
}
logs<span style="color:#f92672">++</span>;
}
<span style="color:#66d9ef">return</span> need_times;
}
</code></pre></div></description>
</item>
<item>
<title>Cf#661 A-输入输出</title>
<link>https://luosuu.github.io/post/cf661-a/</link>
<pubDate>Thu, 06 Aug 2020 08:41:45 +0800</pubDate>
<guid>https://luosuu.github.io/post/cf661-a/</guid>
<description><p>题面:https://codeforces.com/contest/1399/problem/A</p>
<p>存储每一例数据,排序,判断相邻的两个之间是否超过1即可。这里要注意的是输入输出的方式。</p>
<p>以下注释掉的地方也都是可以采用的方式。</p>
<p>其中一种方式是避免动态数组,使用用提前规定好的最大数组。(虽然这个题用动态数组也过了)</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-C++" data-lang="C++"><span style="color:#75715e">#include</span> <span style="color:#75715e">&#34;stdio.h&#34;</span><span style="color:#75715e">
</span><span style="color:#75715e">#include</span> <span style="color:#75715e">&#34;algorithm&#34;</span><span style="color:#75715e">
</span><span style="color:#75715e">#include</span> <span style="color:#75715e">&#34;iostream&#34;</span><span style="color:#75715e">
</span><span style="color:#75715e"></span><span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;
<span style="color:#75715e">//int a[1050];
</span><span style="color:#75715e"></span><span style="color:#66d9ef">void</span> <span style="color:#a6e22e">solve</span>(){
<span style="color:#66d9ef">int</span> n;
<span style="color:#75715e">// scanf(&#34;%d&#34;,&amp;n);
</span><span style="color:#75715e"></span> cin <span style="color:#f92672">&gt;&gt;</span> n;
<span style="color:#66d9ef">int</span> a[n];
<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i <span style="color:#f92672">&lt;</span> n; <span style="color:#f92672">++</span>i) {
<span style="color:#75715e">// scanf(&#34;%d&#34;,&amp;a[i]);
</span><span style="color:#75715e"></span> cin <span style="color:#f92672">&gt;&gt;</span> a[i];
}
sort(a,a<span style="color:#f92672">+</span>n);
<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>; i <span style="color:#f92672">&lt;</span> n; <span style="color:#f92672">++</span>i) {
<span style="color:#66d9ef">if</span>(a[i]<span style="color:#f92672">-</span>a[i<span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>]<span style="color:#f92672">&gt;</span><span style="color:#ae81ff">1</span>){
<span style="color:#75715e">// puts(&#34;NO&#34;);
</span><span style="color:#75715e"></span> cout <span style="color:#f92672">&lt;&lt;</span> <span style="color:#e6db74">&#34;NO&#34;</span> <span style="color:#f92672">&lt;&lt;</span>endl;
<span style="color:#66d9ef">return</span>;
}
}
<span style="color:#75715e">// puts(&#34;YES&#34;);
</span><span style="color:#75715e"></span> cout <span style="color:#f92672">&lt;&lt;</span> <span style="color:#e6db74">&#34;YES&#34;</span> <span style="color:#f92672">&lt;&lt;</span> endl;
}
<span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;
<span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>(){
<span style="color:#66d9ef">int</span> t;
<span style="color:#75715e">// scanf(&#34;%d&#34;,&amp;t);
</span><span style="color:#75715e"></span> cin <span style="color:#f92672">&gt;&gt;</span> t;
<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>; i <span style="color:#f92672">&lt;</span> t; <span style="color:#f92672">++</span>i) {
solve();
}
<span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
}
</code></pre></div><h3 id="another">another</h3>
<p>还有一道题也是和输入输出相关的</p>
<p><strong>题目描述:</strong></p>
<p>大学的同学来自全国各地,对于远离家乡步入陌生大学校园的大一新生来说,碰到老乡是多么激动的一件事,于是大家都热衷于问身边的同学是否与自己同乡,来自新疆的小赛尤其热衷。但是大家都不告诉小赛他们来自哪里,只是说与谁是不是同乡,从所给的信息中,你能告诉小赛有多少人确定是她的同乡吗?</p>
<p><strong>输入描述:</strong></p>
<p>包含多组测试用例。</p>
<p>对于每组测试用例:</p>
<p>第一行包括2个整数,N(1 &lt;= N &lt;= 1000),M(0 &lt;= M &lt;= N*(N-1)/2),代表现有N个人(用1~N编号)和M组关系;</p>
<p>在接下来的M行里,每行包括3个整数,a,b, c,如果c为1,则代表a跟b是同乡;如果c为0,则代表a跟b不是同乡;</p>
<p>已知1表示小赛本人。</p>
<p><strong>输入样例:</strong></p>
<p>3 1</p>
<p>2 3 1</p>
<p>5 4</p>
<p>1 2 1</p>
<p>3 4 0</p>
<p>2 5 1</p>
<p>3 2 1</p>
<p>本题的输入部分可以这样写</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-c" data-lang="c"><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;stdio.h&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e"></span><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>()
{
<span style="color:#66d9ef">int</span> N, M;
<span style="color:#75715e">// 每组第一行是2个整数,N和M,至于为啥用while,因为是多组。
</span><span style="color:#75715e"></span> <span style="color:#66d9ef">while</span>(scanf(<span style="color:#e6db74">&#34;%d %d&#34;</span>, <span style="color:#f92672">&amp;</span>N, <span style="color:#f92672">&amp;</span>M) <span style="color:#f92672">!=</span> EOF) {
printf(<span style="color:#e6db74">&#34;%d %d</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span>, N, M);
<span style="color:#75715e">// 循环读取“接下来的M行”
</span><span style="color:#75715e"></span> <span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span> i<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>; i<span style="color:#f92672">&lt;</span>M; i<span style="color:#f92672">++</span>) {
<span style="color:#66d9ef">int</span> a, b, c;
<span style="color:#75715e">// 每行是3个整数,a,b,c。
</span><span style="color:#75715e"></span> scanf(<span style="color:#e6db74">&#34;%d %d %d&#34;</span>, <span style="color:#f92672">&amp;</span>a, <span style="color:#f92672">&amp;</span>b, <span style="color:#f92672">&amp;</span>c);
printf(<span style="color:#e6db74">&#34;%d %d %d</span><span style="color:#ae81ff">\n</span><span style="color:#e6db74">&#34;</span>, a, b, c);
}
<span style="color:#75715e">// M行读取完了,就又要开始下一组了,去while那里。
</span><span style="color:#75715e"></span> }
}
</code></pre></div><h3 id="and-another-one">and another one!</h3>
<p>还有一道题是<a href="https://ac.nowcoder.com/acm/contest/6871/C">2020上海高校程序设计竞赛的C题</a></p>
<p>计算每一例聊天记录里,含<code>2</code>的句子占的比例。</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-C++" data-lang="C++"><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;iostream&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e">#include</span> <span style="color:#75715e">&#34;string&#34;</span><span style="color:#75715e">
</span><span style="color:#75715e"></span><span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;
<span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {
<span style="color:#66d9ef">int</span> T;
cin <span style="color:#f92672">&gt;&gt;</span> T;
<span style="color:#66d9ef">double</span> rate[T];
<span style="color:#66d9ef">double</span> num[T];
<span style="color:#66d9ef">for</span>(<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;i<span style="color:#f92672">&lt;</span>T;i<span style="color:#f92672">++</span>){
num[i] <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;
<span style="color:#66d9ef">int</span> n;
cin <span style="color:#f92672">&gt;&gt;</span> n;
getchar();
<span style="color:#66d9ef">for</span>(<span style="color:#66d9ef">int</span> j <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;j<span style="color:#f92672">&lt;</span>n;j<span style="color:#f92672">++</span>){
string in;
getline(cin,in);
<span style="color:#66d9ef">int</span> len <span style="color:#f92672">=</span> in.size();
<span style="color:#66d9ef">for</span>(<span style="color:#66d9ef">int</span> k <span style="color:#f92672">=</span> <span style="color:#ae81ff">0</span>;k<span style="color:#f92672">&lt;</span>len;k<span style="color:#f92672">++</span>){
<span style="color:#66d9ef">if</span>(in[k]<span style="color:#f92672">==</span><span style="color:#e6db74">&#39;2&#39;</span>){
num[i]<span style="color:#f92672">++</span>;
<span style="color:#66d9ef">break</span>;
}
}
}
rate[i] <span style="color:#f92672">=</span> num[i]<span style="color:#f92672">/</span>(n<span style="color:#f92672">*</span><span style="color:#ae81ff">1.0</span>);
cout <span style="color:#f92672">&lt;&lt;</span> rate[i] <span style="color:#f92672">&lt;&lt;</span> endl;
}
}
</code></pre></div><h3 id="one-more-thing">one more thing</h3>
<p>转载一下<a href="https://blog.csdn.net/m0_38059875/article/details/105205096">CSDN上的OJ之C++输入输出总结</a>。</p>
<h4 id="不知道输入几组">不知道输入几组</h4>
<blockquote>
<p>计算a+b的和</p>
<p>每行包含两个整数a和b</p>
<p>对于每行输入对应输出一行a和b的和</p>
<p>输入</p>
<p>1 5</p>
<p>输出</p>
<p>6</p>
</blockquote>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cpp" data-lang="cpp"><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;iostream&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e"></span><span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;
<span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {
<span style="color:#66d9ef">int</span> a,b;
<span style="color:#66d9ef">while</span>(cin <span style="color:#f92672">&gt;&gt;</span> a <span style="color:#f92672">&gt;&gt;</span> b)<span style="color:#75715e">//注意while处理多个case
</span><span style="color:#75715e"></span> cout <span style="color:#f92672">&lt;&lt;</span> a<span style="color:#f92672">+</span>b <span style="color:#f92672">&lt;&lt;</span> endl;
<span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
}
</code></pre></div><h4 id="知道输入几组">知道输入几组</h4>
<p>先输入一个组数n,然后再循环读取n组数据。</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cpp" data-lang="cpp"><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;iostream&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e"></span><span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;
<span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {
<span style="color:#66d9ef">int</span> n; <span style="color:#75715e">// 数据的组数
</span><span style="color:#75715e"></span> cin <span style="color:#f92672">&gt;&gt;</span> n; <span style="color:#75715e">// 读取组数
</span><span style="color:#75715e"></span> <span style="color:#66d9ef">for</span>(<span style="color:#66d9ef">int</span> i<span style="color:#f92672">=</span><span style="color:#ae81ff">0</span>; i<span style="color:#f92672">&lt;</span>n; <span style="color:#f92672">++</span>i){
<span style="color:#66d9ef">int</span> a, b;
cin <span style="color:#f92672">&gt;&gt;</span> a <span style="color:#f92672">&gt;&gt;</span> b;
cout <span style="color:#f92672">&lt;&lt;</span> a<span style="color:#f92672">+</span>b <span style="color:#f92672">&lt;&lt;</span>endl;
}
<span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
}
</code></pre></div><h4 id="字符串的输入处理">字符串的输入处理</h4>
<p>因为OJ最终只比较文件,就不用保存所有输入,可以读一组数据计算一组数据。</p>
<p>当读取字符串的时候需要注意,<code>cin</code>不能读取空白字符,比如空格,如果遇到空格则会直接终止字符串。</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cpp" data-lang="cpp"><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;iostream&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;string&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e"></span><span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;
<span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {
string s;
cin <span style="color:#f92672">&gt;&gt;</span> s; <span style="color:#75715e">// 读到空白就结束当前的字符串
</span><span style="color:#75715e"></span> cout <span style="color:#f92672">&lt;&lt;</span> s;
<span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
}
</code></pre></div><p>运行的结果:</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">abc <span style="color:#ae81ff">123</span>
abc请按任意键继续. . .
</code></pre></div><p>如果要读取整行字符串,可以使用<code>getline()</code>和<code>cin.getline()</code>这两个函数,两个函数都是遇到定界符,则结束这行的字符串,定界符默认设置为<strong>回车</strong>。两个函数略有不同的是,<code>getline()</code>操作的对象是string,<code>cin.getline()</code>操作的对象的char数组。详细的定义如下:</p>
<p><code>getline()</code>,要使用这个函数需要包含头文件&lt;string&gt;,</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cpp" data-lang="cpp">istream<span style="color:#f92672">&amp;</span> getline(istream<span style="color:#f92672">&amp;</span> is, string<span style="color:#f92672">&amp;</span> str, <span style="color:#66d9ef">char</span> delim);
istream<span style="color:#f92672">&amp;</span> getline(istream<span style="color:#f92672">&amp;</span> is, string<span style="color:#f92672">&amp;</span> str);
</code></pre></div><ul>
<li>is:它是istream类的对象,告诉函数从何处读取输入流。</li>
<li>str:这是一个string字符串对象,从流中读取输入后,将输入存储在此对象中。</li>
<li>delim:这是定界字符,它告诉函数在达到该字符后停止读取进一步的输入。</li>
<li>返回值:此函数返回值是与输入参数is相同的输入流。</li>
</ul>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cpp" data-lang="cpp"><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;iostream&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;string&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e"></span><span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;
<span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {
string s;
getline(cin, s);
cout <span style="color:#f92672">&lt;&lt;</span> s;
system(<span style="color:#e6db74">&#34;pause&#34;</span>);
<span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
}
<span style="color:#ae81ff">12345678910</span>
</code></pre></div><p>运行结果:</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">abc <span style="color:#ae81ff">123</span>
abc 123请按任意键继续. . .
</code></pre></div><p><code>cin.getline()</code>函数读取至新行结尾或直到达到最大限制的整行文本。函数定义如下:</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cpp" data-lang="cpp"><span style="color:#75715e">// (buffer, stream_size, delimiter)
</span><span style="color:#75715e"></span>istream<span style="color:#f92672">&amp;</span> getline(<span style="color:#66d9ef">char</span><span style="color:#f92672">*</span>, <span style="color:#66d9ef">int</span> size, <span style="color:#66d9ef">char</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#39;\n&#39;</span>)
<span style="color:#75715e">// The delimiter character is considered as &#39;\n&#39;
</span><span style="color:#75715e"></span>istream<span style="color:#f92672">&amp;</span> getline(<span style="color:#66d9ef">char</span><span style="color:#f92672">*</span>, <span style="color:#66d9ef">int</span> size)
<span style="color:#ae81ff">12345</span>
</code></pre></div><ol>
<li>提取字符直到定界符。</li>
<li>将字符存储在缓冲区中。</li>
<li>提取的最大字符数为<code>size-1</code>。</li>
</ol>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cpp" data-lang="cpp"><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;iostream&gt; </span><span style="color:#75715e">
</span><span style="color:#75715e"></span><span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;
<span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>()
{
<span style="color:#66d9ef">char</span> str[<span style="color:#ae81ff">20</span>];
cin.getline(str, <span style="color:#ae81ff">20</span>);
cout <span style="color:#f92672">&lt;&lt;</span> str;
<span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
}
<span style="color:#ae81ff">123456789</span>
</code></pre></div><p>运行结果:</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">no bug forever
no bug forever请按任意键继续. . .
<span style="color:#ae81ff">12</span>
</code></pre></div><p>例子:</p>
<p>输入为9个数字,每个数字用<code>逗号,</code>分隔,将数字保存到一个一维数组中。</p>
<blockquote>
<p>1,2,3,4,5,6,7,8,9</p>
</blockquote>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-cpp" data-lang="cpp"><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;iostream&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;string&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;vector&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e"></span><span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;
<span style="color:#66d9ef">void</span> <span style="color:#a6e22e">test</span>() {
string str;
cin <span style="color:#f92672">&gt;&gt;</span> str; <span style="color:#75715e">// 获取整行数据
</span><span style="color:#75715e"></span> vector<span style="color:#f92672">&lt;</span><span style="color:#66d9ef">int</span><span style="color:#f92672">&gt;</span> vec; <span style="color:#75715e">// 将数字保存在数组中
</span><span style="color:#75715e"></span> <span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">char</span><span style="color:#f92672">&amp;</span> ch : str) {
<span style="color:#66d9ef">if</span> (isdigit(ch)) vec.push_back(ch <span style="color:#f92672">-</span> <span style="color:#e6db74">&#39;0&#39;</span>); <span style="color:#75715e">// 如果是数字才保存,并且需要减去字符0
</span><span style="color:#75715e"></span> }
<span style="color:#66d9ef">for</span> (<span style="color:#66d9ef">int</span><span style="color:#f92672">&amp;</span> i : vec) {
cout <span style="color:#f92672">&lt;&lt;</span> i <span style="color:#f92672">&lt;&lt;</span> <span style="color:#e6db74">&#39; &#39;</span>;
}
}
<span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {
test();
system(<span style="color:#e6db74">&#34;pause&#34;</span>);
<span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
}
<span style="color:#ae81ff">123456789101112131415161718192021</span>
</code></pre></div><p>运行结果:</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-shell" data-lang="shell">1,2,3,4,5,6,7,8,9
<span style="color:#ae81ff">1</span> <span style="color:#ae81ff">2</span> <span style="color:#ae81ff">3</span> <span style="color:#ae81ff">4</span> <span style="color:#ae81ff">5</span> <span style="color:#ae81ff">6</span> <span style="color:#ae81ff">7</span> <span style="color:#ae81ff">8</span> <span style="color:#ae81ff">9</span> 请按任意键继续. . .
</code></pre></div></description>
</item>
<item>
<title>AtABC174C-模运算</title>
<link>https://luosuu.github.io/post/atabc174_c/</link>
<pubDate>Tue, 04 Aug 2020 17:04:51 +0800</pubDate>
<guid>https://luosuu.github.io/post/atabc174_c/</guid>
<description><p>题面:https://atcoder.jp/contests/abc174/tasks/abc174_c</p>
<p>本题可以简单化简 $$ K \cdot a=7 \cdot \frac{1-10^n}{1-10} $$</p>
<p>等同于 $$ K \cdot a \cdot 9=7 \cdot (10^n-1) $$</p>
<p>a是K的倍数,n为被除数的位数,n即为所求。只要右侧式能够整除9K(a是个整数),那么就满足要求。</p>
<p>于是调试n,用右侧式对左侧进行取模操作即可。</p>
<p>但计算过程中有$10^n$的限制,可能会超过<code>long long </code>数据的最大值。</p>
<p>这里要引出取模运算的运算规则</p>
<pre><code>(a+b)%p=(a%p+b%p)%p
(a-b)%p=(a%p-b%p)%p
(a*b%p)=(a%p * b%p)%p
(a^b)%p=((a%p)^b)%p
</code></pre><p>观察右侧式,先抛去7这个乘数,它的变化应该是</p>
<pre><code>9
99
999
...
</code></pre><p>可以表示为</p>
<pre><code>d(0)=9
d(1)=d(0)*10+9
d(2)=d(1)*10+9
...
d(n)=d(n-1)*10+9
</code></pre><p>现在要求<code>d(n)</code>能不能整除<code>9K</code>,可以递推式的表达,这样循环中每一次验证都只需要一次计算。</p>
<p>最后考虑停机条件,时间限制为2s,以CPU 1GHz的速度来考虑,保守的可以设置停机条件为2e7。如果2e7位数还没有找到,大概率是没有了。</p>
<p>完整的代码可以写为</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-C++" data-lang="C++"><span style="color:#75715e">#include</span> <span style="color:#75715e">&lt;iostream&gt;</span><span style="color:#75715e">
</span><span style="color:#75715e"></span><span style="color:#66d9ef">using</span> <span style="color:#66d9ef">namespace</span> std;
<span style="color:#66d9ef">int</span> <span style="color:#a6e22e">main</span>() {
<span style="color:#66d9ef">long</span> <span style="color:#66d9ef">int</span> K;
cin <span style="color:#f92672">&gt;&gt;</span> K;
<span style="color:#66d9ef">long</span> <span style="color:#66d9ef">int</span> s <span style="color:#f92672">=</span> <span style="color:#ae81ff">9</span> <span style="color:#f92672">*</span> K;
<span style="color:#66d9ef">if</span>(K <span style="color:#f92672">%</span> <span style="color:#ae81ff">2</span> <span style="color:#f92672">==</span> <span style="color:#ae81ff">0</span> <span style="color:#f92672">||</span> K <span style="color:#f92672">%</span> <span style="color:#ae81ff">5</span> <span style="color:#f92672">==</span> <span style="color:#ae81ff">0</span>){
cout <span style="color:#f92672">&lt;&lt;</span> <span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>;
<span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
}
<span style="color:#66d9ef">long</span> <span style="color:#66d9ef">int</span> d <span style="color:#f92672">=</span> <span style="color:#ae81ff">9</span>;
<span style="color:#66d9ef">for</span>(<span style="color:#66d9ef">long</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>;i<span style="color:#f92672">&lt;</span><span style="color:#ae81ff">20000000</span>;i<span style="color:#f92672">++</span>){
<span style="color:#66d9ef">if</span>((<span style="color:#ae81ff">7</span><span style="color:#f92672">*</span>d)<span style="color:#f92672">%</span>s<span style="color:#f92672">==</span><span style="color:#ae81ff">0</span>){
cout <span style="color:#f92672">&lt;&lt;</span> i;
<span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
}
d <span style="color:#f92672">=</span> (d<span style="color:#f92672">*</span><span style="color:#ae81ff">10</span><span style="color:#f92672">+</span><span style="color:#ae81ff">9</span>)<span style="color:#f92672">%</span>s;
}
cout <span style="color:#f92672">&lt;&lt;</span> <span style="color:#f92672">-</span><span style="color:#ae81ff">1</span>;
<span style="color:#66d9ef">return</span> <span style="color:#ae81ff">0</span>;
}
</code></pre></div><h3 id="one-more-thing">one more thing</h3>
<p>关于模运算有很多有趣的知识,其中一些在OJ中经常常用,快速幂就是其中一个。</p>
<p>快速幂的全称是“快速计算一个幂式的模(余)”</p>
<p>假如我们要计算<code>a^b mod c</code></p>
<p>如果我们直接算</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-c++" data-lang="c++"><span style="color:#66d9ef">int</span> ans <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>;
<span style="color:#66d9ef">for</span>(<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>;i<span style="color:#f92672">&lt;=</span>b;i<span style="color:#f92672">++</span>)
{
ans <span style="color:#f92672">=</span> ans <span style="color:#f92672">*</span> a;
}
ans <span style="color:#f92672">=</span> ans <span style="color:#f92672">%</span> c;
</code></pre></div><p>那么当b比较大的时候,<code>long long </code>也是撑不住的,数据会溢出。</p>
<p>可以根据模运算的性质<code>(a^b)%p=((a%p)^b)%p</code></p>
<p>在算指数之前先取模,这样可以小一些</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-c++" data-lang="c++"><span style="color:#66d9ef">int</span> ans <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>;
a <span style="color:#f92672">=</span> a <span style="color:#f92672">%</span> c;
<span style="color:#66d9ef">for</span>(<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>;i<span style="color:#f92672">&lt;=</span>b;i<span style="color:#f92672">++</span>)
{
ans <span style="color:#f92672">=</span> ans <span style="color:#f92672">*</span> a;
}
ans <span style="color:#f92672">=</span> ans <span style="color:#f92672">%</span> c;
</code></pre></div><p>如果一个因子取余不影响最终结果,那么中间的因子取余应该也是不影响结果的(反正最后都被消掉,可以在计算指数的过程中消掉)</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-c++" data-lang="c++"><span style="color:#66d9ef">int</span> ans <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>;
a <span style="color:#f92672">=</span> a <span style="color:#f92672">%</span> c;
<span style="color:#66d9ef">for</span>(<span style="color:#66d9ef">int</span> i <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>;i<span style="color:#f92672">&lt;=</span>b;i<span style="color:#f92672">++</span>)
{
ans <span style="color:#f92672">=</span> (ans <span style="color:#f92672">*</span> a)<span style="color:#f92672">%</span>c;
}
ans <span style="color:#f92672">=</span> ans <span style="color:#f92672">%</span> c;
</code></pre></div><p>现在已经比最开始好很多了,但现在的复杂度式还是<code>O(b)</code>,当b比较大的时候还是有可能超时。</p>
<p>也就是问题出现在求指数的过程中,这里要考虑到如何快速计算幂式,我们可以这样考虑
$$
2^{1000}=4^{500}
$$
底数做一次平方,运算次数少了一半,如果是奇数
$$
2^{1001}=4^{500}*2
$$
现在先不考虑幂式求模余的问题,如果单纯要求快速计算<code>a^b</code></p>
<p>方法应该是这样的</p>
<p>当指数b是偶数时,平方底数,指数b自除2;</p>
<p>当指数b是奇数时,先用一个数才收集落单的底数,然后平方底数,b自减1再除2。</p>
<p>最后除到b为1的时候,用于收集落单的底数的数就会乘以最后的底,从而变成最终结果。</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-c++" data-lang="c++"><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">QuickPower</span>(<span style="color:#66d9ef">int</span> a,<span style="color:#66d9ef">int</span> b){
<span style="color:#66d9ef">int</span> result <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>;
<span style="color:#66d9ef">while</span>(b<span style="color:#f92672">&gt;</span><span style="color:#ae81ff">0</span>){
<span style="color:#66d9ef">if</span>(b <span style="color:#f92672">%</span> <span style="color:#ae81ff">2</span> <span style="color:#f92672">==</span> <span style="color:#ae81ff">1</span>){
result <span style="color:#f92672">=</span> result<span style="color:#f92672">*</span>a;
b <span style="color:#f92672">=</span> b <span style="color:#f92672">-</span> <span style="color:#ae81ff">1</span>;
}
b <span style="color:#f92672">=</span> b<span style="color:#f92672">/</span><span style="color:#ae81ff">2</span>;
a <span style="color:#f92672">=</span> a <span style="color:#f92672">*</span> a;
}
}
</code></pre></div><p>如何应用在求幂式的模余中呢?应该是很简单的。</p>
<p>当指数b是偶数时,平方底数,指数b自除2;</p>
<p>当指数b是奇数时,先让ans乘以底数a(这里可以对c取模优化),用于收集落单的底数,然后平方底数,b自减1再除2。</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-c++" data-lang="c++"><span style="color:#66d9ef">int</span> <span style="color:#a6e22e">PowerMod</span>(<span style="color:#66d9ef">int</span> a, <span style="color:#66d9ef">int</span> b, <span style="color:#66d9ef">int</span> c)
{
<span style="color:#66d9ef">int</span> ans <span style="color:#f92672">=</span> <span style="color:#ae81ff">1</span>;
a <span style="color:#f92672">=</span> a <span style="color:#f92672">%</span> c;
<span style="color:#66d9ef">while</span>(b<span style="color:#f92672">&gt;</span><span style="color:#ae81ff">0</span>) {
<span style="color:#66d9ef">if</span>(b <span style="color:#f92672">%</span> <span style="color:#ae81ff">2</span> <span style="color:#f92672">==</span> <span style="color:#ae81ff">1</span>){
ans <span style="color:#f92672">=</span> (ans <span style="color:#f92672">*</span> a) <span style="color:#f92672">%</span> c;
}
<span style="color:#75715e">//由于是整形,不减1直接除二也是可以的
</span><span style="color:#75715e"></span> b <span style="color:#f92672">=</span> b<span style="color:#f92672">/</span><span style="color:#ae81ff">2</span>;
<span style="color:#75715e">// 下面这种写法也是可以的,右移操作也是可以实现除二,并且自动舍去了余数(就是对整数这样操作不tidy)
</span><span style="color:#75715e"></span> <span style="color:#75715e">// b = b &gt;&gt; 1
</span><span style="color:#75715e"></span> a <span style="color:#f92672">=</span> (a <span style="color:#f92672">*</span> a) <span style="color:#f92672">%</span> c;
}
<span style="color:#66d9ef">return</span> ans;
}
</code></pre></div></description>
</item>
<item>
<title>微信小程序开发训练营</title>
<link>https://luosuu.github.io/post/wx-miniprogram-tips/</link>
<pubDate>Wed, 29 Jul 2020 18:53:26 +0800</pubDate>
<guid>https://luosuu.github.io/post/wx-miniprogram-tips/</guid>
<description><p>最近参加了腾讯微信小程序开发训练营,记录一些有趣的点。</p>
<p>参考文档:</p>
<p><a href="https://cloudbase.net/community/guides/handbook/index.html">腾讯云开发训练营</a></p>
<p><a href="https://developers.weixin.qq.com/miniprogram/dev/framework/">微信小程序开放文档</a></p>
<h2 id="用户登陆">用户登陆</h2>
<p>登陆方式有很多种,可以用<code>wx.login</code>登陆,也可以使用云函数登陆 。所谓云函数,是在云端运行的代码,由微信私有协议天然鉴权,开发者只需编写业务逻辑代码。如果我们想对不同的用户有不同的记录,区分不同的用户的方式就是获取他们的<code>openid</code>。由服务器端云函数返回用户<code>openid</code>是简单的。在创建小程序项目时,选择基于云的小程序,其中的<code>cloudfunctions/login</code>就是登陆函数。</p>
<p><img src="https://luosuu.github.io/image-20200730111044048.png" alt="image-20200730111044048"></p>
<p>以下是<code>login</code>云函数的主要内容</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-js" data-lang="js"><span style="color:#75715e">// 云函数模板
</span><span style="color:#75715e">// 部署:在 cloud-functions/login 文件夹右击选择 “上传并部署”
</span><span style="color:#75715e"></span><span style="color:#66d9ef">const</span> <span style="color:#a6e22e">cloud</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">require</span>(<span style="color:#e6db74">&#39;wx-server-sdk&#39;</span>)
<span style="color:#75715e">// 初始化 cloud
</span><span style="color:#75715e"></span><span style="color:#a6e22e">cloud</span>.<span style="color:#a6e22e">init</span>({
<span style="color:#75715e">// API 调用都保持和云函数当前所在环境一致
</span><span style="color:#75715e"></span> <span style="color:#a6e22e">env</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">cloud</span>.<span style="color:#a6e22e">DYNAMIC_CURRENT_ENV</span>
})
<span style="color:#75715e">/**
</span><span style="color:#75715e"> * 这个示例将经自动鉴权过的小程序用户 openid 返回给小程序端
</span><span style="color:#75715e"> *
</span><span style="color:#75715e"> * event 参数包含小程序端调用传入的 data
</span><span style="color:#75715e"> *
</span><span style="color:#75715e"> */</span>
<span style="color:#a6e22e">exports</span>.<span style="color:#a6e22e">main</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">async</span> (<span style="color:#a6e22e">event</span>, <span style="color:#a6e22e">context</span>) =&gt; {
<span style="color:#75715e">// 可执行其他自定义逻辑
</span><span style="color:#75715e"></span> <span style="color:#75715e">// console.log 的内容可以在云开发云函数调用日志查看
</span><span style="color:#75715e"></span> <span style="color:#75715e">// 获取 WX Context (微信调用上下文),包括 OPENID、APPID、及 UNIONID(需满足 UNIONID 获取条件)等信息
</span><span style="color:#75715e"></span> <span style="color:#66d9ef">const</span> <span style="color:#a6e22e">wxContext</span> <span style="color:#f92672">=</span> <span style="color:#a6e22e">cloud</span>.<span style="color:#a6e22e">getWXContext</span>()
<span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#e6db74">&#39;getWXContext返回的结果&#39;</span>,<span style="color:#a6e22e">wxContext</span>)
<span style="color:#66d9ef">return</span> {
<span style="color:#a6e22e">event</span>,
<span style="color:#a6e22e">openid</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">wxContext</span>.<span style="color:#a6e22e">OPENID</span>,
<span style="color:#a6e22e">appid</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">wxContext</span>.<span style="color:#a6e22e">APPID</span>,
<span style="color:#a6e22e">unionid</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">wxContext</span>.<span style="color:#a6e22e">UNIONID</span>,
<span style="color:#a6e22e">env</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">wxContext</span>.<span style="color:#a6e22e">ENV</span>,
}
}
</code></pre></div><p>下面是一个使用云函数登陆的示例代码</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-javascript" data-lang="javascript"><span style="color:#a6e22e">wx</span>.<span style="color:#a6e22e">cloud</span>.<span style="color:#a6e22e">callFunction</span>({
<span style="color:#a6e22e">name</span><span style="color:#f92672">:</span><span style="color:#e6db74">&#39;login&#39;</span>,
<span style="color:#a6e22e">data</span><span style="color:#f92672">:</span>{},
<span style="color:#a6e22e">succeess</span><span style="color:#f92672">:</span><span style="color:#a6e22e">res</span>=&gt;{
<span style="color:#75715e">//登陆成功后的处理,其中回调函数的res.result.openid就是云端返回的用户openid
</span><span style="color:#75715e"></span> <span style="color:#75715e">//在云端存储用户信息
</span><span style="color:#75715e"></span> <span style="color:#a6e22e">wx</span>.<span style="color:#a6e22e">cloud</span>.<span style="color:#a6e22e">callFunction</span>({
<span style="color:#a6e22e">name</span><span style="color:#f92672">:</span><span style="color:#e6db74">&#39;setUserInfo&#39;</span>
<span style="color:#a6e22e">data</span><span style="color:#f92672">:</span>{
<span style="color:#a6e22e">userid</span><span style="color:#f92672">:</span><span style="color:#a6e22e">res</span>.<span style="color:#a6e22e">result</span>.<span style="color:#a6e22e">openid</span>
<span style="color:#75715e">//其他参数
</span><span style="color:#75715e"></span> <span style="color:#75715e">//....
</span><span style="color:#75715e"></span> }
})
}
})
</code></pre></div><h2 id="文件存储">文件存储</h2>
<p>微信小程序支持本地缓存储存文件,也支持云存储文件。缓存文件只在用户小程序端存在,可以用来缓存用户个人信息等,云存储的文件可以用云开发控制台直接上传,获取<code>cloud://</code>开头的路径,就可以在小程序中直接使用了。</p>
<p>当然我们也可以让用户上传文件,其中一种方式就是将本地的临时文件上传到云端,要使用<code>wx.cloud.uploadFile</code></p>
<p>cloudPath是文件在云端的路径,我们可以指定。</p>
<p>filePath是本地临时文件的路径。</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-javascript" data-lang="javascript"> <span style="color:#a6e22e">uploadFiles</span>(<span style="color:#a6e22e">e</span>) {
<span style="color:#66d9ef">const</span> <span style="color:#a6e22e">filePath</span> <span style="color:#f92672">=</span> <span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">data</span>.<span style="color:#a6e22e">files</span>[<span style="color:#ae81ff">0</span>].<span style="color:#a6e22e">src</span>
<span style="color:#66d9ef">const</span> <span style="color:#a6e22e">cloudPath</span> <span style="color:#f92672">=</span> <span style="color:#e6db74">`cloudbase/</span><span style="color:#e6db74">${</span>Date.<span style="color:#a6e22e">now</span>()<span style="color:#e6db74">}</span><span style="color:#e6db74">-</span><span style="color:#e6db74">${</span>Math.<span style="color:#a6e22e">floor</span>(Math.<span style="color:#a6e22e">random</span>(<span style="color:#ae81ff">0</span>, <span style="color:#ae81ff">1</span>) <span style="color:#f92672">*</span> <span style="color:#ae81ff">1000</span>)<span style="color:#e6db74">}</span><span style="color:#e6db74">`</span> <span style="color:#f92672">+</span> <span style="color:#a6e22e">filePath</span>.<span style="color:#a6e22e">match</span>(<span style="color:#e6db74">/\.[^.]+?$/</span>)
<span style="color:#a6e22e">wx</span>.<span style="color:#a6e22e">cloud</span>.<span style="color:#a6e22e">uploadFile</span>({
<span style="color:#a6e22e">cloudPath</span>,<span style="color:#a6e22e">filePath</span>
}).<span style="color:#a6e22e">then</span>(<span style="color:#a6e22e">res</span> =&gt; {
<span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">setData</span>({
<span style="color:#a6e22e">fileID</span><span style="color:#f92672">:</span><span style="color:#a6e22e">res</span>.<span style="color:#a6e22e">fileID</span>
})
}).<span style="color:#66d9ef">catch</span>(<span style="color:#a6e22e">error</span> =&gt; {
<span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#e6db74">&#34;文件上传失败&#34;</span>,<span style="color:#a6e22e">error</span>)
})
},
</code></pre></div><h2 id="生命周期">生命周期</h2>
<p>有时候我们需要数据跨页面渲染,我们当然可以全部都存储到云端然后读取、处理,但是也可以使用url带数据的方式将数据传递到下一个页面。</p>
<p>对于一个链接来说</p>
<ul>
<li>/ 分隔目录和子目录</li>
<li>? 分隔实际的 URL 和参数</li>
<li>&amp; URL 中指定的参数间的分隔符</li>
<li>= URL 中指定的参数的值</li>
</ul>
<p>以下面这个链接为例</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-html" data-lang="html">&lt;<span style="color:#f92672">navigator</span> <span style="color:#a6e22e">url</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;./../home/detail/detail?id={{index}}&amp;name={{movies.name}}&amp;img={{movies.img}}&amp;desc={{movies.desc}}&#34;</span> <span style="color:#a6e22e">class</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;weui-media-box weui-media-box_appmsg&#34;</span> <span style="color:#a6e22e">hover-class</span><span style="color:#f92672">=</span><span style="color:#e6db74">&#34;weui-cell_active&#34;</span>&gt;
</code></pre></div><p>这是一个跳转链接,跳转到<code>home/detail/detail</code>页面,传递了变量<code>id</code>,<code>name</code>,<code>img</code>,<code>desc</code>。这些变量的值都在对应的本页面的js文件中定义。</p>
<p>然后我们可以在跳转目标页面的js文件里,在<code>onLoad</code>中获得到这些变量,并赋给需要的地方,比如</p>
<div class="highlight"><pre style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4"><code class="language-javascript" data-lang="javascript"><span style="color:#a6e22e">onLoad</span><span style="color:#f92672">:</span> <span style="color:#66d9ef">function</span> (<span style="color:#a6e22e">options</span>) {
<span style="color:#a6e22e">console</span>.<span style="color:#a6e22e">log</span>(<span style="color:#a6e22e">options</span>)
<span style="color:#a6e22e">wx</span>.<span style="color:#a6e22e">setNavigationBarTitle</span>({
<span style="color:#a6e22e">title</span><span style="color:#f92672">:</span> <span style="color:#a6e22e">options</span>.<span style="color:#a6e22e">name</span>
})
<span style="color:#66d9ef">this</span>.<span style="color:#a6e22e">setData</span>({
<span style="color:#a6e22e">detail</span> <span style="color:#f92672">:</span> <span style="color:#a6e22e">options</span>,
})
},
</code></pre></div><h2 id="一丢丢心得">一丢丢心得</h2>
<p>微信小程序开发主要还是需要熟悉微信小程序开发的框架与规定(与angularJs框架类似),虽然一个功能逻辑可以有很多种写法,但是有很多既定的推荐写法可以借鉴。</p>
<p>云函数的开发要对各种API比较熟悉,不同的小程序之间可以方便的复用。但是我对云函数的调试并不满意,虽然提供了本地调试的选项,用起来也不是特别的方便。最后要吐槽很多功能的表现在电脑的开发者工具上预览的效果与手机实际效果是有不少差距的,debug的时候也很麻烦。</p></description>
</item>
<item>
<title>Always Know What Is Important</title>
<link>https://luosuu.github.io/post/always-know-what-is-important/</link>
<pubDate>Fri, 27 Mar 2020 12:00:09 +0800</pubDate>
<guid>https://luosuu.github.io/post/always-know-what-is-important/</guid>
<description><p>整理心情,重新出发</p>
<p>我身边的朋友可能知道我最近遭遇了一点小挫折,大学道路陷入了一些迷茫。开下自己的玩笑,就是又“焦虑”了。</p>
<p>然而高帆学长应该是在他无意之间,给我了很大的帮助。让我重新认识到我想要从事程序语言(PL)方向的初心,并认识到自己的规划的不合理之处。感谢学长的鞭策。</p>
<p>这里我想重新谈一下sicp,当初读sicp是看重了两方面,一方面是想打基础修内功,另一方面是作为MIT的基础课程,上手难度不会太大。王垠前辈有一篇博客,讲的是<a href="http://www.yinwang.org/blog-cn/2012/08/01/interpreter">如何构造自己的解释器</a>。其中sicp的第一二章为先修内容。</p>
<p>我曾经过分看重“如何设计一个语言”,“如何构造一个编译器”这种过于“落地”的问题,却忽略了内核,忽略了最开始我入坑的兴趣点。另外,我也太过于容易受旁人的影响,盲目去崇拜龙书、虎书等,并将编译器的工作和PL的工作混淆起来。</p>
<p>国内的很多教材重视所谓“前端”,包括龙书在内将parser技术长篇大论。然正如<a href="http://www.yinwang.org/blog-cn/2015/09/19/parser">对 Parser 的误解</a>里王垠所言,语义转化和优化才是精华的内容,才是软件的核心。学习不是为了解决人为制造的困难而显得高级,而是为了理解其中的原理。如此“头重脚轻”,增大了学习的困难,消磨了学习的热情。</p>
<p>我在上篇博客整理了下PL相关的学习内容,再结合我“烂尾”的Todo,我学习的优先顺序应该为:</p>
<ol>
<li>南京大学《软件分析》课程</li>
<li>SICP</li>
<li>EOPL</li>
</ol>
<p>这个学期内,能够完成这些内容,可以说是善莫大焉。理解了核心的概念和理念之后,再去看编译器的构造一类,就是工程上的细枝末节和摸索了。</p>
<p>最后想谈一下国内PL界的风云人物,有很多人确实是受大佬影响而了解的,但也终要能做出他们的影子,独立的思考与研究,真的找到自己感兴趣的内容和关键点才行,而不是大佬在做什么,我就想了解什么,想学什么。大佬之所以为大佬,是因为他们有由衷的热爱和踏实的努力。最后,还是要靠实力说话的。要看清自己该踏踏实实走的路,也莫要想走什么捷径。</p></description>