EOJ2183. Minimum Scalar Product
创始人
2025-05-31 04:46:43

单点时限: 2.0 sec

内存限制: 256 MB

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.

输入格式

The first line of the input file contains integer number T - the number of test cases. For each test case, the first line contains integer number n. The next two lines contain n integers each, giving the coordinates of v1 and v2 respectively.

T = 10

100 ≤ n ≤ 800

-100000 ≤ xi, yi ≤ 100000

输出格式

For each test case, output a line

Case #X: Y

where X is the test case number, starting from 1, and Y is the minimum scalar product of all permutations of the two given vectors.

样例

input

2
3
1 3 -5
-2 4 1
5
1 2 3 4 5
1 0 1 0 1

output

Case #1: -25
Case #2: 6
#include 
#include 
#include 
using namespace std;
class SingleJob{
public:int dim;vector vecA; vector vecB;
};
int main() {int jobs, temp;SingleJob J[10];// 输入cin >> jobs;for(int i=0;i> J[i].dim;for(int j=0;j> temp;J[i].vecA.insert(J[i].vecA.end(), temp);}for(int j=0;j> temp;J[i].vecB.insert(J[i].vecB.end(), temp);}}// 输出。注意结果dotpdt是两个int型相乘,需要用longlong定义long long dotpdt=0;for(int i=0;i

ps:假设维度是n,让A、B生成全排列然后暴力解的时间复杂度是O(n^2)。注意到最小点积可以是 “让每个vecA最大的数 × vecB最小的数” 从而简化运算。

因此本例将vecA递增排序、vecB递减排序,最后求出每个job对应的点积 dotpdt 并输出。

另外,本题与 EOJ3003. 最小向量点积 的不同之处在于vectorA和vectorB 的范围扩大了,导致的点积结果可能超过int所表示的范畴

相关内容

热门资讯

世界上最漂亮的人 世界上最漂亮... 此前在某网上,选出了全球265万颜值姣好的女性。从这些数量庞大的女性群体中,人们投票选出了心目中最美...
吸猫伐是什么意思 吸猫是吸哪里 作为铲屎官,相信对于网络上流行的各种与猫咪相关的梗都是了然于心的,什么吸猫啦,撸猫啦,云养猫啦……等...
世界上最漂亮的人 世界上最漂亮... 此前在某网上,选出了全球265万颜值姣好的女性。从这些数量庞大的女性群体中,人们投票选出了心目中最美...
长白山自助游攻略 吉林长白山游... 昨天介绍了西坡的景点详细请看链接:一个人的旅行,据说能看到长白山天池全凭运气,您的运气如何?今日介绍...