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 ...
随机推荐
- Introducing ASLR for FreeBSD
Shawn WebbOliver Pinter10 July 2014http://www.hardenedbsd.org/ [ 1. Introduction ]Security in FreeBS ...
- 编译安装 gcc 4.9并验证使用
编译安装 gcc 4.9并验证使用 1. 准备环境(GCC 编译器) centOS 6.3 cat /proc/version Linux version 2.6.32-279.el6.x86_64 ...
- 安装个wampserver 环境 执行php
php代码执行要有相关环境. 在这里推荐一个环境工具.wampserver :内置了下面工具: watermark/2/text/aHR0cDovL2Jsb2cuY3Nkbi5uZXQv/font/5 ...
- QCAD Plugin 开发
QCAD Plugin 开发 eryar@163.com Abstract. QCAD是基于GPL协议的开源CAD软件,核心功能基于Qt使用C++开发,界面及其交互使用Javascript脚本进行开发 ...
- ios代理的使用,正向传值,逆向传值
#import <UIKit/UIKit.h> #import "SubViewController.h" @interface ViewController : UI ...
- ip6tables: ipv6-icmp vs icmp
ip6tables: ipv6-icmp vs icmp资料来源 https://www.jethrocarr.com/2013/02/09/ip6tables-ipv6-icmp-vs-icmp/I ...
- elasticsearch index 之 create index(二)
创建索引需要创建索引并且更新集群index matedata,这一过程在MetaDataCreateIndexService的createIndex方法中完成.这里会提交一个高优先级,AckedClu ...
- 一题多解(三)—— Python 字符串的拼接
1. format def event_log(name, time): print('Event: {}, happens at {}'.format(name, str(time))) 2. 使用 ...
- hbase xshell
用Xshell登陆linux主机后,在hbase shell下死活不能使用backspace和delete删除误输的指令,只得不停退出,重登,仔细输..又错了,再退出,再登,仔细输...又错了...又 ...
- 【Codeforces Round #456 (Div. 2) A】Tricky Alchemy
[链接] 我是链接,点我呀:) [题意] 在这里输入题意 [题解] 统计需要的个数. 不够了,就买. [代码] #include <bits/stdc++.h> #define ll lo ...