AC diary--Vector dot product calculation Openjudge 1.6 09

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.