Tony's Log

Algorithms, Distributed System, Machine Learning

  博客园 :: 首页 :: 新随笔 :: 联系 :: 订阅 :: 管理 ::

04 2015 档案

摘要:My first reaction was, total No. of strings - no. of palindromic strings. But looks like counting all palindromic strings is not that easy.. So it has... 阅读全文
posted @ 2015-04-30 15:30 Tonix 阅读(249) 评论(0) 推荐(0)

摘要:Please note input constraints. String length will not exceed 100, which means, we can use relatively naive representation\calculation for anagrams: so... 阅读全文
posted @ 2015-04-30 13:29 Tonix 阅读(477) 评论(0) 推荐(0)

摘要:Sieve of Eratosthenesclass Solution {public: int countPrimes(int n) { if(n rec(n + 1, false); int bound = floor(sqrt(n)); i... 阅读全文
posted @ 2015-04-30 01:04 Tonix 阅读(145) 评论(0) 推荐(0)

摘要:Simplied a DFS\BFS with minor modification.#include #include #include #include #include #include using namespace std;typedef vector> Matrix;typedef pa... 阅读全文
posted @ 2015-04-27 14:16 Tonix 阅读(546) 评论(0) 推荐(0)

摘要:Typical tree recursion works. The key is: ANY node can be treated as the root, since it is about edge, not about node. This simplifies things a lot.#i... 阅读全文
posted @ 2015-04-27 14:14 Tonix 阅读(243) 评论(0) 推荐(0)

摘要:This is a super interesting bit problem. This link can be found in discussion panel:http://math.stackexchange.com/questions/712487/finding-xor-of-all-... 阅读全文
posted @ 2015-04-23 05:18 Tonix 阅读(441) 评论(0) 推荐(0)

摘要:Intuitive coding problem. But several details to take care.#include #include #include #include #include #include #include using namespace std;bool pla... 阅读全文
posted @ 2015-04-20 07:34 Tonix 阅读(211) 评论(0) 推荐(0)

摘要:Typical greedy\recursion algorithm.#include #include #include #include #include #include using namespace std;struct Node{ Node() : pinx(0), nodeCnt... 阅读全文
posted @ 2015-04-17 14:16 Tonix 阅读(328) 评论(0) 推荐(0)

摘要:Really interesting problem! My 1st solution was DP based, like bottom-up pattern, but it got TLE since it is O(n^2). Then I thought there must be a O(... 阅读全文
posted @ 2015-04-16 14:52 Tonix 阅读(400) 评论(0) 推荐(0)

摘要:Just picture the shifting process in your mind..class Solution {public: int rangeBitwiseAnd(int m, int n) { if (m == n) return m; int... 阅读全文
posted @ 2015-04-16 12:52 Tonix 阅读(121) 评论(0) 推荐(0)

摘要:A coding problem. The trick is, some part of computation can be reused from last iteration. Check out my code:#include #include #include #include #inc... 阅读全文
posted @ 2015-04-16 12:30 Tonix 阅读(319) 评论(0) 推荐(0)

摘要:I tried Python:def f(x,i,n,a,b,r,s,w): if(i>n):return r return f(x,i+1,n,a*x*x,b*2*i*(2*i+s),r+a*w/b,s,-w)n=int(input())for _ in range(n): v=... 阅读全文
posted @ 2015-04-16 10:18 Tonix 阅读(189) 评论(0) 推荐(0)

摘要:I saw a lot of BFS based solutions. And my alternative solution is this mirror-ed BST iterator one, with some book-keeping:class Solution {public: ... 阅读全文
posted @ 2015-04-13 11:28 Tonix 阅读(174) 评论(0) 推荐(0)

摘要:Floyd-Warshall算法其实是比较容易理解也比较容易coding的DP... 不说了,上代码:#include #include #include #include #include #include #include #include #include using namespace st... 阅读全文
posted @ 2015-04-07 13:19 Tonix 阅读(144) 评论(0) 推荐(0)

摘要:HihoCoder上有两道背包问题的problem,http://hihocoder.com/problemset/problem/1038 (01背包)#include #include #include #include #include #include #include using name... 阅读全文
posted @ 2015-04-03 05:05 Tonix 阅读(233) 评论(0) 推荐(0)