1 | findFirstByOrderByIdDesc() // 1.查询ID最大的一条数据,注意first后面要跟by()。 |
KMP algorithm
很久以前看到的KMP算法,重新回顾了一下。主要就是如何寻找next数组。
对于类似字符串A,aaaaaaab,与字符串B,aaab。寻找A中包含字符串B的位置。
如果使用暴力搜索,每次失配都需要从A的下一位开始,但其实并不用。对于这个例子来说,
前面的两位是不需要再次判断的,因为有公共的前后缀,因此构建一个next数组如下。
B: a a a b
index: 0 1 2 3
next: 0 1 2 0
假设我们已经知道了aa这个字符串的值为1,那么如果新加入另一个字母a,则判断index为1的值和该值是否相同。
相同,则在之前的前缀表长度加一,如果不同,则找到前一个字符的前缀表,进行如上的判断。
最后进行匹配的时候,则在失配时候可以直接跳过已经匹配过的前缀。
hadoop ArrayWritable实现自定义类
感觉网上的博客对于如何重写arraywritable并不是很详细,自己重新整理了一下,如何使用arraywritable存放复杂类。
1 | public class MyArrayWritable extends ArrayWritable { |
完美世界2020Java开发
完美世界2020Java游戏开发笔试
做了一下完美的Java笔试。发现关于类的东西忘光了,好久不写。编程题的一个题大概是自己创建一个栈,实现一些功能,返回最大最小元素,min,max,以及pop和push四个功能。
确实很简单,但是基础的东西有点忘了,第一题没写出来就直接退了。
虽然事后看到有人直接在Main函数里建一个自带的Stack就可以了。不过僵硬在创建class上了。
发现主要原因好像是忘了在Stack类中加入static修饰,没用本地IDE,半天没有运行成功。
下面重新把两道题都写一下。
puzzle9-problem
1.The 9 puzzle描述
2.代码分析部分
3.延伸N宫格
The 9 puzzle描述
Dispatch the integers from 0 to 8, with 0 possibly changed to None, as a list of 3 lists of size 3, to represent a 9 puzzle.
For instance, let [[4, 0, 8], [1, 3, 7], [5, 2, 6]] or [[4, None ,8], [1, 3, 7], [5, 2, 6]] represent the 9 puzzle
SelectTermAndCourse
学了Shell之后,感觉学校的HandBook太蠢了,没有选项根据学期来分离课程,毕竟选课的时候是根据学期来选的,你只在页面上看到了这门课,但是点进去才发现不是这学期的。就很浪费时间。
所以用shell写了一个脚本可以直接将课程代码与他开设的学期对应起来,下次再找课的时候就会比较的方便。
1 | URL=https://www.handbook.unsw.edu.au/postgraduate/courses/2019/ |
代码也是非常的简单,基本就是使用了一些基本的命令,egrep,sed,head等等之类。不过还是省了不少事,爽
prolog学习
Write a prolog predicate insert(Num, List, NewList) that takes a number Num along with a list of numbers List which is already sorted in increasing order, and binds NewList to the list obtained by inserting Num into List so that the resulting list is still sorted in increasing order.
QuickSort
一般的快排,效率是稍微低一点的。
1 | public void quickSort(int[] arr, int begin, int end) { |
所以可以有两个标记i,j,从两边靠拢。初始的i = begin,j = end,用k来扫描整个序列。
始终保持序列中[start,i] < pivot; [i,k] = pivot; [j ,end] > pivot的。
因此当遇到小于pivot的元素,swap(arr,i,k),i++
当遇到大于pivot的元素,swap(arr,j,k),j–
1 | public int partition(int[] arr, int begin, int end) { |
还有另一种实现方式,也就是双轴快排(DualPivotQuickSort),也是JDK1.8对基本数据类型排序的实现。
看一下源码是怎么实现的。可以看出是分成了三段,取两个中心点。pivot1,pivot2,且pivot <= pivot2,可将序列分成三段:x < pivot1、pivot1 <= x <= pivot2,x > pivot2
1 | /* |
根据这个,大概实现了一下。
1 |
|
COMP9021tangram
2. Background
The game of tangram consists in creating shapes out of pieces. We assume that each piece has its own colour,
different to the colour of any other piece in the set we are working with. Just for reference, here is the list of
colours that are available to us (you will not make use of this list):