摘要: 递归 # 优先处理尾部的链表,此时需要返回子链表的头节点和尾节点 # Definition for singly-linked list. # class ListNode: # def __init__(self, val=0, next=None): # self.val = val # sel 阅读全文
posted @ 2023-04-19 11:23 Serein_MK 阅读(26) 评论(0) 推荐(0)
摘要: 基础八皇后 PAT--7-14 N皇后 (30分) 在N*N的方格棋盘放置了N个皇后,使得它们不相互攻击(即任意2个皇后不允许处在同一排,同一列,也不允许处在与棋盘边框成45角的斜线上。 你的任务是,对于给定的N,求出有多少种合法的放置方法 输入格式: 共有若干行,每行一个正整数N≤10,表示棋盘和 阅读全文
posted @ 2020-11-01 22:25 Serein_MK 阅读(422) 评论(0) 推荐(0)
摘要: Given a collection of number segments, you are supposed to recover the smallest number from them. For example, given { 32, 321, 3214, 0229, 87 }, we c 阅读全文
posted @ 2020-10-29 21:08 Serein_MK 阅读(101) 评论(0) 推荐(0)
摘要: A traveler's map gives the distances between cities along the highways, together with the cost of each highway. Now you are supposed to write a progra 阅读全文
posted @ 2020-10-29 20:35 Serein_MK 阅读(74) 评论(0) 推荐(0)
摘要: One way that the police finds the head of a gang is to check people's phone calls. If there is a phone call between A and B, we say that A and B is re 阅读全文
posted @ 2020-10-29 20:11 Serein_MK 阅读(66) 评论(0) 推荐(0)
摘要: 题目描述 在初赛普及组的“阅读程序写结果”的问题中,我们曾给出一个字符串展开的例子:如果在输入的字符串中,含有类似于“d-h”或者“4-8”的字串,我们就把它当作一种简写,输出时,用连续递增的字母或数字串替代其中的减号,即,将上面两个子串分别输出为“defgh”和“45678"。在本题中,我们通过增 阅读全文
posted @ 2020-10-29 17:09 Serein_MK 阅读(115) 评论(0) 推荐(0)
摘要: 题目背景 在absi2011的帮派里,死号偏多。现在absi2011和帮主等人联合决定,要清除一些死号,加进一些新号,同时还要鼓励帮贡多的人,对帮派进行一番休整。 题目描述 目前帮派内共最多有一位帮主,两位副帮主,两位护法,四位长老,七位堂主,二十五名精英,帮众若干。 现在absi2011要对帮派内 阅读全文
posted @ 2020-10-29 17:05 Serein_MK 阅读(122) 评论(0) 推荐(0)