-
Notifications
You must be signed in to change notification settings - Fork 1
/
lan-qiao-bei-li-jie-shi-ti-k-bei-qu-jian-shu-c-yu-yan.html
1813 lines (1330 loc) · 59.3 KB
/
lan-qiao-bei-li-jie-shi-ti-k-bei-qu-jian-shu-c-yu-yan.html
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
<!DOCTYPE HTML>
<html lang="zh-CN">
<head><meta name="generator" content="Hexo 3.9.0">
<meta charset="utf-8">
<meta name="keywords" content="蓝桥杯历届试题K倍区间数(C语言), IT学习">
<meta name="description" content=" K&#x500D;&#x533A;&#x95F4;&#x6570; &#x95EE;&#x9898;&#">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=no">
<meta name="renderer" content="webkit|ie-stand|ie-comp">
<meta name="mobile-web-app-capable" content="yes">
<meta name="format-detection" content="telephone=no">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent">
<title>蓝桥杯历届试题K倍区间数(C语言) | IT学习</title>
<link rel="icon" type="image/png" href="/favicon.png">
<link rel="stylesheet" type="text/css" href="/libs/awesome/css/font-awesome.min.css">
<link rel="stylesheet" type="text/css" href="/libs/materialize/materialize.min.css">
<link rel="stylesheet" type="text/css" href="/libs/aos/aos.css">
<link rel="stylesheet" type="text/css" href="/libs/animate/animate.min.css">
<link rel="stylesheet" type="text/css" href="/libs/lightGallery/css/lightgallery.min.css">
<link rel="stylesheet" type="text/css" href="/css/matery.css">
<link rel="stylesheet" type="text/css" href="/css/my.css">
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css">
<style type="text/css">
</style>
<div id="fv_loading">
<div class="fv_loadingBorder2"><div class="fv_loadingBorder3"><div class="fv_loadingBorder"></div></div></div>
<div class="fv_bounce">
<span class="fv_letter"><br><br><br>F</span>
<span class="fv_letter"><br><br><br>i</span>
<span class="fv_letter"><br><br><br>v</span>
<span class="fv_letter"><br><br><br>e</span>
<span class="fv_letter"><br><br><br>-</span>
<span class="fv_letter"><br><br><br>gr</span>
<span class="fv_letter"><br><br><br>ea</span>
<span class="fv_letter"><br><br><br>t</span>
<div>
</div>
<script src="/libs/jquery/jquery-2.2.0.min.js"></script>
<!--百度统计代码-->
<script>
var _hmt = _hmt || [];
(function() {
var hm = document.createElement("script");
hm.src = "https://hm.baidu.com/hm.js?cc6f0804a30e83a31b6140fbfab1897b";
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(hm, s);
})();
</script>
<!--推送-->
<script>
(function(){
var bp = document.createElement('script');
var curProtocol = window.location.protocol.split(':')[0];
if (curProtocol === 'https'){
bp.src = 'https://zz.bdstatic.com/linksubmit/push.js';
}
else{
bp.src = 'http://push.zhanzhang.baidu.com/push.js';
}
var s = document.getElementsByTagName("script")[0];
s.parentNode.insertBefore(bp, s);
})();
</script>
<!--广告-->
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
<script>
(adsbygoogle = window.adsbygoogle || []).push({
google_ad_client: "ca-pub-4200955217986403",
enable_page_level_ads: true
});
</script>
</div></div></head>
<body>
<style>
@media only screen and (max-width: 422px){
nav .brand-logo {left: 41%;}
nav a {margin: 0px 0px 0px 0px;}
nav ul a {padding: 0px;}
.bg-cover .title{fone-size:3rem;}
}
</style>
<header class="navbar-fixed">
<nav id="headNav" class="bg-color nav-transparent">
<div id="navContainer" class="nav-wrapper container">
<div class="brand-logo" >
<a href="/" class="waves-effect waves-light">
<img src="/medias/logo.png" class="logo-img" alt="LOGO">
<span class="logo-span">IT学习</span>
</a>
</div>
<a href="#" data-target="mobile-nav" class="sidenav-trigger button-collapse"><i class="fa fa-navicon"></i></a>
<ul class="right nav-menu">
<li class="hide-on-med-and-down nav-item" >
<a href="/" class="waves-effect waves-light">
<i class="fa fa-home"></i>
<span>首页</span>
</a>
</li>
<li class="hide-on-med-and-down nav-item" >
<a href="/tags" class="waves-effect waves-light">
<i class="fa fa-tags"></i>
<span>标签</span>
</a>
</li>
<li class="hide-on-med-and-down nav-item" >
<a href="/categories" class="waves-effect waves-light">
<i class="fa fa-bookmark"></i>
<span>分类</span>
</a>
</li>
<li class="hide-on-med-and-down nav-item" >
<a href="/archives" class="waves-effect waves-light">
<i class="fa fa-archive"></i>
<span>归档</span>
</a>
</li>
<li class="hide-on-med-and-down nav-item" >
<a href="/about" class="waves-effect waves-light">
<i class="fa fa-user-circle-o"></i>
<span>关于</span>
<i class="fa fa-chevron-down" aria-hidden="true"></i>
</a>
<ul class="sub-nav menus_item_child ">
<li>
<a href="/about" >
<i class="fa fa-user-circle-o" style="margin-top: -20px;"></i>
<span>自我介绍</span>
</a>
</li>
<li>
<a href="https://github.com/Five-great/" >
<i class="fa fa-github" style="margin-top: -20px;"></i>
<span>Github</span>
</a>
</li>
</ul>
</li>
<li class="hide-on-med-and-down nav-item" >
<a href="/lyb" class="waves-effect waves-light">
<i class="fa fa-paper-plane-o"></i>
<span>留言板</span>
</a>
</li>
<li class="hide-on-med-and-down nav-item" >
<a href="/friends" class="waves-effect waves-light">
<i class="fa fa-address-book"></i>
<span>友情链接</span>
</a>
</li>
<li>
<a href="#searchModal" class="modal-trigger waves-effect waves-light">
<i id="searchIcon" class="fa fa-search" title="搜索"></i>
</a>
</li>
</ul>
<div id="mobile-nav" class="side-nav sidenav">
<div class="mobile-head bg-color">
<img src="/medias/logo.png" class="logo-img circle responsive-img">
<div class="logo-name">IT学习</div>
<div class="logo-desc">
有事多研究 没事多琢磨
</div>
</div>
<ul class="menu-list mobile-menu-list">
<li class="m-nav-item">
<a href="/" class="waves-effect waves-light">
<i class="fa fa-fw fa-home"></i>
首页
</a>
</li>
<li class="m-nav-item">
<a href="/tags" class="waves-effect waves-light">
<i class="fa fa-fw fa-tags"></i>
标签
</a>
</li>
<li class="m-nav-item">
<a href="/categories" class="waves-effect waves-light">
<i class="fa fa-fw fa-bookmark"></i>
分类
</a>
</li>
<li class="m-nav-item">
<a href="/archives" class="waves-effect waves-light">
<i class="fa fa-fw fa-archive"></i>
归档
</a>
</li>
<li class="m-nav-item">
<a href="javascript:;">
<i class="fa fa-fw fa-user-circle-o"></i>
关于
<span class="m-icon"><i class="fa fa-chevron-right"></i></span>
</a>
<ul >
<li>
<a href="/about " style="margin-left:75px";>
<i class="fa fa-user-circle-o" style="position: absolute;left:50px" ></i>
<span>自我介绍</span>
</a>
</li>
<li>
<a href="https://github.com/Five-great/ " style="margin-left:75px";>
<i class="fa fa-github" style="position: absolute;left:50px" ></i>
<span>Github</span>
</a>
</li>
</ul>
</li>
<li class="m-nav-item">
<a href="/lyb" class="waves-effect waves-light">
<i class="fa fa-fw fa-paper-plane-o"></i>
留言板
</a>
</li>
<li class="m-nav-item">
<a href="/friends" class="waves-effect waves-light">
<i class="fa fa-fw fa-address-book"></i>
友情链接
</a>
</li>
</ul>
</div>
</div>
</nav>
</header>
<head><meta name="generator" content="Hexo 3.9.0">
<style>
*{
margin: 0;
padding: 0;
}
#canvas111{
position: fixed;
background: #ccc;
overflow: auto;
z-index: -1;
}
</style>
<canvas id="canvas111"></canvas>
<link rel="stylesheet" href="/css/prism-tomorrow.css" type="text/css"></head>
<body>
</body>
<script>
window.requestAnimationFrame = (function(){
return window.requestAnimationFrame ||
window.webkitRequestAnimationFrame ||
window.mozRequestAnimationFrame ||
function( callback ){
window.setTimeout( callback, 1000/2 );
};
})();
var myCanvas = document.getElementById("canvas111");
var ctx = myCanvas.getContext("2d");//getContext 设置画笔
var num;
var w,h;
var duixiang = [];
var move = {};
function widthheight(){
w = myCanvas.width = window.innerWidth;
h = myCanvas.height = window.innerHeight;
num= Math.floor(w*h*0.0001);
for(var i = 0;i < num;i++){
duixiang[i] = {
x:Math.random()*w,
y:Math.random()*h,
cX:Math.random()*0.6-0.3,
cY:Math.random()*0.6-0.3,
R:Math.floor(Math.random()*5)+2,
//CC:Math.floor(Math.random()*3)+2,
r: Math.floor(Math.random() * 254),
g: Math.floor(Math.random() * 254),
b:Math.floor(Math.random() * 254)
}
// console.log(duixiang[i])
Cricle(duixiang[i].x,duixiang[i].y,duixiang[i].R,duixiang[i].r,duixiang[i].g,duixiang[i].b);
//Cricle(duixiang[i].x,duixiang[i].y,duixiang[i].R,duixiang[i].CC);
}
};widthheight();//获取浏览器的等宽度等高
function Cricle(x,y,R,r,g,b){
ctx.save();//保存路径
if(Math.random()>0.991) {ctx.globalAlpha= 0.9;}//ctx.fillStyle = "#CCC";}//填充的背景颜色
else { ctx.globalAlpha=0.47;}
ctx.fillStyle = "rgb("+ r +","+ g +","+ b +")";
ctx.beginPath();//开始绘画
ctx.arc(x,y,R,Math.PI*2,0);//绘画圆 x y 半径(大小) 角度 一个PI 是180 * 2 = 360 真假 0/1 true/false
ctx.closePath();//结束绘画
ctx.fill();//填充背景颜色
ctx.restore();//回复路径
};Cricle();
!function draw(){
ctx.clearRect(0,0,w,h)//先清除画布上的点
for(var i = 0;i < num;i++){
duixiang[i].x += duixiang[i].cX;
duixiang[i].y += duixiang[i].cY;
if(duixiang[i].x>w || duixiang[i].x<0){
duixiang[i].cX = -duixiang[i].cX;
}
if(duixiang[i].y>h || duixiang[i].y<0){
duixiang[i].cY = -duixiang[i].cY;
}
Cricle(duixiang[i].x,duixiang[i].y,duixiang[i].R,duixiang[i].r,duixiang[i].g,duixiang[i].b);
//勾股定理判断两点是否连线
for(var j = i + 1;j < num;j++){
if( (duixiang[i].x-duixiang[j].x)*(duixiang[i].x-duixiang[j].x)+(duixiang[i].y-duixiang[j].y)*(duixiang[i].y-duixiang[j].y) <= 55*55 ){
line(duixiang[i].x,duixiang[i].y,duixiang[j].x,duixiang[j].y,0,i,j)
}
if(move.x){
if( (duixiang[i].x-move.x)*(duixiang[i].x-move.x)+(duixiang[i].y-move.y)*(duixiang[i].y-move.y) <= 100*100 ){
line(duixiang[i].x,duixiang[i].y,move.x,move.y,1,i,1)
}
}
}
}
window.requestAnimationFrame(draw)
}();
//绘制线条
function line(x1,y1,x2,y2,flag,i,j){
if (flag){var color = ctx.createLinearGradient(x1,y1,x2,y2);
ctx.globalAlpha=0.5;
color.addColorStop(0,"rgb("+ duixiang[i].r +","+ duixiang[i].g +","+ duixiang[i].b +")");
color.addColorStop(0.8,"#019ee5");
}
else
{
var color = ctx.createLinearGradient(x1,y1,x2,y2);
ctx.globalAlpha=0.9;
color.addColorStop(0,"rgb("+ duixiang[i].r +","+ duixiang[i].g +","+ duixiang[i].b +")");
color.addColorStop(1,"rgb("+ duixiang[j].r +","+ duixiang[j].g +","+ duixiang[j].b +")");
}
ctx.save();
ctx.strokeStyle = color;
ctx.lineWidth = 0.5;
ctx.beginPath();
ctx.moveTo(x1,y1);
ctx.lineTo(x2,y2);
ctx.stroke();
//ctx.restore();
}
//document.onmousemove = function(e){
// move.x = e.clientX;
// move.y = e.clientY;
//}
//console.log(move)
/*window.onresize = function(){
location.reload();
}*/
</script>
<style>
#canvas1 {
position: fixed;
pointer-events:none;//鼠标多层响应事件
// background: #ccc;
/*透明度*/
width: 100%;
height: 100%;
// opacity: 0;
overflow: auto;
z-index: 999;
}
</style>
<body>
<canvas id="canvas1" style="whdth: 100%;height: 100%"></canvas>
<script>
var _createClass = function () {function defineProperties(target, props)
{ for (var i = 0; i < props.length; i++)
{var descriptor = props[i];descriptor.enumerable = descriptor.enumerable || false;descriptor.configurable = true;if ("value" in descriptor)
descriptor.writable = true;Object.defineProperty(target, descriptor.key, descriptor);}}
return function (Constructor, protoProps, staticProps)
{if (protoProps) defineProperties(Constructor.prototype, protoProps);
if (staticProps) defineProperties(Constructor, staticProps);
return Constructor;};}();function _classCallCheck(instance, Constructor)
{if (!(instance instanceof Constructor)) {throw new TypeError("Cannot call a class as a function");}}
var getRandom = function getRandom(min, max) {
return Math.random() * (max - min) + min;
};
var getRandomInt = function getRandomInt(min, max) {
return Math.floor(Math.random() * (max - min)) + min;
};
var getRandomColor = function getRandomColor() {
var colors = [
'rgba(231, 76, 60, 1)', // red
'rgba(241, 196, 15, 1)', // yellow
'rgba(46, 204, 113, 1)', // green
'rgba(52, 152, 219, 1)', // blue
'rgba(155, 89, 182, 1)' // purple
];
return colors[getRandomInt(0, colors.length)];
};
// Particle//粒子模块
var
Particle = function () {
function Particle(system, x, y) {_classCallCheck(this, Particle);
this.system = system;
this.universe = this.system.world.universe;
this.x = x;
this.y = y;
this.color = getRandomColor();
this.life = 1;
this.aging = getRandom(0.990, 0.999); // 0.99, 0.999 || 0.999, 0.9999
this.r = getRandomInt(12, 16);//初始粒子半径范围
this.speed = getRandom(18, 18.5);//粒子爆炸速度范围
this.velocity = [
getRandom(-this.speed, this.speed),
getRandom(-this.speed, this.speed)];
}_createClass(Particle, [{ key: 'update', value: function update(
dt) {
this.life *= this.aging;
if (
this.r < 0.1 ||
this.life === 0 ||
this.x + this.r < 0 ||
this.x - this.r > this.universe.width ||
this.y + this.r < 0 ||
this.y - this.r > this.universe.height)
{
this.system.removeObject(this);
}
this.r *= this.life;
this.x += this.velocity[0];
this.y += this.velocity[1];
} }, { key: 'render', value: function render(
ctx) {
// Main circle //亮圈模块
ctx.fillStyle = this.color;
ctx.beginPath();
ctx.arc(this.x, this.y, this.r*1.2, 0, 2 * Math.PI, false);
ctx.fill();
ctx.closePath();
var r = this.color.match(/([0-9]+)/g)[0];
var g = this.color.match(/([0-9]+)/g)[1];
var b = this.color.match(/([0-9]+)/g)[2];
// Gradient//梯度变化曲线
var spread = 1.5;
var gradient = ctx.createRadialGradient(
this.x, this.y, this.r,
this.x, this.y, this.r * spread);
gradient.addColorStop(0, 'rgba(' + r + ', ' + g + ', ' + b + ', 0.5)');
gradient.addColorStop(1, 'rgba(' + r + ', ' + g + ', ' + b + ', 0)');
ctx.globalCompositeOperation = 'lighter';
ctx.fillStyle = gradient;
ctx.beginPath();
ctx.arc(this.x, this.y, this.r * spread, 0, 2 * Math.PI, false);
ctx.fill();
ctx.closePath();
ctx.globalCompositeOperation = 'source-over';
// Aberration//偏差
var offset = this.r * 0.5;
var color = 'rgba(' + g + ', ' + b + ', ' + r + ', 0.5)';
ctx.globalCompositeOperation = 'lighter';
ctx.fillStyle = color;
ctx.beginPath();
ctx.arc(this.x + offset, this.y + offset, this.r, 0, 2 * Math.PI, false);
ctx.fill();
ctx.closePath();
ctx.globalCompositeOperation = 'source-over';
} }]);return Particle;}();
// Crown //水波纹圈模块
var
Crown = function () {
function Crown(system, x, y) {_classCallCheck(this, Crown);
this.system = system;
this.x = x;
this.y = y;
this.r = getRandomInt(5, 15); // 5, 20 水波纹圈半径范围
this.mod = 1.1;
this.life = 0.5; //水波纹线
this.aging = getRandom(0.830, 0.899);
this.speed = getRandom(8, 9);
this.color = {
r: getRandomInt(236, 242),
g: getRandomInt(70, 80),
b: getRandomInt(50, 70) };
this.angle1 = Math.PI * getRandom(0, 2);
this.angle2 = this.angle1 + Math.PI * getRandom(0.3, 0.4);//水波纹圈完整度
}_createClass(Crown, [{ key: 'update', value: function update(
dt) {
this.life *= this.aging;
if (this.life <= 0.0001) this.system.removeObject(this);
this.r += Math.abs(1 - this.life) * this.speed;
this.x1 = this.x + this.r * Math.cos(this.angle1);
this.y1 = this.y + this.r * Math.sin(this.angle1);
this.angle3 = this.angle1 + (this.angle2 - this.angle1) / 2;
this.x2 = this.x + this.r * this.mod * Math.cos(this.angle3);
this.y2 = this.y + this.r * this.mod * Math.sin(this.angle3);
} }, { key: 'render', value: function render(
ctx) {
var gradient = ctx.createRadialGradient(
this.x, this.y, this.r * 0.9,
this.x, this.y, this.r);
gradient.addColorStop(0, 'rgba(' + this.color.r + ', ' + this.color.g + ', ' + this.color.b + ', ' + this.life + ')');
gradient.addColorStop(1, 'rgba(' + this.color.r + ', ' + this.color.g + ', ' + this.color.b + ', ' + this.life * 0.5 + ')');
ctx.fillStyle = gradient;
ctx.beginPath();
ctx.arc(this.x, this.y, this.r, this.angle1, this.angle2, false);
ctx.quadraticCurveTo(this.x2, this.y2, this.x1, this.y1);
ctx.fill();
ctx.closePath();
} }]);return Crown;}();
// Explosion //爆炸模块
var
Explosion = function () {
function Explosion(world, x, y) {_classCallCheck(this, Explosion);
this.world = world;
this.x = x;
this.y = y;
this.objects = [];
var particles = getRandomInt(10, 30); // 10, 30 amount of particles//爆炸 粒子数量
var crowns = particles * getRandom(0.4, 0.5);
while (crowns-- > 0) {this.addCrown();}
while (particles-- > 0) {this.addParticle();}
}_createClass(Explosion, [{ key: 'update', value: function update(
dt) {
this.objects.forEach(function (obj) {
if (obj) obj.update(dt);
});
if (this.objects.length <= 0) {
this.world.clearExplosion(this);
}
} }, { key: 'render', value: function render(
ctx) {
this.objects.forEach(function (obj) {
if (obj) obj.render(ctx);
});
} }, { key: 'addCrown', value: function addCrown()
{
this.objects.push(new Crown(this, this.x, this.y));
} }, { key: 'addParticle', value: function addParticle()
{
this.objects.push(new Particle(this, this.x, this.y));
} }, { key: 'removeObject', value: function removeObject(
obj) {
var index = this.objects.indexOf(obj);
if (index !== -1) {
this.objects.splice(index, 1);
}
} }]);return Explosion;}();
// World
var
ConfettiWorld = function () {function ConfettiWorld()
{_classCallCheck(this, ConfettiWorld);}_createClass(ConfettiWorld, [{ key: 'init', value: function init()
{
this.objects = [];
window.addEventListener('click', this.explode.bind(this));
// Initial explosion //初始爆炸
var counter = 0;
while (counter-- > 0) {
this.explode({
clientX: window.event.clientX, //getRandomInt(10, this.universe.width) , //this.universe.width / 2,
clientY: window.event.clientY //getRandomInt(10, 50) //this.universe.height / 2
});
}
} }, { key: 'update', value: function update(
dt) {
this.objects.forEach(function (obj) {
if (obj) obj.update(dt);
});
var amount = this.objects.reduce(function (sum, explosion) {
return sum += explosion.objects.length;
}, 0);
} }, { key: 'render', value: function render(
ctx) {
this.objects.forEach(function (obj) {
if (obj) obj.render(ctx);
});
} }, { key: 'explode', value: function explode(
event) {
var x = event.clientX;
var y = event.clientY;
this.objects.push(new Explosion(this, x, y));
} }, { key: 'clearExplosion', value: function clearExplosion(
explosion) {
var index = this.objects.indexOf(explosion);
if (index !== -1) {
this.objects.splice(index, 1);
}
} }]);return ConfettiWorld;}();
// Time
var
Time = function () {
function Time() {_classCallCheck(this, Time);
this.now = 0; // current tick time
this.prev = 0; // prev tick time
this.elapsed = 0; // elapsed time from last tick
this.delta = 0; // time from last update
this.fps = 60; // desired fps
this.step = 1 / 60; // step duration
}_createClass(Time, [{ key: 'update', value: function update(
time) {
this.now = time;
this.elapsed = (this.now - this.prev) / 1000;
this.prev = this.now;
this.delta += this.elapsed;
} }, { key: 'raf', value: function raf(
func) {
window.requestAnimationFrame(func);
} }, { key: 'hasFrames', value: function hasFrames()
{
return this.delta >= this.step;
} }, { key: 'processFrame', value: function processFrame()
{
this.delta -= this.step;
} }]);return Time;}();
// Canvas
var
Universe = function () {
function Universe(element) {_classCallCheck(this, Universe);
this.el = element;
this.ctx = this.el.getContext('2d');
this.pixelRatio = window.devicePixelRatio;
this.time = new Time();
this.worlds = {};
this.world = null; // current state
this.updateSize();
window.addEventListener('resize', this.updateSize.bind(this));
this.addWorld('confetti', ConfettiWorld);
this.setWorld('confetti');
this.start();
}_createClass(Universe, [{ key: 'start', value: function start()
{
this.time.raf(this.tick.bind(this));
} }, { key: 'tick', value: function tick(
time) {
this.time.update(time);
if (this.time.hasFrames()) {
this.update();
this.time.processFrame();
}
this.render();
this.time.raf(this.tick.bind(this));
} }, { key: 'update', value: function update()
{
this.world.update(this.time.step);
} }, { key: 'render', value: function render()
{
var gradient = this.ctx.createLinearGradient(0, 0, this.width, this.height);
// gradient.addColorStop(0, '#34495e');
//gradient.addColorStop(1, '#2c3e50');
this.ctx.clearRect(0, 0, this.width, this.height);
// this.ctx.fillStyle = '#2c3e50'
// //this.ctx.fillStyle = gradient;
// // this.ctx.fillRect(0, 0, this.width, this.height);
this.world.render(this.ctx);
}
// Helpers 库
}, { key: 'updateSize', value: function updateSize()
{
this.width = window.innerWidth;
this.height = window.innerHeight;
this.el.width = this.width * this.pixelRatio;
this.el.height = this.height * this.pixelRatio;
this.el.style.width = window.innerWidth + 'px';
this.el.style.height = window.innerHeight + 'px';
this.ctx.scale(this.pixelRatio, this.pixelRatio);
} }, { key: 'addWorld', value: function addWorld(
worldName, World) {
this.worlds[worldName] = new World();
this.worlds[worldName].universe = this;
this.worlds[worldName].init();
} }, { key: 'setWorld', value: function setWorld(
worldName) {
this.world = this.worlds[worldName];
} }]);return Universe;}();
// Main
console.clear();
var element = document.querySelector('#canvas1');
window.Canvas= new Universe(element);</script>
</body>
<div class="bg-cover pd-header post-cover" style="background-image: url('/medias/featureimages/1.jpg')">
<div class="container">
<div class="row">
<div class="col s12 m12 l12">
<div class="brand">
<div class="description center-align post-title">
蓝桥杯历届试题K倍区间数(C语言)
</div>
</div>
</div>
</div>
</div>
</div>
<main class="container content">
<!-- 文章内容详情 -->
<div id="artDetail">
<div class="card">
<div class="card-content article-info">
<div class="row tag-cate">
<div class="col s7">
<div class="article-tag">
<a href="/tags/算法/" target="_blank">
<span class="chip bg-color">算法</span>
</a>
<a href="/tags/思维/" target="_blank">
<span class="chip bg-color">思维</span>
</a>
</div>
</div>
<div class="col s5 right-align">
<div class="post-cate">
<i class="fa fa-bookmark fa-fw icon-category"></i>
<a href="/categories/算法/" class="post-category" target="_blank">
算法
</a>
</div>
</div>
</div>
<div class="post-info">
<div class="post-date info-break-policy">
<i class="fa fa-calendar-minus-o fa-fw"></i>发布日期:
<span id="page__date">2018-05-30</sapn>
</div>
<div class="info-break-policy">
<i class="fa fa-file-word-o fa-fw"></i>文章字数:
605
</div>
<div class="info-break-policy">
<i class="fa fa-clock-o fa-fw"></i>阅读时长:
3 分
</div>
<div id="busuanzi_container_page_pv" class="info-break-policy">
<i class="fa fa-eye fa-fw"></i>阅读次数:
<span id="busuanzi_value_page_pv"></span>
</div>
</div>
</div>
<hr class="clearfix">
<div class="card-content article-card-content">
<div id="articleContent">
<p> <blockquote> <h2><a id="K_3"></a>K倍区间数</h2> <p>问题描述   <br> 给定一个长度为N的数列,A1, A2, … AN,如果其中一段连续的子序列 Ai, Ai+1, … Aj(i <=<br> j)之和是K的倍数,<br> 我们就称这个区间[i, j]是K倍区间。<br>  你能求出数列中总共有多少个K倍区间吗?<br> 输入格式   <br> 第一行包含两个整数N和K。(1 <= N, K <= 100000)<br> 以下N行每行包含一个整数Ai。(1 <= Ai <= 100000)<br> 输出格式   <br> 输出一个整数,代表K倍区间的数目。<br> 样例输入<br> 5 2<br> 1 2 3 4 5<br> 样例输出<br> 6<br> 数据规模和约定</p> </blockquote> </p><p><strong>思路:要求的是k的区间 而且是任意起点都可以,也就是随便截取区间只要是K的倍数即可。<br> 那这里我们肯定得做取余运算了,如果余数为0当然是k的倍数了 那么余数不为0就不是K的倍数,<br> 但是 仔细想一想 两个区间对k的取余结果相同,比如余数都为1时,此时这两个区间相减之后的<br> 区间就是K的倍数了,但然这里不用担心,因为每次取到的都是连续的区间,所以减出来的区间也是连续的。<br> 这里用到了sum来存余数x对应这个有y个区间,对于每种不同的区间他们的数量就是C(n,2),<br> 就是n个里取两个相减,当然这里有特殊,就是余数为0的情况需要额外加1 因为 比如说S5就是K的倍数,他不需要减什么区间,但是在我们的运算中是要取到两个区间,所以要额外加1 相当于加了个 和为0的区间S0</strong></p> <div><p></p>