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所表示的范畴

相关内容

热门资讯

cad打印线条粗细设置 cad... 004-线型(下)打印样式设置和线型文件使用一、线宽设置方法制图规范里边的线宽要求,我们已经定义好,...
荼蘼什么意思 岁月缱绻葳蕤生香... 感谢作者【辰夕】的原创独家授权分享编辑整理:【多肉植物百科】百科君坐标:云南 曲靖春而至,季节流转,...
cad打印线条粗细设置 cad... 004-线型(下)打印样式设置和线型文件使用一、线宽设置方法制图规范里边的线宽要求,我们已经定义好,...
应用未安装解决办法 平板应用未... ---IT小技术,每天Get一个小技能!一、前言描述苹果IPad2居然不能安装怎么办?与此IPad不...
阿西吧是什么意思 阿西吧相当于... 即使你没有受到过任何外语培训,你也懂四国语言。汉语:你好英语:Shit韩语:阿西吧(아,씨발! )日...