- 博客(67)
- 收藏
- 关注
原创 电话聊天狂人Java
编程语言:Java题目:题解:不超时需要用技巧。结果:ACimport java.io.*;import java.util.*;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter out = new PrintWriter(new OutputSt
2022-05-10 22:03:10 361
原创 关键活动Java
编程语言:Java题目:题解:见注释结果:ACimport java.io.*;import java.util.*;import java.util.concurrent.LinkedBlockingQueue;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static Pr
2022-05-10 21:17:23 349
原创 POJ 1631 Bridging signals
编程语言:Java题目链接:http://poj.org/problem?id=1631题解:见注释结果:ACimport java.io.*;import java.util.*;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter out = ne
2022-05-10 19:32:15 218
原创 How Long Does It Take
编程语言:Java题目:题解:拓扑排序结果:ACimport java.io.*;import java.util.*;import java.util.concurrent.LinkedBlockingQueue;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static P
2022-05-05 15:41:49 244
原创 公路村村通
编程语言:Java题目:题解:最后输出的代码段感觉可以优化,写的有点繁琐。结果:ACimport java.io.*;import java.util.*;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter out = new PrintWrite
2022-05-05 15:08:14 115
原创 旅游规划 Java
编程语言:Java题目:题解:水题结果:ACimport java.io.*;import java.util.*;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter out = new PrintWriter(new OutputStreamWr
2022-04-25 15:45:48 269
原创 Saving James Bond - Hard Version
编程语言:Java题目:题解:路径还原罢了,每次跳到下一个点的时候记录一下就可以了,还以为能一次过,结果竟然可以一次跳到岸上(咱们强大的詹姆斯·邦德~~),也不想去优化程序了,直接一个外部条件判断解决;一个参数的distance是第一次跳的距离,后面的是判断两点之间的距离;此外,题目还有一个要求,在有很多最短路径的时候选择第一条最短的,解决方法就是按到岸的距离的远近来排序,这样还可以提前结束循环(到岸的距离太长了,一次跳不上去,那后面的也跳不上去了呀);最后这道题用Scanner也不会超时的。结果:
2022-04-25 15:03:13 545
原创 哈利·波特的考试
编程语言:Java题目:题解:背模板(虽然我是照着打的),AC的背后藏着StreamTokenizer读取数据,不然等着TL吧!结果:ACFloyd 算法:import java.io.*;import java.util.Arrays;import java.util.Scanner;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputSt
2022-04-25 14:09:15 96
原创 LeetCode 19 删除链表的倒数第 N 个结点
编程语言:Java题目链接:https://leetcode-cn.com/problems/remove-nth-node-from-end-of-list/题解:递归即可,注意的是,要是被翻转的位置刚好是开头,则需要手动处理,因为递归中并没有处理。难度:Medium结果:ACclass Solution { public ListNode removeNthFromEnd(ListNode head, int n) { if(gogo(head, n)!=n)
2022-04-24 19:05:38 1007
原创 LeetCode 53 最大子数组和
编程语言:Java题目链接:https://leetcode-cn.com/problems/maximum-subarray/题解:无,不想进阶,,,难度:easy结果:ACclass Solution { public int maxSubArray(int[] nums) { int sum=0; int res=Integer.MIN_VALUE; for(int i=0;i<nums.length;i++){
2022-04-24 17:07:40 160
原创 LeetCode 18 四数之和
编程语言:Java题目链接:https://leetcode-cn.com/problems/4sum/题解:其他都简单,主要是剪枝,为了让大家能看懂,注释写的满满的。难度:Medium结果:以后就不放图片了,好麻烦class Solution { public List<List<Integer>> fourSum(int[] nums, int target) { List<List<Integer>> res = ne
2022-04-24 16:54:43 117
原创 六度空间 Java
编程语言:Java题目:题解:这这这不是为难人嘛,测试点5是最大N&最大M,那这样邻接矩阵就是最好的选择,然而呢还是超内存,不知道咋写能不超,希望有人能补充。结果:PAC(测试点5 ML)邻接链表写法:import java.io.*;import java.util.Arrays;import java.util.LinkedList;import java.util.Scanner;import java.util.concurrent.LinkedBlockingQueue
2022-04-24 16:03:20 775
原创 Saving James Bond - Easy Version
编程语言:Java题目:题解:写着写着一遍过了。结果:ACimport java.io.*;import java.util.Scanner;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter out = new PrintWriter(new O
2022-04-24 15:22:29 391
原创 LeetCode 22 括号生成
编程语言:Java题目链接:https://leetcode-cn.com/problems/generate-parentheses/题解:也可以使用StringBuilder,记得每次要恢复状态即可,第一个AC是用了StringBuilder的。难度:Medium结果:class Solution { static List<String> list=new LinkedList<>(); public List<String> gen
2022-04-23 20:06:12 345
原创 LeetCode 21 合并两个有序链表
编程语言:Java题目链接:https://leetcode-cn.com/problems/merge-two-sorted-lists/题解:水题,但递归写法,确实一开始没想到,然后自己做的时候还定义了辅助空间,菜了。难度:easy结果:正常写法:class Solution { public ListNode mergeTwoLists(ListNode list1, ListNode list2) { ListNode list=new ListNode(0,n
2022-04-23 19:47:13 1437
原创 LeetCode 20 有效的括号
编程语言:Java题目链接:https://leetcode-cn.com/problems/valid-parentheses/题解:水题,这几天没时间,继续做水题难度:easy结果:class Solution { static String str = "()[]{}"; public boolean isValid(String s) { Deque<Character> que = new LinkedList<>();
2022-04-23 19:17:26 302
原创 LeetCode 16 最接近的三数之和
编程语言:Java题目链接:https://leetcode-cn.com/problems/3sum-closest/题解:最开始是暴力的,看了题解觉得自己是**难度:Medium结果:class Solution { public int threeSumClosest(int[] nums, int target) { Arrays.sort(nums); int res = nums[0] + nums[1] + nums[2];
2022-04-21 21:00:28 410
原创 LeetCode 12 整数转罗马数字
编程语言:Java题目链接:https://leetcode-cn.com/problems/integer-to-roman/题解:水题难度:Medium结果:class Solution { public String intToRoman(int num) { int[]a={1000,900,500,400,100,90,50,40,10,9,5,4,1}; String[]b={"M","CM","D","CD","C","XC","L","XL
2022-04-21 20:41:22 446
原创 LeetCode 17 电话号码的字母组合
编程语言:Java题目链接:https://leetcode-cn.com/problems/letter-combinations-of-a-phone-number/题解:水题难度:Medium结果:class Solution { static List<String> list; static String[][] strs={ {"a","b","c"}, {"d","e","f"}, {"g","h","i"
2022-04-21 20:11:34 428
原创 POJ 1065 Wooden Sticks
编程语言:Java题目链接:http://poj.org/problem?id=1065题解:贪心即可。可能有人会问为什么这么贪心选取是正确的,你可以假设不选择这个,而选择一个更大的,反正我是能说服我自己的,不能说服自己的可以来找我。结果:ACimport java.io.*;import java.util.*;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(
2022-04-18 20:35:51 159
原创 POJ 3181 Dollar Dayz
编程语言:Java题目链接:http://poj.org/problem?id=3181题解:属于是java为数不多的优势了结果:ACimport java.io.*;import java.math.BigInteger;import java.util.*;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(Syst
2022-04-18 19:42:48 218
原创 POJ 3046 Ant Counting
编程语言:Java题目链接:http://poj.org/problem?id=3046题解:题目绕死我了,然后果断看题解,好家伙题解也看不懂,可能现在问我,我也还是一样搞不懂,解释都写在注解了,有错误希望及时指正,我菜我菜。结果:ACimport java.io.*;import java.util.*;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new
2022-04-18 19:26:04 127
原创 POJ 1742 Coins
编程语言:Java题目链接:http://poj.org/problem?id=1742题解:dp数组表示可以达到的金额,dpc数组用来记录每次已经用掉的该金额的张数结果:ACimport java.io.*;import java.util.*;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)))
2022-04-18 14:59:14 104
原创 列出连通集
编程语言:Java题目:题解:水题结果:ACimport java.io.*;import java.util.*;import java.util.concurrent.LinkedBlockingQueue;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static Pri
2022-04-18 14:31:23 271
原创 Huffman Codes
编程语言:Java题目:题解:超时了一个极端的测试点,完全可以为其写一个特殊的处理过程,但是我看了一下其他c++写的程序,好像没有处理也过了,于是不想写了。(不是我的错~)结果:PAC(测试点3 TL)import java.io.*;import java.util.*;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReade
2022-04-18 14:13:48 335
原创 File Transfer
编程语言:Java题目:题解:并查集,要使用StreamTokenizer,不然会超时,另外要注意,find函数返回的值即可理解为下标也可理解为该下标指向的值(废话),但是不弄清楚的话,会很容易出问题的结果:ACimport java.io.*;import java.util.LinkedHashSet;import java.util.Scanner;import java.util.Set;public class Main { static StreamTokenizer
2022-04-17 20:06:44 162
原创 堆中的路径
编程语言:Java题目:题解:为了计算方便,将下标为1定义为根结点,要不然调整小根堆的时候要麻烦一点结果:ACimport java.io.*;import java.util.Scanner;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter o
2022-04-17 19:23:01 153
原创 POJ 3616 Milking Time
编程语言:Java题目链接:http://poj.org/problem?id=3616题解:初始时间升序排列,后续不解释了,代码比较容易看懂结果:ACimport java.io.*;import java.util.Arrays;import java.util.Comparator;import java.util.Scanner;public class Main { static StreamTokenizer in = new StreamTokenizer(new B
2022-04-17 18:52:32 250
原创 Complete Binary Search Tree
编程语言:Java题目:题解:题目一共就两个条件:完全二叉树和二叉排序树。二叉排序树可以通过数组排序一步解决;完全二叉树就求根结点相对于两边的偏移即可,本人写的代码中是相对于左边界限进行偏移,其实也可以相对于右边界限进行偏移(当最后一层大于该层的一半时,就将大于的结点都加到右子树里去,反之就加0即可。)结果:ACimport java.io.*;import java.util.Arrays;import java.util.Scanner;public class Main { s
2022-04-16 19:51:12 582
原创 LeetCode 10 正则表达式匹配
编程语言:Java题目链接:https://leetcode-cn.com/problems/regular-expression-matching/题解:看注释,太菜了,搬题解。结果:class Solution { public boolean isMatch(String s, String p) { if (s != null && p != null) { int m = s.length(); in
2022-04-15 16:04:00 350
原创 LeeCode 6 Z 字形变换
编程语言:Java题目链接:https://leetcode-cn.com/problems/zigzag-conversion/description/题解:大体思路为直接根据输出格式进行一行一行的输出,但是要分情况:①第一行和最后一行一直加同一个数即可,这个数的值显而易见;②中间行,时而加多一点,时而加少一点,故需要记录状态,以便确定下一个位移的步数。难度:Medium结果:class Solution { public String convert(String s, int nu
2022-04-15 11:28:16 242
原创 POJ 2385 Apple Catching
编程语言:Java题目链接:http://poj.org/problem?id=2385题解:见注释结果:ACimport java.io.*;import java.util.Scanner;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter ou
2022-04-14 20:20:19 90
原创 POJ 2229 Sumsets
编程语言:Java题目链接:http://poj.org/problem?id=2229题解:任何一组组合,只会出现如下两种情况:①由1组成,这样组成该数的组合数量就跟比他小1的数的组合数量相同;②没有1组成,那该数就只可能是偶数,那么组成他的组合,其实也就是组成他一半的组合乘以2罢了。如果上述听懂了,那么题目就简单了,奇数必定带1,所以等于上一个数的组合数量;偶数可能带1,也有可能不带1,带1的时候等于上一个数的组合数量,不带1的时候,就等于组成他一半的组合数量,两者相加即可。结果:AC
2022-04-14 20:05:22 390
原创 POJ 3176 Cow Bowling
编程语言:Java题目链接:http://poj.org/problem?id=3176题解:简单结果:ACimport java.io.*;import java.util.Scanner;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter out
2022-04-14 19:41:38 73
原创 POJ 3262 Protecting the Flowers
编程语言:Java题目链接:http://poj.org/problem?id=3262题解:没啥注意的,就是保存结果的变量要用long类型结果:ACimport java.io.*;import java.util.Arrays;import java.util.Comparator;import java.util.Scanner;public class Main { static StreamTokenizer in = new StreamTokenizer(new Bu
2022-04-14 19:28:39 103
原创 POJ 1862 Stripies
编程语言:Java题目链接:http://poj.org/problem?id=1862题解:数学推理一下就知道该取最大的两个相乘,这样最后剩下的才是所有计算中最小的。结果:ACimport java.io.*;import java.util.Comparator;import java.util.PriorityQueue;import java.util.Scanner;public class Main { static StreamTokenizer in = new S
2022-04-14 19:11:45 106
原创 POJ 3040 Allowance
编程语言:Java题目链接:http://poj.org/problem?id=3040题解:见注解结果:ACimport java.io.*;import java.util.Arrays;import java.util.Comparator;import java.util.Scanner;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new Inp
2022-04-14 17:09:09 126
原创 Maximum Subsequence Sum
编程语言:Java题目:题解:这里选择了先存储再处理,结果值更新的同时也要更新下标结果:ACimport java.io.*;import java.util.Scanner;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter out = new
2022-04-14 16:41:09 57
原创 最大子列和问题
编程语言:Java题目:题解:边处理便输入结果:ACimport java.io.*;import java.util.Scanner;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter out = new PrintWriter(new Outp
2022-04-14 16:37:04 66
原创 Root of AVL Tree
编程语言:Java题目:题解:较为简单。结果:ACimport java.io.*;import java.util.Scanner;public class Main { static StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in))); static PrintWriter out = new PrintWriter(new Output
2022-04-14 13:38:00 105
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人