Hust oj 1754 Minimum Scalar Product(水题)
来源:互联网 发布:九九乘法表c语言编程 编辑:程序博客网 时间:2024/06/05 11:13
You are given two vectors v1=(x1,x2,...,xn) and v2=(y1,y2,...,yn). The scalar product of these vectors is a single number, calculated as x1y1+x2y2+...+xnyn.
Suppose you are allowed to permute the coordinates of each vector as you wish. Choose two permutations such that the scalar product of your two new vectors is the smallest possible, and output that minimum scalar product.
InputThere are multiple test cases.
For each test case, the first line contains integer number n. The next two lines contain n integers each (1<=n<=800), giving the coordinates of v1 and v2 respectively.
Process to the end of file.
For each test case, output a line X, where X is the minimum scalar product of all permutations of the two given vectors.
Sample Input31 3 -5-2 4 151 2 3 4 51 0 1 0 1Sample Output
-256
给你俩数组,问俩数组乘积之和最小是多少
#include<cstdio>#include<iostream>#include<cstring>#include<algorithm>using namespace std;const int Maxn = 1000;typedef long long ll;ll a[Maxn];ll b[Maxn];int n;int main(){ while(~scanf("%d",&n)) { for(int i=0;i<n;i++) { scanf("%lld",&a[i]); } for(int i=0;i<n;i++) { scanf("%lld",&b[i]); } sort(a,a+n); sort(b,b+n); ll sum = 0; for(int i=0;i<n;i++) { sum += a[i] * b[n-1-i]; } printf("%lld\n",sum); }}
- Hust oj 1754 Minimum Scalar Product(水题)
- Minimum Scalar Product
- Minimum Scalar product
- Hust oj 2116 Maximum continuous product(水题)
- 2008 Round1AA Minimum Scalar Product
- TOJ 3508.Minimum Scalar Product
- Minimum Scalar Product(2008 Round1A A)
- (code jam)Problem A. Minimum Scalar Product
- Code Jam - Minimum Scalar Product for Python
- Code jam Problem A. Minimum Scalar Product
- GCJ 2008 Round1A A Minimum Scalar Product
- GCJ Round 1A 2008 Problem A. Minimum Scalar Product(YY)
- Google code jam: Problem A. Minimum Scalar Product
- GCJ Round 1A 2008 Problem A. Minimum Scalar Product
- GCJ 2008 Round 1A A - Minimum Scalar Product (贪心)
- Google Code Jam Notes - Minimum Scalar Product - Java
- GCJ 2008 Round 1A Minimum Scalar Product
- GCJ Round 1A 2008 Problem A. Minimum Scalar Product
- MIPI调试经验
- Eclipse 在开发中使用到的快捷键很实用噢
- 一个男人关注的东西 决定了他的层次
- SASS的介绍和应用示例入门
- 根据容器大小设置字体
- Hust oj 1754 Minimum Scalar Product(水题)
- TOJ 2881.Biased Standings
- 关于C++指向函数的指针 的理解
- 赛马问题
- Java的优点以及与C++的异同
- 待解决问题
- javascript中设置cookie
- 关于二叉树的按层打印
- [编程题] LeetCode上的Tree类型的题目