今天准备熟悉一下codejam的在线编程,为google的笔试做准备,因此按照codejam上对新手的建议,先用了一个简单的题目来弄清楚流程。记录一下需要注意的地方。

 

1.输入输出

输入输出重定位即可,拿Minimum Scalar Product这个例子示例如下:

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
using namespace std; int main()
{
freopen("A-large-practice.in","r",stdin);
freopen("output.in","w",stdout); int caseNum;
int curVectorLen;
typedef long long longType;
longType curTotal;
cin>>caseNum;
for(int i=0;i<caseNum;++i)
{
cin>>curVectorLen; vector<int> vec1(curVectorLen,0);
vector<int> vec2(curVectorLen,0); for(int j=0;j<curVectorLen;j++)
{
cin>>vec1[j];
} for(int j=0;j<curVectorLen;j++)
{
cin>>vec2[j];
} sort(vec1.begin(),vec1.end());
sort(vec2.begin(),vec2.end()); curTotal=0LL;
for(int j=0;j<curVectorLen;++j)
{
curTotal+=(longType)vec1[j]*vec2[curVectorLen-1-j];
} cout<<"Case #"<<i+1<<": "<<curTotal<<endl; } return 0;
}

 

可知,平时的OJ环境默认输出现在转到了文件读取和写入。转换的关键代码如下:

#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdio>
using namespace std; int main()
{
freopen("A-large-practice.in","r",stdin);
freopen("output.in","w",stdout); //正常的cin和cout
return 0;
}

2.关于Minimum Scalar Product

注意溢出问题就好了。两个int类型乘的时候注意强制类型转换一下。

codejam环境熟悉—Minimum Scalar Product的更多相关文章

  1. [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 ...

  2. GCJ 2008 Round 1A Minimum Scalar Product

    https://code.google.com/codejam/contest/32016/dashboard 题目大意: GCJ(google code jam)上的水题.下周二有比赛,来熟悉熟悉. ...

  3. GCJ——Minimum Scalar Product(2008 Round1 AA)

    题意: 给定两组各n个数,可任意调整同一组数之中数字的顺序,求 sum xi*yi i=1..n的最小值. Small: n<=8 abs xy,yi<=1000 Large: n< ...

  4. GCJ 2008 Round 1A Minimum Scalar Product( 水 )

    链接:传送门 题意:给两个向量 v1 = { x1 , x2 , x3 , x4 .... } , v2 = { y1 , y2 , y3 , y4 ...... } 允许任意交换 v1 和 v2 各 ...

  5. GCJ:2008 Round1AA-Minimum Scalar Product(有序数组倒序乘积和最小)

    题目链接:https://code.google.com/codejam/contest/32016/dashboard#s=p0 Minimum Scalar Product This contes ...

  6. [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_ ...

  7. 20165304实验一java开发环境熟悉

    实验报告封面 一.实验报告封面 课程:Java程序设计 班级:1653班 姓名:李松杨 学号:20165304 指导教师:娄嘉鹏 实验日期:2018年4月2日 实验时间:13:45 - 15:25 实 ...

  8. intellij idea 初步环境熟悉

    刚进来天渔项目组,连开发环境都是新的,学习至上 so 从eclipse过度过来还是有段时间的,期间虽然懵懂,但是也要坚持不耻下问 好了一下是idea的官网http://confluence.jetbr ...

  9. minimum viable product

    w https://en.wikipedia.org/wiki/Minimum_viable_product

随机推荐

  1. 《c程序设计语言》读书笔记--子函数原型和声明的形参

    #include <stdio.h> #define Num 20 int power(int base,int n) { int p = 1; int i; for(i = 0;i &l ...

  2. hdoj - 1258 Sum It Up && hdoj - 1016 Prime Ring Problem (简单dfs)

    http://acm.hdu.edu.cn/showproblem.php?pid=1258 关键点就是一次递归里面一样的数字只能选一次. #include <cstdio> #inclu ...

  3. poj -1065 Wooden Sticks (贪心or dp)

    http://poj.org/problem?id=1065 题意比较简单,有n跟木棍,事先知道每根木棍的长度和宽度,这些木棍需要送去加工,第一根木棍需要一分钟的生产时间,如果当前木棍的长度跟宽度 都 ...

  4. shell 块注释

    方法一 : ' 被注释的多行内容 ' 方法二 :<<eof 被注释的多行内容 eof 方法三 :<<! 被注释的多行内容 ! 方法四 if false ; then 被注释的多 ...

  5. [POJ3264]Balanced Lineup(线段树,区间最值差)

    题目链接:http://poj.org/problem?id=3264 一排牛按1~n标号记录重量,问每个区间最重的和最轻的差值. 线段树维护当前节点下属叶节点的两个最值,查询后作差即可. #incl ...

  6. 【转】Android之内存泄漏调试学习与总结

    大家有或经常碰到OOM的问题,对吧?很多这样的问题只要一出现相信大家的想法跟小马的一样,就是自己的应用:优化.优化.再优化!而且如果出现类似于OOM这样级别的问题,根本就不好处理,LogCat日志中显 ...

  7. C++ STL之priority_queue

    STL中的priority_queue(优先队列)是一种会按照自定义的一种方式(数据的优先级)来对队列中的数据进行动态的排序的容器,不同优先级的情况下,top()上永远是最高优先级的数据,其底层采用的 ...

  8. JSON 之 SuperObject(10): Merge、Clone、ForcePath

    unit Unit1; interface uses   Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, For ...

  9. D3D中深度测试和Alpha混合的关系

    我在学习D3D的深度测试和Alpha混合的时候,有一些遗憾.书上提供的例子里说一定要先渲染不透明物体,再渲染透明物体,对渲染状态的设置也有特殊要求.我看的很晕.自己查图形学的书,上网找资料,结果还是糊 ...

  10. jint

    nuget地址 https://www.nuget.org/packages/Jint/ github上源代码 https://github.com/sebastienros/jint