File tree Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Expand file tree Collapse file tree 1 file changed +42
-0
lines changed Original file line number Diff line number Diff line change
1
+ package codem .music ;
2
+
3
+ import java .util .Scanner ;
4
+
5
+ /**
6
+ * 【工程】: Algorithm 包名: codem.music 类名: Main
7
+ * 【作者】: liuyang
8
+ * 【时间】: 17/6/11 下午11:12
9
+ * 【题目】: 音乐研究
10
+ * 【内容】:
11
+ * 【版本】: V1.0
12
+ * 【运行时间】:
13
+ * 【时间复杂度】:
14
+ * 【空间复杂度】:
15
+ * 【备注】: AC
16
+ * 【思路】: 暴力即可
17
+ */
18
+ public class Main {
19
+
20
+ public static void main (String [] args ) {
21
+ Scanner in = new Scanner (System .in );
22
+ int n = in .nextInt ();
23
+ int [] arrN = new int [n ];
24
+ for (int i = 0 ; i < n ; i ++) {
25
+ arrN [i ] = in .nextInt ();
26
+ }
27
+ int m = in .nextInt ();
28
+ int [] arrM = new int [m ];
29
+ for (int i = 0 ; i < m ; i ++) {
30
+ arrM [i ] = in .nextInt ();
31
+ }
32
+ long min = Long .MAX_VALUE ; //保存最后结果的最小值
33
+ for (int i = 0 ; i < m - n + 1 ; i ++) {
34
+ long cur = 0 ;//计算当前最小值
35
+ for (int j = 0 ; j < n ; j ++) {
36
+ cur += (arrN [j ] - arrM [j + i ]) * (arrN [j ] - arrM [j + i ]);
37
+ }
38
+ min = cur < min ? cur : min ;
39
+ }
40
+ System .out .println (min );
41
+ }
42
+ }
You can’t perform that action at this time.
0 commit comments