codejam环境熟悉—Minimum Scalar Product
今天准备熟悉一下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的更多相关文章
- [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 ...
- GCJ 2008 Round 1A Minimum Scalar Product
https://code.google.com/codejam/contest/32016/dashboard 题目大意: GCJ(google code jam)上的水题.下周二有比赛,来熟悉熟悉. ...
- GCJ——Minimum Scalar Product(2008 Round1 AA)
题意: 给定两组各n个数,可任意调整同一组数之中数字的顺序,求 sum xi*yi i=1..n的最小值. Small: n<=8 abs xy,yi<=1000 Large: n< ...
- GCJ 2008 Round 1A Minimum Scalar Product( 水 )
链接:传送门 题意:给两个向量 v1 = { x1 , x2 , x3 , x4 .... } , v2 = { y1 , y2 , y3 , y4 ...... } 允许任意交换 v1 和 v2 各 ...
- 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_ ...
- 20165304实验一java开发环境熟悉
实验报告封面 一.实验报告封面 课程:Java程序设计 班级:1653班 姓名:李松杨 学号:20165304 指导教师:娄嘉鹏 实验日期:2018年4月2日 实验时间:13:45 - 15:25 实 ...
- intellij idea 初步环境熟悉
刚进来天渔项目组,连开发环境都是新的,学习至上 so 从eclipse过度过来还是有段时间的,期间虽然懵懂,但是也要坚持不耻下问 好了一下是idea的官网http://confluence.jetbr ...
- minimum viable product
w https://en.wikipedia.org/wiki/Minimum_viable_product
随机推荐
- 【转】HashMap的工作原理
很好的文章,推荐Java的一个好网站:ImportNew HashMap的工作原理是近年来常见的Java面试题.几乎每个Java程序员都知道HashMap,都知道哪里要用HashMap,知道Hasht ...
- echo "hello" | nc -4t -w1 localhost 8001
TCP4: echo "hello" | nc -4t -w1 localhost 8001 UDP4: echo "hello" | nc -4u -w1 l ...
- NDK(1)配置ndk,含eclipse,Android Studio1.5.1
现在的ndk配置已经非常简单,如果看到要cygwin的请关闭. 1,Eclipse 添加ndk linux,mac ,windows 相似, a.下载 ndk并解压, b.在eclipse的andro ...
- linux/shell 文本文件删除/删掉空行
分别用sed awk perl grep 实现: sed '/^$/d' input.txt > output.txt #output file: output.txt sed -i '/^$/ ...
- UVa 11107 (后缀数组 二分) Life Forms
利用height值对后缀进行分组的方法很常用,好吧,那就先记下了. 题意: 给出n个字符串,求一个长度最大的字符串使得它在超过一半的字符串中出现. 多解的话,按字典序输出全部解. 分析: 在所有输入的 ...
- I.MX6 shutdown by software
/************************************************************************ * I.MX6 shutdown by softwa ...
- Jave 鼠标点击画太极 PaintTaiji (整理)
package demo; /** * Jave 鼠标点击画太极 PaintTaiji (整理) * 声明: * 又是一份没有注释的代码,而且时间已经久远了,不过代码很短,解读起来应该 * 不会很麻烦 ...
- phonegap 退出确认
实现 再按一次退出 ,这里只针对 主active继承 DroidGap 或者CordovaActive 以下有2种 方案1: 重写CordovaWebView类 新建类NobackWebView p ...
- 删除特定影响因素(字段列)下的重复记录(MySQL)
;CREATE TABLE TabTest ( `id` ) NOT NULL AUTO_INCREMENT ,`factorA` ) NOT NULL DEFAULT ' ' ,`factorB` ...
- 服务器中判断客户端socket断开连接的方法
1, 如果服务端的Socket比客户端的Socket先关闭,会导致客户端出现TIME_WAIT状态,占用系统资源. 所以,必须等客户端先关闭Socket后,服务器端再关闭Socket才能避免TIME_ ...