08 2014 档案
摘要:250分题:给出一些规则,问街道上哪些地方可以停车。简单的模拟题,考察每条规则是否成立即可。代码:StreetParking500分题:实现集合的交,并和差运算。交运算:一个数组放到集合中,遍历另外一个数组,考察每个元素是否在第一个集合中。并运算:遍历两个数组,把两个数组中的每个元素放入集合中。差运...
阅读全文
摘要:250分题:给定一个4位字符串initial和rotate这个字符串的方式,然后再给另一个字符串current,问current能否由initial通过rotate得到,需要几次rotate?简单的模拟题,把rotate模拟好就行。代码:TireRotation500分题:给定一个等式,求出这个等式...
阅读全文
摘要:250分题:简单的二分,就是平常玩的猜数字游戏代码:GitHub500分题:给出一个员工一天的打卡时间段,要求求出员工这一天的工资。其中正常上班时间是6:00:00到18:00:00,薪水是wage,其他时间薪水是1.5*wage。我的思路比较直接,将时间分成三个时间段分别计算:00:00~06:0...
阅读全文
摘要:为什么平常刷的时候感觉还不错,比赛的时候只能做出来一道题=。=250分题:大水题,根据题目规则把一个字符串翻译成数字,直接代码:GitHub我是通过遍历一个个数出来的,看到大神的解法是把字符用‘-’这个符号分割,然后累加每一段的长度。500分题:给定一串数字,以及1~9每个数字出现的概率计算公式,然...
阅读全文
摘要:第一次做完整的SRM题,刷完感觉萌萌哒,不过自己对java中很多细节不熟练,还要边做题边google。250分的题:判断字符串序列是否是前缀码,如果不是,返回第一个违反前缀码规则的字符串。简单的暴力方法,要积累的是java中startsWith的用法:1 public boolean startsW...
阅读全文
摘要:题目链接:Turbo Sort用java自带O(NlogN)的排序就可以,java要特别注意输入输出。输入用BufferedReader,输出用printWriter。printWriter的速度比System.out快很多,参考StackOverflow。代码: 1 import java.io....
阅读全文
摘要:题目链接:Median做了整整一天T_T尝试了各种方法:首先看了解答,可以用multiset,但是发现java不支持;然后想起来用堆,这个基本思想其实很巧妙的,就是维护一个最大堆和最小堆,最大堆存放前半部分较小的元素,最小堆存放后半部分较大的元素,并且最大堆的所有元素小于最小堆的所有元素;保持最大堆...
阅读全文
摘要:题目链接:Coin on the Table一开始想用DFS做的,做了好久都超时。看了题解才明白要用动态规划。设置一个三维数组dp,其中dp[i][j][k]表示在时间k到达(i,j)所需要做的最小改动,那么递推式如下:图片来源:Editorial,其中当从周围的格子可以直接移动到(i,j)时,de...
阅读全文
摘要:题目链接:Pairs完全就是Two Sum问题的变形!Two Sum问题是要求数组中和正好等于K的两个数,这个是求数组中两个数的差正好等于K的两个数。总结其实就是“骑驴找马”的问题:即当前遍历ar[i],那么只要看数组中是否存在ar[i]+K或者ar[i]-K就可以了,还是用HashMap在O(1)...
阅读全文
摘要:题目链接:Cut the tree题解:题目要求求一条边,去掉这条边后得到的两棵树的节点和差的绝对值最小。暴力求解会超时。如果我们可以求出以每个节点为根的子树的节点之和,那么当我们去掉一条边(a,b)的时候,其中的一棵树必是以a或者b为根的子树,那么我们就可以知道生成的两棵树的节点之和了。所以,当我...
阅读全文
摘要:Numeros, The Artist, had two listsAandB, such that,Bwas a permutation ofA. Numeros was very proud of these lists. Unfortunately, while transporting th...
阅读全文
摘要: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...
阅读全文
摘要: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 ...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要: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...
阅读全文
摘要:题目链接:Running Time of QuicksortChallengeIn practice, how much faster is Quicksort (in-place) than Insertion Sort? Compare the running time of the two a...
阅读全文
摘要: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...
阅读全文
摘要:题目连接:Sherlock and MiniMaxWatson gives Sherlock an arrayA1,A2...AN.He asks him to find an integerMbetweenPandQ(both inclusive), such that,min {|Ai-M|, ...
阅读全文
摘要:题目连接: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...
阅读全文
摘要:有n组好朋友在公交车站前排队。第i组有ai个人。还有一辆公交车在路线上行驶。公交车的容量大小为x,即它可以同时运载x个人。 当车站来车时(车总是空载过来),一些组从会队头开始走向公交车。 当然,同一组的朋友不想分开,所以仅当公交车能容纳下整个组的时候,他们才会上车。另外,每个人不想失去自己的位置,即...
阅读全文
摘要:给你一个n*n的地图。地图中的每个格子有一个值表示该地区的深度。我们称一个地图中的一个格子为空洞,当且仅当该格子不在地图边缘并且每个和它相邻的格子都具有比它更小的深度。两个格子称为相邻如果它们共有一条边。你要找到地图中所有的空洞,并且用X描述。输入格式第一行包含一个整数n,表示地图的规模。 接下来n...
阅读全文
摘要: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 ...
阅读全文
摘要:QuickSortIn the previous challenge, you wrote a partition method to split an array into 2 sub-arrays, one containing smaller elements and one containi...
阅读全文
摘要: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 ...
阅读全文
摘要:1 import java.io.*; 2 import java.util.*; 3 4 public class Solution { 5 6 public static void insertionSort(int[] ar) 7 { 8 i...
阅读全文