算法
文章平均质量分 53
什么你竟然不会敲代码
因故停了,谢谢大家支持。不必私信
展开
-
oj-排序和分治
插入排序private static void InsertSort(int[] nums) { for (int i = 1; i < nums.length; i++) { for (int j = i; j >= 0; j--) { if (nums[j - 1] > nums[j]) { swap(nums, j, j - 1); } } }}非递原创 2021-04-14 13:53:11 · 524 阅读 · 0 评论 -
oj-固定和的元素对-java
Description输入一个数组和一个数字,在数组中查找两个数,使得它们的和正好是输入的那个数字,统计这样两个数的对数。Input输入第一行为用例个数, 每个测试用例输入第一行是数组,每一个数用空格隔开;第二行是数字和。Output输出这样两个数有几对。Sample Input 111 2 4 7 11 0 9 1511Sample Output 13Codepackage org.alphacat.fifth;import java.util.Arrays;import原创 2021-04-12 16:40:58 · 443 阅读 · 0 评论 -
oj-管道网络-java
DescriptionEvery house in the colony has at most one pipe going into it and at most one pipe going out of it. Tanks and taps are to be installed in a manner such that every house with one outgoing pipe but no incoming pipe gets a tank installed on its roo原创 2021-04-12 16:39:57 · 323 阅读 · 0 评论 -
oj-时间分隔-java
DescriptionGiven arrival and departure times of all trains that reach a railway station. Your task is to find the minimum number of platforms required for the railway station so that no train waits.Note: Consider that all the trains arrive on the same da原创 2021-04-12 16:39:08 · 311 阅读 · 0 评论 -
oj-时间与收益-java
DescriptionGiven a set of n jobs where each job i has a deadline and profit associated to it. Each job takes 1 unit of time to complete and only one job can be scheduled at a time. We earn the profit if and only if the job is completed by its deadline. Th原创 2021-04-12 16:38:13 · 329 阅读 · 0 评论 -
oj-硬币最小数量-java
DescriptionGiven the list of coins of distinct denominations and total amount of money. Output the minimum number of coins required to make up that amount. Output -1 if that money cannot be made up using given coins. You may assume that there are infinite原创 2021-04-12 16:37:00 · 208 阅读 · 0 评论 -
oj-路上的球-java
DescriptionThere are two parallel roads, each containing N and M buckets, respectively. Each bucket may contain some balls. The buckets on both roads are kept in such a way that they are sorted according to the number of balls in them. Geek starts from th原创 2021-04-12 16:35:59 · 180 阅读 · 0 评论 -
oj-子数组的取值范围-java
Description给定数组arr和整数num,求arr的连续子数组中满足:其最大值减去最小值的结果大于num的个数。请实现一个时间复杂度为O(length(arr))的算法。Input输入第一行为测试用例个数。每一个用例有若干行,第一行为数组,每一个数用空格隔开,第二行为num。Output输出一个值。Sample Input 113 6 4 3 22Sample Output 16Codepackage org.alphacat.fifth;import java.uti原创 2021-04-12 16:35:01 · 239 阅读 · 0 评论 -
oj-数组和窗口-java
Description给定一个整型数组arr和一个大小为w的窗口,窗口从数组最左边滑动到最右边,每次向右滑动一个位置,求出每一次滑动时窗口内最大元素的和。Input输入第一行为用例个数, 每个测试用例输入的第一行为数组,每一个元素使用空格隔开;第二行为窗口大小。Output输出每个测试用例结果。Sample Input 114 3 5 4 3 3 6 73Sample Output 132Codepackage org.alphacat.fifth;import java.ut原创 2021-04-12 16:34:02 · 120 阅读 · 0 评论 -
oj-格子里的整数-java
DescriptionGiven a square grid of size n, each cell of which contains integer cost which represents a cost to traverse through that cell, we need to find a path from top left cell to bottom right cell by which total cost incurred is minimum.Note : It is原创 2021-04-12 16:32:43 · 181 阅读 · 0 评论 -
oj-订单问题-java
DescriptionRahul and Ankit are the only two waiters in Royal Restaurant. Today, the restaurant received N orders. The amount of tips may differ when handled by different waiters, if Rahul takes the ith order, he would be tipped Ai rupees and if Ankit take原创 2021-04-02 21:33:27 · 260 阅读 · 0 评论 -
oj-数组查询-java
DescriptionGiven an array, the task is to complete the function which finds the maximum sum subarray, where you may remove at most one element to get the maximum sum.Input第一行为测试用例个数T;后面每两行表示一个用例,第一行为用例中数组长度N,第二行为数组具体内容。Output每一行表示对应用例的结果。Sample Input原创 2021-04-02 21:32:20 · 233 阅读 · 0 评论 -
oj-按照要求保留数组元素使得和最大-java
DescriptionGiven an array of N numbers, we need to maximize the sum of selected numbers. At each step, you need to select a number Ai, delete one occurrence of Ai-1 (if exists) and Ai each from the array. Repeat these steps until the array gets empty. The原创 2021-04-02 21:30:28 · 196 阅读 · 0 评论 -
oj-如何花最少的钱购买蔬菜-java
DescriptionRahul wanted to purchase vegetables mainly brinjal, carrot and tomato. There are N different vegetable sellers in a line. Each vegetable seller sells all three vegetable items, but at different prices. Rahul, obsessed by his nature to spend opt原创 2021-04-02 21:29:05 · 235 阅读 · 0 评论 -
oj-是否能通过考试-java
Description小张想要通过明天的考试。他知道考题的分值分布,也知道考试中要拿到每一个题目需要耗费的时间。假设考试时长为h,共n个题目,需要拿到p分才能通过考试。现在已知每个考题的得分与耗时,请你判断小张能否通过合理安排时间,而通过考试,并给出通过考试的最短时间。Input输入第一行为测试用例个数.每一个用例有若干行,第一行为任务数量n、考试时常h、通过分数p,下面的n行是每一个题目的耗时和得分。所有数值用空格分开。Output对每一个用例输出一行,如果能够通过考试,则输出“YES”和消耗最原创 2021-04-02 21:27:15 · 292 阅读 · 0 评论 -
oj-无重复字符子集问题-java
DescriptionMike is a lawyer with the gift of photographic memory. He is so good with it that he can tell you all the numbers on a sheet of paper by having a look at it without any mistake. Mike is also brilliant with subsets so he thought of giving a chal原创 2021-04-02 21:25:46 · 246 阅读 · 0 评论 -
oj-矩阵计算-java
DescriptionLet’s define a Series Whose recurrence formula is as follows :C(n)= 3C(i-1) + 4C(i-2) + 5C(i-3) + 6C(i-4)C(0)= 2C(1)= 0C(2)= 1C(3)= 7Now based on this Series a Matrix Mi,j of size nn is to be formed.The top left cell is(1,1) and the botto原创 2021-04-02 21:22:21 · 218 阅读 · 0 评论 -
oj-最小化初始点-java
DescriptionGiven a grid with each cell consisting of positive, negative or no points i.e, zero points. We can move across a cell only if we have positive points ( > 0 ). Whenever we pass through a cell, points in that cell are added to our overall poin原创 2021-04-02 21:20:56 · 213 阅读 · 0 评论 -
oj-距离问题-java
DescriptionIn a given cartesian plane, there are N points. We need to find the Number of Pairs of points(A,B) such thatPoint A and Point B do not coincide.Manhattan Distance and the Euclidean Distance between the points should be equal.Note : Pair of 2原创 2021-03-13 15:54:11 · 335 阅读 · 2 评论 -
oj-和最大的连续降序字符-java
DescriptionArchana is very fond of strings. She likes to solve many questions related to strings. She comes across a problem which she is unable to solve. Help her to solve. The problem is as follows: Given is a string of length L. Her task is to find the原创 2021-03-13 15:18:39 · 307 阅读 · 0 评论 -
oj-牛的繁殖问题-java
DescriptionCows in the FooLand city are interesting animals. One of their specialties is related to producing offsprings. A cow in FooLand produces its first calve (female calf) at the age of two years and proceeds to produce other calves (one female calf原创 2021-03-13 11:29:15 · 330 阅读 · 0 评论 -
oj-子矩阵问题-java
Description给定一个矩形区域,每一个位置上都是1或0,求该矩阵中每一个位置上都是1的最大子矩形区域中的1的个数。Input输入第一行为测试用例个数。每一个用例有若干行,第一行为矩阵行数n和列数m,下面的n行每一行是用空格隔开的0或1。Output输出一个数值。Sample Input 113 41 0 1 11 1 1 11 1 1 0Sample Output 16思路与原代码[算法]极大子矩阵问题Java// https://blog.csdn.net/qq_原创 2021-03-13 10:22:37 · 373 阅读 · 0 评论 -
oj-字符串匹配问题-java
DescriptionGiven a text txt[0…n-1] and a pattern pat[0…m-1], write a function search(char pat[], char txt[]) that prints all occurrences of pat[] in txt[]. You may assume that n > m.Input输入第一行是用例个数,后面一行表示一个用例;用例包括两部分,第一部分为给定文本,第二部分为搜索串,两部分使用","隔开。Ou原创 2021-03-13 09:16:52 · 294 阅读 · 0 评论 -
oj-对称子字符串-java
DescriptionGiven a string ‘str’ of digits, find length of the longest substring of ‘str’, such that the length of the substring is 2k digits and sum of left k digits is equal to the sum of right k digits.Input输入第一行是测试用例的个数,后面每一行表示一个数字组成的字符串,例如:“123123”原创 2021-03-12 19:23:20 · 177 阅读 · 0 评论 -
oj-区间第k最小-java
Description找到给定数组的给定区间内的第K小的数值。Input输入第一行为用例个数, 每个测试用例输入的第一行为数组,每一个数用空格隔开;第二行是区间(第几个数到第几个数,两头均包含),两个值用空格隔开;第三行为K值。Output结果。Sample Input 111 2 3 4 5 6 73 52Sample Output 14Codepackage org.alphacat.third;import java.util.Arrays;import java.u原创 2021-03-12 19:21:18 · 276 阅读 · 0 评论 -
oj-最长公共子序列-java
Description给定两个字符串,返回两个字符串的最长公共子序列(不是最长公共子字符串),可能是多个。Input输入第一行为用例个数, 每个测试用例输入为两行,一行一个字符串Output如果没有公共子序列,不输出,如果有多个则分为多行,按字典序排序。Sample Input 111A2BD3G4H56JK23EFG4I5J6K7Sample Output 123G456K23G45JKpackage org.alphacat.third;import java.util.*原创 2021-03-12 14:50:07 · 307 阅读 · 0 评论 -
oj-Searching_3-java
DescriptionThey declared Sonam as bewafa. Although she is not, believe me! She asked a number of queries to people regrading their position in a test. Now its your duty to remove her bewafa tag by answering simple queries. All the students who give test c原创 2021-03-06 19:39:06 · 272 阅读 · 0 评论 -
oj-Searching_4-java
DescriptionGiven n Magnets which are placed linearly, with each magnet to be considered as of point object. Each magnet suffers force from its left sided magnets such that they repel it to the right and vice versa. All forces are repulsive. The force bein转载 2021-03-06 19:35:39 · 276 阅读 · 0 评论 -
oj-拓扑排序解的个数-java
Description给定有向无环图中所有边,计算图的拓扑排序解的个数。Input输入第一行为用例个数,后面每一行表示一个图中的所有边,边的起点和终点用空格隔开,边之间使用逗号隔开。Output输出拓扑排序解的个数。Sample Input 11a c,b c,c d,d e,d f,e g,f gSample Output 14Code参考代码:AdvancedAlgorithmpackage org.alphacat.second;import java.util.*;转载 2021-03-06 19:31:54 · 1073 阅读 · 0 评论 -
oj-二叉树-java
DescriptionGiven a Complete Binary tree, print the level order traversal in sorted order.InputThe first line of the input contains integer T denoting the number of test cases. For each test case, the first line takes an integer n denoting the size of ar转载 2021-03-06 19:27:35 · 379 阅读 · 0 评论 -
oj-点的凸包-java
DescriptionConvex Hull of a set of points, in 2D plane, is a convex polygon with minimum area such that each point lies either on the boundary of polygon or inside it. Now given a set of points the task is to find the convex hull of points.InputThe firs转载 2021-03-06 19:20:41 · 403 阅读 · 0 评论 -
oj-按照另一个数组排序-java
DescriptionGiven two array A1[] and A2[], sort A1 in such a way that the relative order among the elements will be same as those in A2. For the elements not present in A2. Append them at last in sorted order. It is also given that the number of elements i原创 2021-03-02 15:12:52 · 375 阅读 · 0 评论 -
oj-有9个因数的数-java
DescriptionFind the count of numbers less than N having exactly 9 divisors1<=T<=1000,1<=N<=10^12InputFirst Line of Input contains the number of testcases. Only Line of each testcase contains the number of members N in the rival gang.Output转载 2021-03-02 14:54:44 · 302 阅读 · 0 评论 -
oj-深度优先遍历-java
Description按照给定的起始顶点深度优先遍历给定的无向图,尝试所有可能的遍历方式,打印遍历过程中出现的最大深度。Input输入第一行是用例个数,后面每个用例使用多行表示,用例的第一行是图中节点的个数n和起始点,用空格隔开,后面n+1行为图的邻接矩阵,其中第一行为节点名称。值之间使用空格隔开。Output输出深度优先遍历中遇到的最大深度。Sample Input 114 aa b c da 0 1 1 0b 1 0 1 0c 1 1 0 1d 0 0 1 0Sample O原创 2021-03-02 14:10:31 · 315 阅读 · 0 评论 -
oj-广度优先遍历图-java
Description按照给定的起始顶点广度优先遍历图,每一次通过字母顺序选择顶点查找下一层邻接点,打印遍历顺序。Input输入第一行为测试用例个数,后面每一个用例用多行表示,用例第一行是节点个数n和开始顶点,用空格隔开,后面n+1行为图的邻接矩阵,其中第一行为节点名称。值之间使用空格隔开。Output输出遍历顺序,用空格隔开Sample Input 114 aa b c da 0 1 1 0b 1 0 1 0c 1 1 0 1d 0 0 1 0Sample Output 1a原创 2021-03-02 13:56:40 · 256 阅读 · 0 评论 -
oj-按照数值个数排序-java
Description对给定数组中的元素按照元素出现的次数排序,出现次数多的排在前面,如果出现次数相同,则按照数值大小排序。例如,给定数组为{2, 3, 2, 4, 5, 12, 2, 3, 3, 3, 12},则排序后结果为{3, 3, 3, 3, 2, 2, 2, 12, 12, 4, 5}。Input输入的第一行为用例个数;后面每一个用例使用两行表示,第一行为数组长度,第二行为数组内容,数组元素间使用空格隔开。Output每一个用例的排序结果在一行中输出,元素之间使用空格隔开。Sample原创 2021-03-02 12:14:16 · 297 阅读 · 0 评论 -
oj-分治法解最近对问题-java
Description最近对问题:使用分治算法解决最近对问题。Input第一行为测试用例个数。后面每一行表示一个用例,一个用例为一些平面上点的集合,点与点之间用逗号隔开,一个点的两个坐标用空格隔开。坐标值都是正数。Output对每一个用例输出两个距离最近的点(坐标使用空格隔开),用逗号隔开,先按照第一个坐标大小排列,再按照第二个坐标大小排列。如果有多个解,则按照每个解的第一个点的坐标排序,连续输出多个解,用逗号隔开。Sample Input 111 1,2 2,3 3,4 4,5 5,1.5转载 2021-03-01 20:47:59 · 540 阅读 · 0 评论 -
oj-宠物屋涂色-java
DescriptionDilpreet wants to paint his dog- Buzo’s home that has n boards with different lengths[A1, A2,…, An]. He hired k painters for this work and each painter takes 1 unit time to paint 1 unit of the board.The problem is to find the minimum time to ge原创 2021-03-01 19:48:32 · 485 阅读 · 0 评论 -
oj-数学公式[快速幂]-java
DescriptionImplement pow(A, B) % C.In other words, given A, B and C, find (A^B)%CInputThe first line of input consists number of the test cases. The following T lines consist of 3 numbers each separated by a space and in the following order:A B C’A’ bei原创 2021-02-27 16:57:01 · 344 阅读 · 0 评论 -
oj-棋盘覆盖问题-java
Description棋盘覆盖问题:给定一个大小为2n2n个小方格的棋盘,其中有一个位置已经被填充,现在要用一个L型(22个小方格组成的大方格中去掉其中一个小方格)形状去覆盖剩下的小方格。求出覆盖方案,即哪些坐标下的小方格使用同一个L型格子覆盖。注意:坐标从0开始。左上方的第一个格子坐标为(0,0),第一行第二个坐标为(0,1),第二行第一个为(1,0),以此类推。Input输入第一行为测试用例个数,后面每一个用例有两行,第一行为n值和特殊的格子的坐标(用空格隔开),第二行为需要查找其属于同一个L型格原创 2021-02-13 17:38:07 · 724 阅读 · 1 评论