GCJ 2008 Round 1A Minimum Scalar Product( 水 )
**链接:****传送门 **
题意:给两个向量 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( 水 )的更多相关文章
- GCJ 2008 Round 1A Minimum Scalar Product
https://code.google.com/codejam/contest/32016/dashboard 题目大意: GCJ(google code jam)上的水题.下周二有比赛,来熟悉熟悉. ...
- [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_ ...
- 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 ...
随机推荐
- asp.net--CRSF
asp.net使用了token来防止CRSF攻击 前台: 使用@Html.AntiForgeryToken(); 浏览器里面被存了一个cookie值,这个值是asp.net存给浏览器的,是readon ...
- 服务器session,Tomcat有自己的session维护机制,apache有自己的session维护机制
1.SESSION一般不是你说的这种工作方式,你打开一个浏览器,再打开一个,请求同一个网址,然后其中一个登陆,另外一个绝对不会也登陆.SESSION和浏览器本身这个程序就是挂钩的,一般不通过IP和端口 ...
- vue-自定义组件传
项目中,我们经常会遇到自定义组件传值的问题,方法很多种,但是原理很简单,下述文档总结实际项目中使用的传值方式. 父组件传递给子组件某一值,子组件内会修改该值,然后父组件需要获取新值 在 Vue 中 ...
- STL之rb_tree的find函数
1 通用的search方法 STL在实现对特定key值的查找时,并没有採用通用的方法: BRTreeNode * rb_tree_search(RBTreeNode * x, int key){ wh ...
- Seaside HDU 3665 【Dijkstra】
Problem Description XiaoY is living in a big city, there are N towns in it and some towns near the s ...
- faster-rcnn代码阅读1
毫无疑问,faster-rcnn是目标检测领域的一个里程碑式的算法.本文主要是本人阅读python版本的faster-rcnn代码的一个记录,算法的具体原理本文也会有介绍,但是为了对该算法有一个整体性 ...
- 初探BurpSuite
BurpSuite这套渗透软件.或者已经能够说是渗透攻击平台了吧,玩的好.确实非常方便. 就像是玩英雄联盟的ADC,一開始玩VN.感觉非常难上手,玩多了肯定会爱上VN(啊,貌似提到了什么奇怪的东西). ...
- 远程桌面授权server没有提供许可证问题解决方法
今天远程server报如图所看到的错误,网上查找的方法 方法一:(亲測有效) mstsc /V:192.168.0.3 /admin 方法二:(因为server正在使用中,未作測试) 删除远程桌面服 ...
- oc12--对象作为参数
// main.m // 对象作为方法的参数传递 #import <Foundation/Foundation.h> /* 士兵 事物名称: 士兵(Soldier) 属性:姓名(name) ...
- Intel 的 MKL是可以用来训练的——官方的实验也提到了训练
TensorFlow如何充分使用所有CPU核数,提高TensorFlow的CPU使用率,以及Intel的MKL加速 转载 2017年09月07日 16:34:58 标签: cpu / gpu 转载 ...