上一页 1 2 3 4 5 6 7 8 9 ··· 26 下一页
摘要: 题目链接:Turbo Sort用java自带O(NlogN)的排序就可以,java要特别注意输入输出。输入用BufferedReader,输出用printWriter。printWriter的速度比System.out快很多,参考StackOverflow。代码: 1 import java.io.... 阅读全文
posted @ 2014-08-19 10:55 SunshineAtNoon 阅读(204) 评论(0) 推荐(0) 编辑
摘要: 题目链接:Median做了整整一天T_T尝试了各种方法:首先看了解答,可以用multiset,但是发现java不支持;然后想起来用堆,这个基本思想其实很巧妙的,就是维护一个最大堆和最小堆,最大堆存放前半部分较小的元素,最小堆存放后半部分较大的元素,并且最大堆的所有元素小于最小堆的所有元素;保持最大堆... 阅读全文
posted @ 2014-08-18 22:54 SunshineAtNoon 阅读(619) 评论(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 阅读(262) 评论(0) 推荐(0) 编辑
摘要: 题目链接:Cut the tree题解:题目要求求一条边,去掉这条边后得到的两棵树的节点和差的绝对值最小。暴力求解会超时。如果我们可以求出以每个节点为根的子树的节点之和,那么当我们去掉一条边(a,b)的时候,其中的一棵树必是以a或者b为根的子树,那么我们就可以知道生成的两棵树的节点之和了。所以,当我... 阅读全文
posted @ 2014-08-15 15:29 SunshineAtNoon 阅读(774) 评论(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 阅读(694) 评论(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 阅读(572) 评论(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 阅读(1777) 评论(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 阅读(416) 评论(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 阅读(497) 评论(0) 推荐(0) 编辑
上一页 1 2 3 4 5 6 7 8 9 ··· 26 下一页