我遇到了这个算法问题.我能够实现O(n ^ 2)解决方案.在O(n)时间有更好的方法吗?
题:
你得到一个N个整数的数组A1, A2 ,…, AN.返回f(i, j)所有的最大值1 ? i, j ? N.
f(i, j)定义为|A[i] - A[j]| + |i - j|,其中|x|表示x的绝对值.
示例:
A=[1, 3, -1]
f(1, 1) = f(2, 2) = f(3, 3) = 0
f(1, 2) = f(2, 1) = |1 - 3| + |1 - 2| = 3
f(1, 3) = f(3, 1) = |1 - (-1)| + |1 - 3| = 4
f(2, 3) …Run Code Online (Sandbox Code Playgroud) 我是一名Web开发人员.我有JavaScript,Jquery,Php,HTML等Web技术的经验.我知道C的基本概念.最近我有兴趣学习更多关于mapreduce和hadoop的知识.所以我在我大学的mapreduce课程中参加并行数据处理.由于我没有任何面向Java或C++等面向对象语言的编程知识,我应该如何学习map reduce和hadoop.我已经开始阅读雅虎hadoop教程以及OReilly的Hadoop The Definitive Guide 2nd.Edition.
我希望你们建议我学习mapreduce和hadoop的方法.
我需要创建一个临时文件夹,我可以在其中放置一些临时文件进行处理.我不确定我是否会在我的应用程序jar执行的文件夹中具有读/写访问权限.
File tempFolder = File.createTempFile("fooo","");Where是文件夹创建的时候?当我进入我的mac中的临时文件夹时,我无法通过名称fooo看到文件夹.我一直在努力让Hbase在我的机器上工作.我相信我的设置有问题,我无法修复它.我让主人没有运行错误,但Jsp清楚地表明它正在运行.启动Hadoop和Hbase之后.我做了JPS
yeshwanthvenkatesh@mymachineip /usr/local/Cellar/hbase/0.94.4/bin (master)$ jps
1609 Main
715 DataNode
985 TaskTracker
614 NameNode
886 JobTracker
1463 HRegionServer
1263 HQuorumPeer
814 SecondaryNameNode
1695
1349 HMaster
1842 Jps
Run Code Online (Sandbox Code Playgroud)
当我尝试在Hbase shell中调用命令时,我收到以下错误.
hbase(main):001:0> list
TABLE
2013-04-25 16:20:28.933 java[1609:1703] Unable to load realm info from SCDynamicStore
ERROR: org.apache.hadoop.hbase.MasterNotRunningException: Retried 7 times
Here is some help for this command:
List all tables in hbase. Optional regular expression parameter could
be used to filter the output. Examples:
hbase> list
hbase> list 'abc.*'
hbase(main):002:0> scan 'ResultStore'
ROW COLUMN+CELL …Run Code Online (Sandbox Code Playgroud) 我最近在一次采访中被问到了这个问题,我无法弄清楚如何实现它.我希望有人能指出我如何处理这个问题的正确方向.
问题陈述:给定2D整数数组,找到可以容纳的总水量.数字代表地图中的高程(即山峰的高度).水从最高的山流到山谷(最高的高度到最低的高度).
例1:这是一个5 x 3矩阵.10是最高峰.你可以假设水流下来并开始收集在坐标2的瓷砖上(3, 1).这块瓷砖将收集7个单位的水.在以坐标溢出到高度为9的相邻瓷砖(2, 0) or (3, 0)并流入海洋之前(假设边缘被海洋包围).因此,为此地图收集的总水量为7.
9 9 9
9 10 9
9 9 9
9 2 10
10 10 10
Run Code Online (Sandbox Code Playgroud)
例2:
9 9 9 9 9 9
9 10 9 8 2 4
9 9 9 10 3 5
9 2 2 10 3 5
10 10 10 10 9 9
Run Code Online (Sandbox Code Playgroud)
在这种情况下,水可以在以下坐标中收集:
我想验证目录中的所有文件是否属于某种类型.到目前为止我做了什么.
private static final String[] IMAGE_EXTS = { "jpg", "jpeg" };
private void validateFolderPath(String folderPath, final String[] ext) {
File dir = new File(folderPath);
int totalFiles = dir.listFiles().length;
// Filter the files with JPEG or JPG extensions.
File[] matchingFiles = dir.listFiles(new FileFilter() {
public boolean accept(File pathname) {
return pathname.getName().endsWith(ext[0])
|| pathname.getName().endsWith(ext[1]);
}
});
// Check if all the files have JPEG or JPG extensions
// Terminate if validation fails.
if (matchingFiles.length != totalFiles) {
System.out.println("All the tiles should be …Run Code Online (Sandbox Code Playgroud) 我是ROR的新手,我正在努力了解范围.在我当前的实现中,我将获取所有处理器并在视图中显示它.
class ProcessorsController
def index
@processors = Processor.all
end
end
Run Code Online (Sandbox Code Playgroud)
我想修改它,所以我只能得到用户管理员的处理器.这就是我的关系建立的方式.
class Processor
belongs_to :feed
#SCOPES (what I have done so far)
scope :feed, joins(:feed)
scope :groups, joins(:feed => :groups).join(:user).where(:admin => true)
end
class Feed < ActiveRecord::Base
has_and_belongs_to_many :groups
end
class Group < ActiveRecord::Base
belongs_to :user
end
class User < ActiveRecord::Base
has_many :groups
scope :admin, where(:admin => true)
end
Run Code Online (Sandbox Code Playgroud)
我能够在我的撬中做到这一点
pry(main)> Processor.find(63).feed.groups.first.user.admin?
Run Code Online (Sandbox Code Playgroud)
PS:有人可以提供一些很好的资源,如果关系复杂,我可以学习如何使用范围.
我有一个具有多个属性的对象,我想使用lodash删除空的对象/嵌套对象.做这个的最好方式是什么?
Let template = {
node: "test",
representation: {
range: { }
},
transmit: {
timeMs: 0
}
};
Run Code Online (Sandbox Code Playgroud)
至
template = {
node: "test",
transmit: {
timeMs: 0
}
};
Run Code Online (Sandbox Code Playgroud)
我试过这样的事,但我迷路了.
Utils.removeEmptyObjects = function(obj) {
return _.transform(obj, function(o, v, k) {
if (typeof v === 'object') {
o[k] = _.removeEmptyObjects(v);
} else if (!_.isEmpty(v)) {
o[k] = v;
}
});
};
_.mixin({
'removeEmptyObjects': Utils.removeEmptyObjects
});
Run Code Online (Sandbox Code Playgroud) 我试图使用Mapreduce找到维基百科的内部页面排名.我在一小部分wikipages上实现了Pagerank算法.有6349页.我用这个公式来计算pagerank(d = 0.85).

我想验证所有pagerank的总和是否等于总页数(6349).
到目前为止我发现了什么:
1.所有6349页的总页面排名是1001.26044
2.根据WikiPedia,如果我使用上述公式each PageRank is multiplied by N and the sum becomes N.我将每页的排名乘以N(6349)并计算总和,得到6356789.5.
有没有理由为什么页面排名的总和不等于总页数?我应该使用第二个公式来验证吗?
注意:我运行了mapreduce代码10次迭代,以获得良好的近似值.
我已经链接了两个Map减少工作.Job1将只有一个reducer,我正在计算浮点值.我想在Job2的reducer中使用这个值.这是我的主要方法设置.
public static String GlobalVriable;
public static void main(String[] args) throws Exception {
int runs = 0;
for (; runs < 10; runs++) {
String inputPath = "part-r-000" + nf.format(runs);
String outputPath = "part-r-000" + nf.format(runs + 1);
MyProgram.MR1(inputPath);
MyProgram.MR2(inputPath, outputPath);
}
}
public static void MR1(String inputPath)
throws IOException, InterruptedException, ClassNotFoundException {
Configuration conf = new Configuration();
conf.set("var1","");
Job job = new Job(conf, "This is job1");
job.setJarByClass(MyProgram.class);
job.setMapperClass(MyMapper1.class);
job.setReducerClass(MyReduce1.class);
job.setOutputKeyClass(Text.class);
job.setOutputValueClass(FloatWritable.class);
FileInputFormat.addInputPath(job, new Path(inputPath));
job.waitForCompletion(true);
GlobalVriable = conf.get("var1"); // …Run Code Online (Sandbox Code Playgroud) hadoop ×4
algorithm ×3
mapreduce ×3
java ×2
file-exists ×1
flood-fill ×1
hbase ×1
hdfs ×1
image ×1
javascript ×1
jpeg ×1
lodash ×1
macos ×1
object ×1
pagerank ×1