随笔分类 -  HackerRank

https://www.hackerrank.com
摘要:题目链接:Median做了整整一天T_T尝试了各种方法:首先看了解答,可以用multiset,但是发现java不支持;然后想起来用堆,这个基本思想其实很巧妙的,就是维护一个最大堆和最小堆,最大堆存放前半部分较小的元素,最小堆存放后半部分较大的元素,并且最大堆的所有元素小于最小堆的所有元素;保持最大堆... 阅读全文
posted @ 2014-08-18 22:54 SunshineAtNoon 阅读(642) 评论(0) 推荐(0) 编辑
摘要:题目链接:Coin on the Table一开始想用DFS做的,做了好久都超时。看了题解才明白要用动态规划。设置一个三维数组dp,其中dp[i][j][k]表示在时间k到达(i,j)所需要做的最小改动,那么递推式如下:图片来源:Editorial,其中当从周围的格子可以直接移动到(i,j)时,de... 阅读全文
posted @ 2014-08-18 14:14 SunshineAtNoon 阅读(744) 评论(0) 推荐(0) 编辑
摘要:题目链接:Pairs完全就是Two Sum问题的变形!Two Sum问题是要求数组中和正好等于K的两个数,这个是求数组中两个数的差正好等于K的两个数。总结其实就是“骑驴找马”的问题:即当前遍历ar[i],那么只要看数组中是否存在ar[i]+K或者ar[i]-K就可以了,还是用HashMap在O(1)... 阅读全文
posted @ 2014-08-15 15:52 SunshineAtNoon 阅读(266) 评论(0) 推荐(0) 编辑
摘要:题目链接:Cut the tree题解:题目要求求一条边,去掉这条边后得到的两棵树的节点和差的绝对值最小。暴力求解会超时。如果我们可以求出以每个节点为根的子树的节点之和,那么当我们去掉一条边(a,b)的时候,其中的一棵树必是以a或者b为根的子树,那么我们就可以知道生成的两棵树的节点之和了。所以,当我... 阅读全文
posted @ 2014-08-15 15:29 SunshineAtNoon 阅读(786) 评论(0) 推荐(0) 编辑
摘要:Numeros, The Artist, had two listsAandB, such that,Bwas a permutation ofA. Numeros was very proud of these lists. Unfortunately, while transporting th... 阅读全文
posted @ 2014-08-15 12:50 SunshineAtNoon 阅读(701) 评论(0) 推荐(0) 编辑
摘要:Sorting is often useful as the first step in many different tasks. The most common task is to make finding things easier, but there are other uses als... 阅读全文
posted @ 2014-08-15 11:41 SunshineAtNoon 阅读(574) 评论(0) 推荐(0) 编辑
摘要:In the Quicksort challenges, you sorted an entire array. Sometimes, you just need specific information about a list of numbers, and doing a full sort ... 阅读全文
posted @ 2014-08-14 17:58 SunshineAtNoon 阅读(1818) 评论(1) 推荐(0) 编辑
摘要:One classic method for composing secret messages is called a square code. The spaces are removed from the english textand the characters are written i... 阅读全文
posted @ 2014-08-14 17:02 SunshineAtNoon 阅读(421) 评论(0) 推荐(0) 编辑
摘要:Sunny and Johnny together have M dollars which they intend to use at the ice cream parlour. Among N flavors available, they have to choose two distinc... 阅读全文
posted @ 2014-08-14 15:17 SunshineAtNoon 阅读(500) 评论(0) 推荐(0) 编辑
摘要:There areNintegers in an arrayA. All but one integer occur in pairs. Your task is to find out the number that occurs only once.Input FormatThe first l... 阅读全文
posted @ 2014-08-14 11:51 SunshineAtNoon 阅读(283) 评论(0) 推荐(0) 编辑
摘要:题目链接:Running Time of QuicksortChallengeIn practice, how much faster is Quicksort (in-place) than Insertion Sort? Compare the running time of the two a... 阅读全文
posted @ 2014-08-13 13:25 SunshineAtNoon 阅读(867) 评论(0) 推荐(0) 编辑
摘要:Insertion Sort is a simple sorting technique which was covered in previous challenges. Sometimes, arrays may be too large for us to wait around for in... 阅读全文
posted @ 2014-08-12 16:37 SunshineAtNoon 阅读(883) 评论(0) 推荐(0) 编辑
摘要:题目连接:Sherlock and MiniMaxWatson gives Sherlock an arrayA1,A2...AN.He asks him to find an integerMbetweenPandQ(both inclusive), such that,min {|Ai-M|, ... 阅读全文
posted @ 2014-08-03 21:28 SunshineAtNoon 阅读(1174) 评论(0) 推荐(0) 编辑
摘要:题目连接:Game Of RotationMark is an undergraduate student and he is interested in rotation. A conveyor belt competition is going on in the town which Mark... 阅读全文
posted @ 2014-08-02 22:24 SunshineAtNoon 阅读(425) 评论(0) 推荐(0) 编辑
摘要:有n组好朋友在公交车站前排队。第i组有ai个人。还有一辆公交车在路线上行驶。公交车的容量大小为x,即它可以同时运载x个人。 当车站来车时(车总是空载过来),一些组从会队头开始走向公交车。 当然,同一组的朋友不想分开,所以仅当公交车能容纳下整个组的时候,他们才会上车。另外,每个人不想失去自己的位置,即... 阅读全文
posted @ 2014-08-02 21:32 SunshineAtNoon 阅读(513) 评论(0) 推荐(0) 编辑
摘要:给你一个n*n的地图。地图中的每个格子有一个值表示该地区的深度。我们称一个地图中的一个格子为空洞,当且仅当该格子不在地图边缘并且每个和它相邻的格子都具有比它更小的深度。两个格子称为相邻如果它们共有一条边。你要找到地图中所有的空洞,并且用X描述。输入格式第一行包含一个整数n,表示地图的规模。 接下来n... 阅读全文
posted @ 2014-08-02 13:11 SunshineAtNoon 阅读(346) 评论(0) 推荐(0) 编辑
摘要:Watson gives an array A1,A2...AN to Sherlock. Then he asks him to find if there exists an element in the array, such that, the sum of elements on its ... 阅读全文
posted @ 2014-08-02 11:10 SunshineAtNoon 阅读(467) 评论(0) 推荐(0) 编辑
摘要:QuickSortIn the previous challenge, you wrote a partition method to split an array into 2 sub-arrays, one containing smaller elements and one containi... 阅读全文
posted @ 2014-08-02 09:49 SunshineAtNoon 阅读(1073) 评论(0) 推荐(0) 编辑
摘要:In this challenge you need to print the data that accompanies each integer in a list. In addition, if two strings have the same integers, you need to ... 阅读全文
posted @ 2014-08-01 19:38 SunshineAtNoon 阅读(1733) 评论(0) 推荐(0) 编辑
摘要:Sherlock and The BeastSherlock Holmes is getting paranoid about Professor Moriarty, his archenemy. All his efforts to subdue Moriarty have been in vai... 阅读全文
posted @ 2014-07-30 10:58 SunshineAtNoon 阅读(610) 评论(0) 推荐(0) 编辑

点击右上角即可分享
微信分享提示