回分類題庫
d198: CP Lab Exercise: Dot Product
出處:

Difficulity : N/A
Accepted : 64 Times | Submit :107 Times | Clicks : 1341
Accepted : 47 Users | Submit : 48 Users | Accepted rate : 98%
Time Limit :10000 ms | Memory Limit : 64000 KBytes
題目加入時間 : 2010-12-29 15:15

Content :

Dot product is an algebraic operation that takes two equal-length sequences of numbers and returns a single number obtained by multiplying corresponding entries and adding up those products.

You are asked to write a program to calculate the dot product of two vectors.

You have to dynamic allocate 1-d arrays and free them when they are useless.

Implement a function with given prototype:
    int dotProduct(int *first, int *second, int size);
    // To be used in exercise 2.

Sample Program:  ~g9803/dotProduct
 

Input :

There are several sets of data, for each data, the first line is an integer N which is the vector's length. (N is so huge that you can't even image it.)

The following two lines are the vectors, each line has N integer which are the vector's value.

Output :

For each set of data, output a line of the dot product result.

Sample Input :

4
1 2 3 4
1 2 3 4
3
1 2 3
1 2 3

Sample Output :

30
14

Hint :


  

Author :


  Solve it!   Status Forum (0)

C++
C
JAVA
76642. alun0922 ( 4 s , 480KB)
65135. CC501 ( 4.1 s , 432KB)
28533. tom86046 ( 6.4 s , 38582KB)
28575. cp96208013 ( 1.6 s , 346KB)
28738. cp95205001 ( 1.6 s , 352KB)
28631. cp99703014 ( 1.6 s , 340KB)
28645. cp99703024 ( 1.6 s , 346KB)
28715. cp99703002 ( 1.6 s , 356KB)
50784. nwgs524513cja ( 2.8 s , 34014KB)

執行時間會受很多因素影響因此僅供參考,主機等級請看這裡