**链接:****传送门 **

题意:给两个向量 v1 = { x1 , x2 , x3 , x4 .... } , v2 = { y1 , y2 , y3 , y4 ...... } 允许任意交换 v1 和 v2 各自向量的分量顺序,计算 v1,v2 内积 ( x1 * y1 + x2 * y2 .... )的最小值

思路:根据样例可大胆猜测内积最小值应该为 v1 的最小值 × v2 的最大值 , v1 的次小值 × v2 的次大值 ...... 也就是需要排两次序即复杂度为 O( nlogn )是可以通过大数据的


/*************************************************************************
> File Name: gcj_2008_round1_A.cpp
> Author: WArobot
> Blog: http://www.cnblogs.com/WArobot/
> Created Time: 2017年06月19日 星期一 14时10分49秒
************************************************************************/ #include<bits/stdc++.h>
using namespace std; #define ll long long
const int MAX_N = 1002;
int v1[MAX_N] , v2[MAX_N];
int n; bool cmp(int a,int b){
return a > b;
}
int main(){
int t , kase = 0;
freopen("A-small-practice.in","r",stdin); // 测试小数据
freopen("A-small-practice.out","w",stdout); // 测试小数据
scanf("%d",&t);
while(t--){
scanf("%d",&n);
for(int i = 0 ; i < n ; i++) scanf("%d",v1+i);
for(int i = 0 ; i < n ; i++) scanf("%d",v2+i);
sort(v1,v1+n);
sort(v2,v2+n,cmp);
ll ret = 0;
for(int i = 0 ; i < n ; i++){
ret += (ll)v1[i]*v2[i];
}
printf("Case #%d: %lld\n",++kase , ret);
}
return 0;
}

GCJ 2008 Round 1A Minimum Scalar Product( 水 )的更多相关文章

  1. GCJ 2008 Round 1A Minimum Scalar Product

    https://code.google.com/codejam/contest/32016/dashboard 题目大意: GCJ(google code jam)上的水题.下周二有比赛,来熟悉熟悉. ...

  2. [Google Code Jam (Round 1A 2008) ] A. Minimum Scalar Product

    Problem A. Minimum Scalar Product   This contest is open for practice. You can try every problem as ...

  3. codejam环境熟悉—Minimum Scalar Product

    今天准备熟悉一下codejam的在线编程,为google的笔试做准备,因此按照codejam上对新手的建议,先用了一个简单的题目来弄清楚流程.记录一下需要注意的地方.   1.输入输出 输入输出重定位 ...

  4. GCJ——Minimum Scalar Product(2008 Round1 AA)

    题意: 给定两组各n个数,可任意调整同一组数之中数字的顺序,求 sum xi*yi i=1..n的最小值. Small: n<=8 abs xy,yi<=1000 Large: n< ...

  5. 2008 Round 1A C Numbers (矩阵快速幂)

    题目描述: 请输出(3+√5)^n整数部分最后3位.如果结果不超过2位,请补足前导0. 分析: 我们最容易想到的方法肯定是直接计算这个表达式的值,但是这样的精度是不够的.朴素的算法没有办法得到答案.但 ...

  6. Google Code Jam 2008 Round 1A C Numbers(矩阵快速幂+化简方程,好题)

    Problem C. Numbers This contest is open for practice. You can try every problem as many times as you ...

  7. GCJ:2008 Round1AA-Minimum Scalar Product(有序数组倒序乘积和最小)

    题目链接:https://code.google.com/codejam/contest/32016/dashboard#s=p0 Minimum Scalar Product This contes ...

  8. [UCSD白板题] Minimum Dot Product

    Problem Introduction The dot product of two sequences \(a_1,a_2,\cdots,a_n\) and \(b_1,b_2,\cdots,b_ ...

  9. Codeforces Round #365 (Div. 2) A 水

    A. Mishka and Game time limit per test 1 second memory limit per test 256 megabytes input standard i ...

随机推荐

  1. linux下apache2更换目录

    修改apache2的默认文档目录(默认是在/var/www) 修改命令:sudo gedit /etc/apache2/sites-enabled/000-default 在文档中找到 Documen ...

  2. uva 704

    自己之前的不见了.. 这题是双向广搜即可过.. // Colour Hash (色彩缤纷游戏) // PC/UVa IDs: 110807/704, Popularity: B, Success ra ...

  3. eclipse快捷键,比較有用

    1:Ctrl+Pg Up   向左切换选项卡   , 切换到头显示隐藏选项卡(等于Ctrl+e). 2:Ctrl+Pg Dn  向右切换选项卡    , 切换到头显示隐藏选项卡(等于Ctrl+e). ...

  4. 对Java单继承的弥补——接口

    接口主要用来实现多重继承,它是常量和方法的集合,这些方法只有声明没有实现,即接口本身是抽象的,系统默认用abstract修饰. 1.接口的定义: public interface A{ int A=1 ...

  5. [Linux]非常方便的上传下载文件工具rz和sz

     linux上非常方便的上传下载文件工具rz和sz (本文适合linux入门的朋友) [一般用于SecureCRT ssh中使用] █ 法一:直接用yum安装lrzsz(推荐) yum insta ...

  6. oc7--内存分析

    // // main.m // 第二个OC类 #import <Foundation/Foundation.h> @interface Person : NSObject { @publi ...

  7. PDOHelper (原创)

    class PDOHelper{ public static $db =null;// new PDO('mysql:host=192.168.1.68;dbname=test','root','12 ...

  8. ubantu安装jdk

    环境:ubantu16.04下安装jdk1.8 1,在当前用户根目录下创建目录,本人所用的用户为bruce: mkdir /home/bruce/jdk 2,官网下载jdk1.8,网址为http:// ...

  9. 2015 多校赛 第一场 1002 (hdu 5289)

    Description Tom owns a company and he is the boss. There are n staffs which are numbered from 1 to n ...

  10. 【Arduino】基于arduino的激光坦克

    历经了总共40来个小时,终于将这个激光坦克做好了. 这是本人的第一件像样的arduino作品. 用arduino为主控制器,配有32路舵机驱动板(在这有些大材小用了),以及一个wr703n的路由器当做 ...