Affiliate初试

这篇文章只是为了尝试把cj上面ipage的链接加入博文,然后尝试点击 这是ipage注册的相关链接 …

算法题--蚂蚁与可重复4求和

蚂蚁题目如下: 一个长度问M的水平杆上有N只蚂蚁爬来爬去,位置已知但他们的方向不确定,一旦到了杆边缘就落下,如果两只方向相反的蚂蚁相遇则同时返回,问这N只蚂蚁全部落下的最短时间和最长时间。 如果所有可能的方向进行遍历,那么每只蚂蚁方向有两种选择,那么N只蚂蚁共有\(2^N\)中组合,复杂度过大,那么进行遍历计算显然是不可能的。 作者们巧妙的选择忽略蚂蚁之间的不同性,将两只相遇并反向行走的蚂蚁视为原来的按照同一方向走的蚂蚁即可,那么最短时间就是蚂蚁们朝最近边缘行走的蚂蚁所用的最长时间,而最长时间即为蚂蚁们朝较远边缘行走的蚂蚁所用的最长时间。直接转化为\(O(N)\)复杂度。 简略代码如下: int L, n, loc[maxN]; void solve(){ int minT=0, maxT=0; for(int i=0; i<n; i++){ minT = max(minT, min(loc[i], L-loc[i])); } for(int i=0; i<n; i++){ maxT = max(maxT, max(loc[i], L-loc[i])); } printf("%d %d",minT, maxT); } 可重复4求和题目:N张纸牌中,有放回的抽出4张,希望知道是否可能组成目标数字tar。 最简单的4重循环复杂度\(O(N^4)​\),疯了才会选。那么3重循环嵌套二分搜索,先排序,故而有\(O(NlogN)+O(N^3logN)=O(N^3logN)​\),我能想到的最优是,两层循环中嵌套左右两pointer进行搜索,复杂度为\(O(N^3)​\)这么远了。那么文中给了个最优简直牛皮,因为是有放回的抽取,所以排序后先计算一波\(c+d​\)进而排序,然后在二重循环内进行二分搜索,复杂度是\(O(N^2)+O(N^2log(N^2))+O(N^2log(N^2))=O(N^2logN)​\)。示意代码如下 int N, sum[NxN], nums[N], tar; void solve(){ for(int c=0;c<N;c++){ for(int d=0;d<N;d++){ sums[c*N+d] = nums[c]+nums[d]; } } sums=sort(sums); for(int a=0;a<N;a++){ for(int b=0;b<N;b++){ if bin_search(sums, tar-nums[a]-nums[b]) return True; } } return False; } …

Leetcode题3Sum解

题目要求是给定数组nums,求无重复三元组,使三元组相加为0。 Given array nums = [-1, 0, 1, 2, -1, -4], A solution set is: [ [-1, 0, 1], [-1, -1, 2] ] 以下算法复杂度O(n^2)且直接除去重复三元组 class Solution: def threeSum(self, nums): """ :type nums: List[int] :rtype: List[List[int]] """ nums = sorted(nums) #首先进行排序 res = [] i = 0 l = len(nums) while i < l: front = i+1 back = l - 1 target = - nums[i] #固定第一个元素并设定头尾两个flag while front < back: tmp = nums[front] + nums[back] if tmp < target: #若过小则左flag右移 front += 1 elif tmp > target: #若过大则右flag左移 back -= 1 else: #正好则加入res this = [nums[i], nums[front], nums[back]] res +=...…

Notes on Hashing 01

Supervised Hashing for Image Retrieval via Image Representation Learning(AAAI2014) Introducing a Two-Stage learning Scheme. A Simlarity Matrix \(S \in \{-1,1\}^{n\times n}\) is decomposed into \(HH^T\) where \(H \in \{-1,1\}^{n\times q}\) (Ofc a specific coordinate ascend updating scheme is given, with relaxation that \(H \in [-1,1]^{n\times n}\)) Then learned codes \(H\) is used to guide the learning of deep conv networks (Used classical Conv_Net 2012). Features in last FC layer are used to learn Binary codes and label info simultaneously. (最后的分支像不像GAN?) Existing Study showed that the code inner product \(H_{i\cdot }H^T_{j\cdot}\) has one to one correspondence to the Hamming distance between...…

Notes on Domain Adaptation

Domain Adaptation论文 ICML2015, Unsupervised Domain Adaptation by Backpropagation (DANN) Learn features that are domain-invariant (domain classifier) and discriminative (label predictor) Introduce a new gate “Gradient Reversal Layer” in applying sgd of adversarial objective (implementation) NIPS2016, Unsupervised Domain Adaptation with Residual Transfer Networks (RTN) learn discriminative features via Deep Architectures (CNN), minimize Maximum Mean Discrepancy(MMD) between source and target domain (Kronecker Product), DL insert residual layers between Source classifier and target classifier, learn permutation function Q: cross-entropy at target classifier ICML2017, Deep Transfer Learning with Joint Adaptation Networks (JAN) Joint Distribution of some untransferable layers are used to minimize the discrepancy...…

Talk Less, Code More

经历了一些我所谓的失败与不得意,做了一些其实没有多少深度的尝试。 虽然读了不同领域的文章,但没有找到好的问题, 并把这归结到一系列客观原因上。(比如没人讨论、没有经验etc) 并对自己的什么都没有做成感到生气与郁闷, 一直在讨论情绪 很少去反思自己 身边的朋友、同学开始发文章,开始做自己的模型,定schedule做东西。 优秀的朋友已经在blog上连载了不少深度炼丹的理解,对比之下只是抱怨的自己太弱了。 沉下来之后,知道想变好,想退出这个状态,情绪作祟太多。 快认不清自己了。 现在的我,读书变少了,锻炼变少了,睡眠不规整,科研没成果。 但现在明白了差距在哪,在于认真做事,潜心积累的时间。 既然选择了炼丹,选好了pytorch作工具,选好了Image Hashing作为接下来的方向,那就多读多复现多尝试。 Talk/Idea is Cheap, Show me the CODE …