-
Total time limit:
-
1000ms
-
Memory Limit:
-
65536kB
-
Describe
-
In linear algebra and computational geometry, the vector dot product is a very important operation.
Given two n-dimensional vectors a= (a1,a2,..., an) and b= (B1,b2,..., bn), find dot product a· b=a1b1+a2b2+...+anbn.
-
Input
-
The first line is an integer n. 1 <= n <= 1000.
The second line contains n integers a1,a2,..., an.
The third line contains n integers b1,b2,..., bn.
Adjacent integers are separated by a single space. The absolute value of each integer is no more than 1000.
-
Output
-
An integer, which is the dot product result of two vectors.
-
Sample input
-
31 4 62) 1 5
-
Sample output
-
36
The code is actually:
1#include <cstdio>2 intn,a[1010],b[1010],ans;3 intMain () {4scanf"%d",&n);5 for(intI=1; i<=n;i++) scanf ("%d",&a[i]);6 for(intI=1; i<=n;i++) scanf ("%d",&b[i]);7 for(intI=1; i<=n;i++) ans+=a[i]*B[i];8printf"%d\n", ans);9 return 0;Ten}
。。。
Vector dot product calculation