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 ...
随机推荐
- 图解hdu5301Buildings
这个题就是给出一个大矩形n*m.当中有个1*1的小格子不能被占用,然后要你用非常多小矩形去填满.问小矩形的最小最大面积是多少. 显然小矩形必定是1*x的最好,毕竟i*x,若i>1则还是能够拆成非 ...
- Day 3 EX 购物车自写
# -*- coding: utf_8 _*_# Author:Vi import copygoods = [0,[1,'iphone',20],[2,'ipad',2500]]salary = in ...
- Python3.7&Django1.11.15 兼容性问题
环境: 1. Windows10 2. python3.7 3. Django1.11.15 启动Django时抛出以下异常: Unhandled exception in thread starte ...
- 【Codeforces Round #457 (Div. 2) C】Jamie and Interesting Graph
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 找比n-1大的最小的素数x 1-2,2-3..(n-2)-(n-1)长度都为1 然后(n-1)-n长度为(x-(n-2)) 然后其他 ...
- Gym - 100502A Amanda Lounges
Amanda Lounges Time Limit: 1000MS Memory Limit: 524288KB 64bit IO Format: %I64d & %I64u AMAN ...
- Linux编译ffmpeg
Linux编译ffmpeg并转换MP3到AMR AMR格式是智能手机上的常用音频文件格式,比如MP3格式的压缩比大,但是文件比MP3小,所以在移动互联项目中应用比较广泛.去年年底协助联想研究院开发一款 ...
- 洛谷 P1757 通天之分组背包
P1757 通天之分组背包 题目背景 直达通天路·小A历险记第二篇 题目描述 自01背包问世之后,小A对此深感兴趣.一天,小A去远游,却发现他的背包不同于01背包,他的物品大致可分为k组,每组中的物品 ...
- 分享一段php获取随意时间的前一天代码
<?php /** * 获取给定日期的前一天 * @param string $date * @return string $yesterday */ function getYesterday ...
- 细说 iOS 消息推送
APNS的推送机制 与Android上我们自己实现的推送服务不一样,Apple对设备的控制很严格.消息推送的流程必需要经过APNs: 这里 Provider 是指某个应用的Developer,当然假设 ...
- 对AWS的计费有点糊涂
对AWS的计费有点糊涂 今天收到亚马逊的账单,就两笔 1. US West (Oregon) Region Elastic IP Addresses $0.005 per Elastic IP ...