GCJ 2008 Round 1A Minimum Scalar Product
https://code.google.com/codejam/contest/32016/dashboard
题目大意:
GCJ(google code jam)上的水题。下周二有比赛,来熟悉熟悉。
有两个向量V1=(x1,x2……xn)和v2=(y1,y2……yn),允许任意交换v1和v2各自的分量顺序,请计算v1和v2的内积x1y1+……xnyn的最小值
思路:
不同于OJ的地方在于有大和小的数据之分,且都是用文件来完成。需要自己下载测试数据,输出的数据用文件保存并且上传。
主函数最前面加个
freopen("e:\\input.in","r",stdin);
freopen("e:\\out.out","w",stdout);
即可。
第一句是输入,第二句是输出。
直接排个序,第一个从小到大,第二个从大到小,然后按顺序乘即可。
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAXN=800+10;
typedef long long LL;
LL a[MAXN],b[MAXN];
int main()
{
freopen("e:\\input.in","r",stdin);
freopen("e:\\out.out","w",stdout);
int T;
scanf("%d",&T);
for(int kase=1;kase<=T;kase++)
{
int n;
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 ans=0;
for(int i=0;i<n;i++)
ans+=a[i]*b[n-i-1];
printf("Case #%d: %lld\n",kase,ans);
}
return 0;
}
GCJ 2008 Round 1A Minimum Scalar Product的更多相关文章
- GCJ 2008 Round 1A Minimum Scalar Product( 水 )
链接:传送门 题意:给两个向量 v1 = { x1 , x2 , x3 , x4 .... } , v2 = { y1 , y2 , y3 , y4 ...... } 允许任意交换 v1 和 v2 各 ...
- [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 ...
- codejam环境熟悉—Minimum Scalar Product
今天准备熟悉一下codejam的在线编程,为google的笔试做准备,因此按照codejam上对新手的建议,先用了一个简单的题目来弄清楚流程.记录一下需要注意的地方. 1.输入输出 输入输出重定位 ...
- GCJ——Minimum Scalar Product(2008 Round1 AA)
题意: 给定两组各n个数,可任意调整同一组数之中数字的顺序,求 sum xi*yi i=1..n的最小值. Small: n<=8 abs xy,yi<=1000 Large: n< ...
- 2008 Round 1A C Numbers (矩阵快速幂)
题目描述: 请输出(3+√5)^n整数部分最后3位.如果结果不超过2位,请补足前导0. 分析: 我们最容易想到的方法肯定是直接计算这个表达式的值,但是这样的精度是不够的.朴素的算法没有办法得到答案.但 ...
- 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 ...
- GCJ:2008 Round1AA-Minimum Scalar Product(有序数组倒序乘积和最小)
题目链接:https://code.google.com/codejam/contest/32016/dashboard#s=p0 Minimum Scalar Product This contes ...
- [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_ ...
- [Google Codejam] Round 1A 2016 - The Last Word
[Problem Description] Problem On the game show The Last Word, the host begins a round by showing the ...
随机推荐
- SPI总线工作模式
一.SPI总线工作模式 SPI总线有四种工作模式,是由时钟极性选择(CPOL)和时钟相位选择(CPHA)决定的. CPOL = 0 ,SPI总线空闲为低电平,CPOL = 1, SPI总线空闲为高电平 ...
- 03012_预处理对象executeQuery方法(实现数据库的查询)
1.概述 (1)通过预处理对象的executeQuery方法,完成记录的select语句的执行: (2)操作格式统一如下: ①注册驱动: ②获取连接: ③获取预处理对象: ④SQL语句占位符设置实际参 ...
- 【Codeforces Round #460 (Div. 2) B】 Perfect Number
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 直接暴力求出第k个perfect数字就好. 纯模拟. [代码] #include <bits/stdc++.h> #de ...
- 动态引入js代码
var _hmt = _hmt || []; (function() { var hm = document.createElement("script"); hm.src = & ...
- Kinect 开发 —— 面部识别
EmguCV库也能用来进行面部识别(face identify).实际的面部识别,就是将一张图像上的人物的脸部识别出来,这是个很复杂的过程,具体过程我们这里不讨论.对一幅影像进行处理来找到包含脸部的那 ...
- fg、bg、jobs、&、 ctrl+z---系统任务
系统任务有关的命令 一.& 这个用在一个命令的最后,可以把这个命令放到后台执行 二.ctrl + z 可以将一个正在前台执行的命令放到后台,并且暂停 一和二的区别(&放入后 ...
- [AngularFire] Angular File Uploads to Firebase Storage with Angular control value accessor
The upload class will be used in the service layer. Notice it has a constructor for file attribute, ...
- [React] Use a Render Porp
More detail check LInk. Render Prop vs HOC: HOC version for withMouse: import React from 'react' imp ...
- tcpdump重要笔记
无关痛痒的參数就不写了.仅仅说一些我觉得值得注意的. 1 tcpdump參数 -s 最早在公司旧机器上截包时发现总是不完整,于是知道了这个參数,之后就一直用-s0了.近期一次在家里,忘记输入-s发现包 ...
- 1.4 Ecosystem官网剖析(博主推荐)
不多说,直接上干货! 一切来源于官网 http://kafka.apache.org/documentation/ 1.4 Ecosystem 生态系统 There are a plethora of ...