自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

算法,时空数据挖掘

Spatial-Temporal Application and Data Analysis

  • 博客(183)
  • 资源 (7)
  • 收藏
  • 关注

原创 leetcode - Search in Rotated Sorted Array II

有duplicate的确会有影响,最坏情况下复杂度为O(n)。产生影响的例子(1)5,5,5,5,9,5(2)5,9,5,5,5,5这种情况下没有办法知道该如何二分。只能简单枚举了,两种枚举办法:(1)枚举最左端(l++) 或者最右端(r--)(2)我这里的策略比较暴力,当没法二分时候,我直接从左到右遍历一边,看看target在不在。public class S

2015-02-08 12:51:58 772

原创 Validate Binary Search Tree_Leetcode

一开始以为是题目SB,只是简单比较了父节点和子节点的值。结果发现原来是自己SB了,除了考虑父节点,还要考虑祖先节点的值,所以要用两个参数来记录每个节点valid的范围(根据父节点的值来不断调整)。public class Solution { public boolean isValidBST(TreeNode root) { if(root == null) ret

2015-01-24 11:23:14 708

原创 Leetcode_Restor IP Address

简单的枚举,关键是corner case。 分成四段,不能多不能少,每段的数字只能从0-255,但是注意0开头的情况,"01","025"都是不行。import java.util.*;public class Solution { public List restoreIpAddresses(String s) { List ips = new LinkedLis

2015-01-24 10:37:17 747

原创 Cut the tree _ HackerRank

有意思的题目,但是题目描述不正确(貌似阿三哥出的题目),让我走了一些弯路,很tmd无语。。输入严格来说根本不是树,是图来的,因为边是无向边。。但是它的输入保证了是没有环路的图,所以某种程度上可以看做是树(任何一个节点都可以为根节点,然后递归地把每个节点的邻居看做子节点)。不过话说回来如果一开始告诉我这个图,我还真想不出来解法。。但是因为它“误导”了我,让我认为它是一颗树后,问题就简单了

2015-01-18 13:27:11 1332

原创 Similar Pair _ HackerRank

Hacker rank真的比leetcode 难了不止一个等级。。这题有点巧妙。。深度搜索每条路径,然后枚举,基本很多人都想的出来,但是关键在于这样肯定超时。巧妙之处在于要给每条路径建立一个线段树来加速查询,每次similar查询复杂度从O(h)变成O(lgh)。。犯了两个错误(1)要用long来存储线段树,已经可能的similar pairs。 (2)值减去T可能

2015-01-18 05:44:56 2576

原创 Leetcode subsets2

第一次提交犯了个常见错误,调用下面for循环的时候,在for里面修改了subsets,这样子会抛异常。以后得注意,调用iteractor来遍历一个collection时候,不能在遍历里面改变这个collection的长度(增加,删除节点)。for(List subset : subsets){import java.util.*;public class Solution {

2014-12-30 13:56:32 915

原创 Leetcode Permutation2

去重的关键在于同样的数字,序号必须总是升序(或者 )

2014-11-24 10:40:50 980

原创 merge interval

常规做法,排序然后合并。import java.util.*;public class Solution { class IntervalComp implements Comparator{ @Override public int compare(Interval inte1, Interval inte2) { if(inte1

2014-11-22 12:24:10 894

原创 Leetcode - insert interval

这题其实出的不好,没有说清楚Limport java.util.*; public class Solution { int bSearch(List intervals, int val) { int n = intervals.size() ; if(val < intervals.get(0).start) { return -

2014-11-22 10:59:59 604

原创 WordladderII

import java.util.*;public class Solution { List> travelPath(String start, String cstr, Map> prevs_map){ List> paths = new LinkedList>(); if(start.equals(cstr)) { List path = new L

2014-11-01 10:54:07 927

原创 Best Time to Buy and Sell Stock II

明白了上一题是求最大的连续子数组之和后,这题就更加简单了,遇到小于0的就不要加。public class Solution { public int maxProfit(int[] prices) { if(prices.length < 2) return 0; int n = prices.length;

2014-10-18 23:17:20 918

原创 Leetcode - Best Time to Buy and Sell Stock

知道是求连续最大子数组后就简单了。但是注意边界条件,如果最大子数组之和<0,那就不要交易了, 返回0.public class Solution { public int maxProfit(int[] prices) { if(prices.length < 2) return 0; int n = prices.

2014-10-18 23:09:05 937

原创 Leetcode- LRUCache

关键是搞懂题目(不知道LRUCache的只能自己google了)。然后用双向链表来模拟cache被get和set。但是naive implementation会exceed time limit。所以最大的关键是用一个HashMap来记录key在链表中的位置,这样子每次查询是O(1)的时间,否则O(n)。这个也是很经典的用Map来加速双向链表查询的思路(前提是key要唯一)。i

2014-10-18 12:19:27 1489

原创 Leetcode - Insertion Sort List

It is quite a basic problem.  However I spent half an hour solving it and made two mistakes. Guess it's because I haven't written some fundamental data structures like linked list for a while and kind

2014-10-12 06:27:40 945

原创 Leetcode - GasStation

An kind of interesting problem.  Use an array arr[] to store how many gas are left if we travel from station i to station i+1, arr[i] = gas[i] - cost[i]. Then it becomes an variance of the maximal sub

2014-10-12 05:14:30 940

原创 Leetcode - WordBreak

试着写了个前缀树,352 ms。  其中最大的trick是要用一个数组 boolean[] searchFlag来记录从s[i]开始的子串(s[i...n-1])是否被搜索过(s[i...n-1]能否由dict的单词组成)。如果被搜索过那就不用再搜索了(因为搜索失败了,如果成功的话程序早已结束)。import java.util.*;public class Solutio

2014-10-12 04:13:22 1105

原创 Leetcode - Single Number II

The key is to use two constant space(32 bits) to store how many times 1 or 0 showed up in the bit i. If times of 1 in bit i is not the multiple of 3, then the unique value's bit i is 1. Otherwise the

2014-10-09 11:36:14 843

原创 Leetcode - CopyWithRandomList

Algorithm: Iterate copy the original list first. For the random pointer, copy its original value(address) first. And during the iterate, use a map to store each node's original address and the corresp

2014-10-09 00:39:28 1131

原创 Leetcode - linked list circle 2

貌似国内面试经常问得题目,以前没遇到过。。思路:1: 两个指针,一个一次走两格,一个一次走一个。相遇了证明有环。2: 然后因为快的那个总是比慢的那个走快一步,当他们相遇后,再走k步(k是circle的结点数量)后,他们会再相遇,从而求出circle结点数量。3: 最后再设置两个指针(都是一次走一步),但一开始一个比另外一个领先k步,那么它们就会刚好在环的起点相遇。。但是

2014-10-08 23:28:09 1350

原创 LeetCode - Sort List

就是用List来实现merge sort.import java.io.*;import java.util.*; class ListNode { int val; ListNode next; ListNode(int x) { val = x; next = null; } s

2014-10-07 10:36:21 853

原创 Leetcode - Evaluate Reverse Polish Notation

初看貌似有点复杂,但是搞懂了非常简单,就一个简单的栈应用,每次遇到计算符号"+", "-", "*", "/"就将栈顶端两个数字出栈,计算后再将结果压栈即可。。#include#include#includeusing namespace std;class Solution {public: int evalRPN(vector &tokens) { stack s

2014-10-03 12:22:01 803

原创 DP Leetcode - Maximum Product Subarray

最近一直忙着写paper,很久没做题,一下子把题目搞复杂了。。思路理清楚了非常简单,每次只需更新2个值:最大乘积和最小乘积。最大乘积被更新有三种可能:当前A[i]>0,乘以前面最大的数(>0),得到新的最大乘积;当前A[i]0,(A[i-1]==0。最小乘积同理。。class Solution {public: int Max(int a, int b, int c) {

2014-10-02 00:55:11 1386

原创 Leetcode - candy

被第二个条件给坑了You are giving candies to these children subjected to the following requirements:Each child must have at least one candy.Children with a higher rating get more candies than their ne

2014-08-23 10:58:10 975

原创 Leetcode - Binary Tree Maximum Path Sum

解题的关键在于这条路径只能是先往上走,到达某个最高点,再往下走,换句话说,只能有一次转折的机会。所以递归这棵树,记录以某个子节点为转折点时的最大值。值得注意的是树节点的值有负值,所以如果某个子路径的和小于0,放弃它(设置和为0)。class Solution {public: int maxPathSum(TreeNode *root) { int maxSum = -1 <

2014-08-23 09:47:04 935

原创 Leetcode 3Sum Closet

用了和3Sum差不多一样的思路,二分查找。关键要剪枝,但是却在剪枝那里犯了很多错误。然后原来有一个更加快的思路O(n^2).#include #include #include #include using namespace std;class Solution {public: int threeSumClosest(vector &num, int ta

2014-07-27 06:35:49 1116

原创 Leetcode - 3Sum

蛮常见一道题目。思路:1:排序,按顺序遍历两个数之和twoSum,2: 二分查找 (0 - twoSum)看是否存在这题最容易错的地方是must not contain duplicate triplets,所以遍历的这时候要用一个数字记录最后一个遍历的数字是,避免重复。#include#include #include using namespace s

2014-07-26 23:50:15 808

原创 Leetcode - Jump Game Two

class Solution {public: const int MAXVALUE = 1 << 30; int findMinStepToIndex(int maxNumbers[],int maxSteps,int index) { if (index == 0) return 0; int left = 1; int right = maxSteps;

2014-07-26 06:24:41 835

原创 LeetCode - Jump Game

一开始想DP一步步迭代更新,求出到跳到最后一个的最小步数,但是时间复杂度O(nk),会超时。再一想,发现该题只需要返回能否到达最后一个,不需要最小步数,所以迭代时候只需要保留当前能够走到的最远距离tmpMax,时间复杂度降到O(n)。class Solution {public: const int MAXVALUE = 1 << 30; bool canJump(int A[],

2014-07-26 04:01:11 795

转载 C++ - Priority_Queue

A good introduction article from http://comsci.liu.edu/~jrodriguez/cs631sp08/c++priorityqueue.htmlC++  priority queuesA priority queue is an abstract data type that captures the idea

2014-06-17 10:48:31 774

原创 LeetCode Decode Ways

有点意思的题目。用动态规划可以O(n)求解出来:a[i]代表子字符串string(0,i)的可能解码方式,a[i] = {a[i-1] or a[i-1]+a[i-2]}.  意思是如果string(i)不为0,至少a[i] == a[i-1],即一种解码方法是string{0,.....(i-1)}+string(i);   然后如果string{i-1,i}是合法的(注意合法概念,比如

2014-05-27 03:53:56 1130

原创 Leetcode - Reverse Words

比起POJ弱爆了一题,从后往前扫描一遍,O(n)时间,只要注意各种极端情况即可,不明白通过率为什么只有13%。#include#includeusing namespace std;class Solution {public: void reverseWords(string &s) { char* cstr = new char[s.size()+1];

2014-05-27 00:54:12 1063

原创 POJ2286 -IDA*

第一次IDA*。很有意思的思路。IDA*重点和A*不一样,A*总是看当前最优的估值函数f()=g()+h(),但IDA*不一样,只要深度在允许范围内,IDA*就不断地深搜,不管f()的大小。另外一个值得mark当要连续对不规则的数组进行有规律的操作时候,可以建立个映射数组。附代码,不过这个代码写的有点丑陋,另外值得参考的代码http://www.cnblogs.com/zhsl/archi

2014-05-13 05:31:26 957

原创 poj 2559求柱形图中最大矩形

两种解法。我想到的是最大的矩形,中间一定有个最矮的某个单位矩形,所以用两个数组记录任何一个单位矩形histogram[i]左右两边第一个比它小的单位矩形的序号,这里找的时候用DP加速。#includeusing namespace std;//the histogram stored from left to rightlong histogram[100001]

2014-05-08 00:16:27 1628

原创 POJ3714 最近点对

变形了的最近点对,关键在于计算距离的时候,如果同类点的话,直接判定为无穷大即可。其他闲话:(1)因为一些原因,被迫暂时用回C++.(2)好久没刷题,忘记了数组一开始要开最大,多次new和delete,导致超时。(3) 感觉算法导论的最近点对没有考虑到有多个点都在一条vertical line上的情形。#include#include#include#include

2014-05-07 09:48:16 1659

原创 PostgreSQL special sql 1 - list all the columns and primary key

There are a few special sql commands that I used often recently, mark them here.1: Show all the columns' nameSELECT * FROM INFORMATION_SCHEMA.COLUMNS WHERE TABLE_NAME='yourtablename';

2014-03-30 04:40:31 933

原创 Transfer postgres database to another server - backup and restore

Currently I want to transfer all my local database to the remote server and I found a very simple solution.  (1) Backup your database [1]  (2) Transfer the backup to the destination server.  (3)

2014-03-29 00:14:29 720

原创 Create Remote Database Server - PostgreSQL

As I said yesterday that I tried to create a remote PostgreSQL database on the Ubuntu Server hosted by DigitalOcean. After I created the PostgreSQL, I met some problems connecting to the remote databa

2014-03-28 01:15:51 801

原创 Install The PostgreSQL on the Ubuntu Server hosted by the Digital Ocean

Today I tried to install the postgresql on the ubuntu server hosted by the digital ocean like[1]. It should be a quite easy task. But I kept getting errors when I typed the command "psql", the error s

2014-03-27 09:55:31 1524

原创 Install PostgreSql and PostGIS On Ubuntu Server

There is an article[1] for installing PostgreSQL on Ubuntu. [2] actually is a even better one if you want to install PostgreSQL and PostGIS at the same time.  In order to use PostGIS in database, yo

2014-03-27 02:52:48 850

原创 Openstack Exploring - nova list no output

I have read some documents  and they all say that the command  "nova list" can output all the instances[1]. But when I try, nothing output. Then I search and got a good explanation in [2].[1

2014-03-23 07:21:48 711

一个Silverlight的DateBinding和DataTemplate的Demo

一个Silverlight的DateBinding和DataTemplate的小Demo。通过DataBinding在界面上显示我个人事务的类TaskCollection。

2012-04-28

基于GPU的3D空间精确三角形拾取

用Directx11的ComputeShader和GeometryShader做的3D空间精确拾取,点击左键,程序判断是否选中了模型某个三角形,如果选中了则显示该三角形,其他以网格方式显示。

2011-12-21

串行的BitonicSort双调排序

CPU串行的BitonicSort双调排序

2011-12-20

Directx11绘制立方体

Directx11绘制一个立方体和四面体,用了我博客一个简单的框架封装,适合初学者学Directx11程序。

2011-12-20

InteliShade

InteliShade,vs的插件,安装后可以高亮.FX文件。

2011-08-17

usertype.dat

HLSL的关键字,放在vs的IDE文件下,以在vs中高亮HLSL的关键字

2011-08-17

Directx11中使用PhysX

在Directx11中使用PhysX物理引擎的小Demo。按a健就会看到盒子掉下来。

2011-08-13

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除