一 安装环境

直接下载algs4.exe

下载完成后C:\Users\zle 下面会有algs4 文件夹

原文:

Our installer downloads, installs, and configures the Java programming environment you will be using, including Java SE 7, DrJava, the textbook libraries, and the Command Prompt.

  • Log in to the user account in which you will be programming. Your account must have Administrator privileges and you must be connected to the Internet.
  • Download algs4.exe and double-click it to perform the installation. If you receive a User Account Control alert before the installation, click Yes or Allow; if you receive a Program Compatibility Assistant alert after the installation, click This program installed correctly.
  • If the installation succeeds, you will see the following:
    • A Command Prompt windows containing approximately this execution log
    • A Standard Drawing window containing a blue bullseye and textbook graphic.

    Note that the installation can take several minutes or longer if you have a slow internet connection.

  • Delete algs4.exe.

 二 将这个文件夹复制到eclipse工作环境下

3 在eclipse中设置cmd环境

选择 External tools configrations

Name 名字随便取我的是UF1.5

Location 是cmd的目录

working director 默认的工作目录

三 编写程序并运行

 import edu.princeton.cs.algs4.StdIn;
import edu.princeton.cs.algs4.StdOut; public class WeightedQuickUnionUF {
private int[] id; // id[i] = parent of i
private int[] sz; // sz[i] = number of objects in subtree rooted at i
private int count; // number of components // Create an empty union find data structure with N isolated sets.
public WeightedQuickUnionUF(int N) {
count = N;
id = new int[N];
sz = new int[N];
for (int i = 0; i < N; i++) {
id[i] = i;
sz[i] = 1;
}
} // Return the number of disjoint sets.
public int count() {
return count;
} // Return component identifier for component containing p
public int find(int p) {
while (p != id[p])
p = id[p];
return p;
} // Are objects p and q in the same set?
public boolean connected(int p, int q) {
return find(p) == find(q);
} // Replace sets containing p and q with their union.
public void union(int p, int q) {
int i = find(p);
int j = find(q);
if (i == j) return; // make smaller root point to larger one
if (sz[i] < sz[j]) { id[i] = j; sz[j] += sz[i]; }
else { id[j] = i; sz[i] += sz[j]; }
count--;
} public static void main(String[] args) {
int N = StdIn.readInt();
WeightedQuickUnionUF uf = new WeightedQuickUnionUF(N); // read in a sequence of pairs of integers (each in the range 0 to N-1),
// calling find() for each pair: If the members of the pair are not already
// call union() and print the pair.
while (!StdIn.isEmpty()) {
int p = StdIn.readInt();
int q = StdIn.readInt();
if (uf.connected(p, q)) continue;
uf.union(p, q);
StdOut.println(p + " " + q);
}
StdOut.println("# components: " + uf.count());
} }

点击刚刚创建的UF1.5

在console可以看到cmd

进入bin 目录下 因为.class文件在bin目录下

在命令框内输入

折磨了好久终于搞好啦!

参考:http://algs4.cs.princeton.edu/windows/

算法第四版 用eclipse实现书中UnionFind例子的更多相关文章

  1. 算法第四版 在Eclipse中调用Algs4库

    首先下载Eclipse,我选择的是Eclipse IDE for Java Developers64位版本,下载下来之后解压缩到喜欢的位置然后双击Eclipse.exe启动 然后开始新建项目,File ...

  2. 二项分布。计算binomial(100,50,0.25)将会产生的递归调用次数(算法第四版1.1.27)

    算法第四版35页问题1.1.27,估计用一下代码计算binomial(100,50,0.25)将会产生的递归调用次数: public static double binomial(int n,int ...

  3. 算法第四版jar包下载地址

    算法第四版jar包下载地址:https://algs4.cs.princeton.edu/code/

  4. 算法第四版-文字版-下载地址-Robert Sedgewick

    下载地址:https://download.csdn.net/download/moshenglv/10777447 算法第四版,文字版,可复制,方便copy代码 目录: 第1章 基 础 ...... ...

  5. 算法第四版学习笔记之优先队列--Priority Queues

    软件:DrJava 参考书:算法(第四版) 章节:2.4优先队列(以下截图是算法配套视频所讲内容截图) 1:API 与初级实现 2:堆得定义 3:堆排序 4:事件驱动的仿真 优先队列最重要的操作就是删 ...

  6. 算法第四版学习笔记之快速排序 QuickSort

    软件:DrJava 参考书:算法(第四版) 章节:2.3快速排序(以下截图是算法配套视频所讲内容截图) 1:快速排序 2:

  7. 配置《算法 第四版》的Eclipse开发环境

    1. 安装JAVA JAVA网址:http://www.oracle.com/technetwork/java/javase/downloads/index.html 配置环境变量(我把JAVA安装在 ...

  8. 用eclipse运行算法第四版的BinarySearch

    import java.util.Arrays; import edu.princeton.cs.algs4.In; import edu.princeton.cs.algs4.StdIn; impo ...

  9. 算法第四版 coursera公开课 普林斯顿算法 ⅠⅡ部分 Robert Sedgewick主讲《Algorithms》

    这是我在网上找到的资源,下载之后上传到我的百度网盘了. 包含两部分:1:算法视频的种子 2:字幕 下载之后,请用迅雷播放器打开,因为迅雷可以直接在线搜索字幕. 如果以下链接失效,请在下边留言,我再更新 ...

随机推荐

  1. Velocity 语法(转)

    一.基本语法 1."#"用来标识Velocity的脚本语句,包括#set.#if .#else.#end.#foreach.#end.#iinclude.#parse.#macro ...

  2. Hadoop_UDF示例

    UDF:  一进一出 Eclipse端 1. 继承UDF 2. 实现evaluate方法(可重裁实现多个evaluate方法,以实现不同需求) 3. 导出类jar包,注意指定main方法 Hive端 ...

  3. KVM 基本命令

    一.问题描述: KVM中宿主机通过console无法连接客户机,卡在这里不动了. # virsh console vm01 Connected to domain vm01 Escape charac ...

  4. sql语句 之聚合函数

      聚合分析 在访问数据库时,经常需要对表中的某列数据进行统计分析,如求其最大值.最小值.平均值等.所有这些针对表中一列或者多列数据的分析就称为聚合分析. 在SQL中,可以使用聚合函数快速实现数据的聚 ...

  5. 第一个python程序

    一个python程序的两种执行方式: 1.第一种方式是通过python解释器: cmd->python->进入python解释器->编写python代码->回车. 2.第二种方 ...

  6. HDU 4757 Tree(可持久化Trie+Tarjan离线LCA)

    Tree Time Limit: 10000/5000 MS (Java/Others)    Memory Limit: 102400/102400 K (Java/Others) Total Su ...

  7. Python强化训练笔记(五)——找出多个字典中的公共键

    在这个问题中,我们期望得到的结果是找到这三轮比赛中,每轮都进球的球员都有谁.下面用python来模拟一下,先生成一批数据: >>> from random import randin ...

  8. Clang比 gcc/g++更人性化代码出错提示的C/C++编译器

    编译器方面的几个命令 gcc/g++ 一. 常用编译命令选项 常用用法 gcc -Wall test.c -o test gcc编译过程 .c ->(-E)-> .i[中间文件] -> ...

  9. Flink - NetworkEnvironment

    NetworkEnvironment 是一个TaskManager对应一个,而不是一个task对应一个 其中最关键的是networkBufferPool, operator产生的中间结果,Result ...

  10. android逆向代码分析截图