09: Vector dot Product calculation
-
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
Ideas:
Simulation
Come on, on the code:
#include <iostream>using namespacestd;Long Long intn,a[1001],b[1001],ans=0;intMain () {CIN>>N; for(intI=1; i<=n;i++) cin>>A[i]; for(intI=1; i<=n;i++) cin>>B[i]; for(intI=1; i<=n;i++) ans+=a[i]*B[i]; cout<<ans<<Endl; return 0;}
AC diary--Vector dot product calculation Openjudge 1.6 09