GCJ Round 1A 2008 Problem A. Minimum Scalar Product
来源:互联网 发布:网络安全法 考题 编辑:程序博客网 时间:2024/04/30 12:12
题目大意:
现有T个测例,每个测例都给定两个大小为N的一维向量x和y,现可以重新排列向量中元素的顺序,要求出两向量可能的最小的点积值。
small:T = 1000, 1 ≤ N ≤ 8, -1000 ≤ xi, yi ≤ 1000
large:T = 10, 100 ≤ N ≤ 800, -100000 ≤ xi, yi ≤ 100000
题目链接
注释代码:
/* * Problem ID : GCJ Round 1A 2008 Problem A. Minimum Scalar Product * Author : Lirx.t.Una * Language : G++ */#include <algorithm>#include <iostream>#include <cstdio>#defineMAXSIZE800using namespace std;typedef__int64llg;intv1[MAXSIZE];intv2[MAXSIZE];intmain() {intnscn, iscn;intn;//向量的大小inti;//计数变量llgans;//保存向量点乘的最终结果//方法就是先排序,然后让最大的和最小的乘,求和即可#ifdef__SMALL__freopen("A-small-practice.in", "r", stdin);//将标准输入输出流重定向到文件中freopen("A-small-practice.out", "w", stdout);//是的scanf、printf都以文件作为对象#endif#ifdef__LARGE__freopen("A-large-practice.in", "r", stdin);freopen("A-large-practice.out", "w", stdout);#endifscanf("%d", &nscn);iscn = 0;while ( nscn-- ) {scanf("%d", &n);for ( i = 0; i < n; i++ ) scanf("%d", v1 + i);for ( i = 0; i < n; i++ ) scanf("%d", v2 + i);sort(v1, v1 + n);sort(v2, v2 + n);ans = 0;for ( i = 0; i < n; i++ )ans += (llg)v1[i] * (llg)v2[n - i - 1];printf("Case #%d: %I64d\n", ++iscn, ans);}fclose(stdin);fclose(stdout);return 0;}无注释代码:
#include <algorithm>#include <iostream>#include <cstdio>#defineMAXSIZE800using namespace std;typedef__int64llg;intv1[MAXSIZE];intv2[MAXSIZE];intmain() {intnscn, iscn;intn;inti;llgans;#ifdef__SMALL__freopen("A-small-practice.in", "r", stdin);freopen("A-small-practice.out", "w", stdout);#endif#ifdef__LARGE__freopen("A-large-practice.in", "r", stdin);freopen("A-large-practice.out", "w", stdout);#endifscanf("%d", &nscn);iscn = 0;while ( nscn-- ) {scanf("%d", &n);for ( i = 0; i < n; i++ ) scanf("%d", v1 + i);for ( i = 0; i < n; i++ ) scanf("%d", v2 + i);sort(v1, v1 + n);sort(v2, v2 + n);ans = 0;for ( i = 0; i < n; i++ )ans += (llg)v1[i] * (llg)v2[n - i - 1];printf("Case #%d: %I64d\n", ++iscn, ans);}fclose(stdin);fclose(stdout);return 0;}
单词解释:
permutation:n, 全排列,置换
permute:vt, 交换,排列
scalar:adj, 标量的,数量的
product:n, 乘积
scalar product:n, 数量积,点积
0 0
- GCJ Round 1A 2008 Problem A. Minimum Scalar Product
- GCJ Round 1A 2008 Problem A. Minimum Scalar Product
- GCJ 2008 Round 1A A - Minimum Scalar Product (贪心)
- GCJ Round 1A 2008 Problem A. Minimum Scalar Product(YY)
- GCJ 2008 Round 1A Minimum Scalar Product
- GCJ 2008 Round1A Problem A. Minimum Scalar Product
- GCJ 2008 Round1A A Minimum Scalar Product
- Minimum Scalar Product(GCJ 2008 Round1A A)数学问题+贪心
- GCJ--Minimum Scalar Product (2008 Round 1AA)
- (code jam)Problem A. Minimum Scalar Product
- Code jam Problem A. Minimum Scalar Product
- 挑战2.7.1 Round 1A 2008 A. Minimum Scalar Product 贪心
- Minimum Scalar Product(2008 Round1A A)
- Google code jam: Problem A. Minimum Scalar Product
- Code Jam 2008 Round1A Problem A. Minimum Scalar Product —— 贪心
- GCJ Round 1A 2008 Problem C. Numbers
- [GCJ] 2011 Round 1A Problem A FreeCell Statistics
- [GCJ] 2011 Round 1B Problem A RPI
- pgsql条件表达式
- IOS开发之----NSDictionary,JSON和XML互相转换
- android系统初始化等待时间设置
- 浏览器调试
- webdriver中元素查找常用方法
- GCJ Round 1A 2008 Problem A. Minimum Scalar Product
- 结账的时候,没出小票,交易会成功吗?
- Greedy Gift Givers
- sqlserver2005 利用触发器 使得在对数据库操作时,自动触发事件
- Makefile中一些特殊符号的意义
- 设计模式C++实现——装饰者模式
- fedora 17 使用gcc命令,未找到该命令
- MapReduce实现推荐系统
- android 中envsetup 输出的全局变量