学习如何学习--对抗拖延症

番茄工作法 科学家通过分析表明,人都会无意识地避开困难的东西。如何避开?我们使用的机制就是当我们面对困难时,我们会把注意力转移到可以令自己开心的事情上去,例如上网,看视频,玩游戏。然后时间就这么过去了,正事一点都没有做。 为了克服人的惰性,上世纪八十年代 Francesco Cirillo 创立了番茄工作法,原理其实很简单: 确定待完成的任务 专注工作25分钟(人的专注时间) 5分钟时间的休息,适当奖励自己,喝喝咖啡,伸伸懒腰。 每完成4个 1到3 的循环就休息15-30分钟。

January 5, 2016

Android Studio For Experts

自动完成 auto completion ctrl + space 选择后按 tab 可以覆盖原理的方法。 shift + ctrl + space 更加聪明的补全方式 selection extend selection alt + ↑ intention alt + enter 对于构造函数,可以自动生成private 变量并赋值,增加变量可自动添加。 在 instanceCheck 中可以自动生成 cast 代码 suppress templates fori list.for 自动生成循环 logi logd loge 打印 logt 生成 TAG logm 方法开头用 logr 方法结尾用 command + n 弹出Generate 布局 tools:showIn="@layout/fragment_sign_in" 可以包含另一个布局来预览 tools 关键字可以用在不同的参数上,用上后该参数只会在预览中有效。 public.xml 可以暴露想暴露的属性给 ide 格式为 <resources> <public name="ccl_app_name" type="string"/> </resources> ctrl + tab Switcher How to use debugger To find an action ...

November 26, 2015

Priority Queues

定义 不同于 Stack 的 FIFO 和 Queue 的 FILO。Priority Queue 总是删除集合中最大(或最小)的数。例如 operation argument return value insert P insert Q insert E remove max Q insert X insert A insert M remove max X insert P insert L insert E remove max P 如果使用数组来实现 Priority Queue 的插入和删除操作,需要的时间复杂度和理想的时间复杂度如下 implementation insert del max max unorded array 1 N N ordered array N 1 1 goal logN logN logN 有一种数据结构可以实现目标的时间复杂度,我们叫它做二叉堆 ...

September 29, 2015

Tree

BST BST 的特性就是左子树都比本节点小,右子树都比本节点大。 private class Node { private Key key; private Value val; private Node left, right; public Node(Key key, Value val) { this.key = key; this.val = val; } } public class BST<Key extends Comparable<Key>, Value> { private Node root; public void put(Key key, Value val) { root = put(root, key, val); } private Node put(Node x, Key key, Value val) { if (x == null) return new Node(key, val); int cmp = key.comapreTo(x.key); if (cmp < 0) x.left = put(x.left, key, val); else if (cmp > 0) x.right = put(x.right, key, val); else x.val = val; return x; } public Value get(Key key) { Node x = root; while(x != null) { int cmp = key.comapreTo(x.key); if (cmp < 0) x = x.left; else if (cmp > 0) x = x.right; else return x.val; } return null; } public void delete(Key key) { root = delete(root, key); } private Node delete(Node x, Key key) { if (x == null) return null; int cmp = key.comapreTo(x.key); if (cmp < 0) x.left = delete(x.left, key); else if (cmp > 0) x.right = delete(x.right, key); else { if (x.right == null) return x.left; if (x.left == null) return x.right; Node t = x; x = min(t.right); x.right = deleteMin(t.right); x.left = t.left; } x.count = size(x.left) + size(x.right) + 1; return x; } public Iterable<Key> iterator { Queue<Key> q = new Queue<Key>(); inorder(root, q); return q; } private void inorder(Node x, Queue<Key> q) { if (x == null) return; inorder(x.left, q); q.enqueue(x.key); inorder(x.right, q); } } floor 寻找比 Key 小的数中最大的数 ...

August 20, 2015

Sort

Selection sort In iteration i, find index min of smallest remaining entry. Swap a[i] and a[min] i 从0开始,找到数组中最小的,与i交换,i++,直到 i 等于数组长度。 Comparable[] a; int N = a.length; for(int i = 0; i < N; i++) { int min = i; for(int j = i + 1; j < N; j++) { if(less(a[j], a[min])) min = j; } exch(a, i, min); } Both best case and worst case: ...

August 9, 2015