刷题日志与精进之路
刷题记录,包括洛谷、Leetcode、PAT、牛客网等OJ的题解和反思
memcpy0
希望探索文理结合的自由之路。
展开
-
SPOJ DQUERY - D-query【莫队】
题目链接:https://www.spoj.com/problems/DQUERY/ Given a sequence of n numbers a1, a2, ..., an and a number of d-queries. A d-query is a pair (i, j) (1 ≤ i ≤ j ≤ n) . For each d-query (i, j) , you have to return the number of distinct elements in the subsequenc原创 2020-08-31 16:25:04 · 196 阅读 · 0 评论 -
东方Project题目 1975 红魔馆爆炸了
这是湖南科技大学OJ中的一道题目,因为在刷贴吧的时候看到了,所以就做了。 题目描述 红魔馆最近迎来了两块陨石,由于防范不到位,第一块陨石从天而降,红魔馆爆炸了。馆主蕾米莉亚有着强大的力量,她决定阻止第二块陨石,方法是将陨石打爆,使其分裂成若干个小石块。 为了简化问题,我们可以将一块陨石看作由连续的 n 个石块组成,每个石块包含了一定能量,蕾米莉亚需要毁掉其中某一段连续的石块(该段能量和为 s ),被毁掉的石块将会消失,且因连锁反应还会使剩余石块总能量减少 s ,蕾米莉亚需要保证剩余石块总能量不大于 m ,原创 2020-06-18 21:53:47 · 829 阅读 · 1 评论 -
POJ 程序设计与算法(二)第09周测验(2020春季) 001:鸣人和佐助【DFS】【剪枝】
文章目录描述思路代码 描述 佐助被大蛇丸诱骗走了,鸣人在多少时间内能追上他呢? 已知一张地图(以二维矩阵的形式表示)以及佐助和鸣人的位置。地图上的每个位置都可以走到,只不过有些位置上有大蛇丸的手下,需要先打败大蛇丸的手下才能到这些位置。鸣人有一定数量的查克拉,每一个单位的查克拉可以打败一个大蛇丸的手下。假设鸣人可以往上下左右四个方向移动,每移动一个距离需要花费 111 个单位时间,打败大蛇丸的手下...原创 2020-04-20 13:32:33 · 488 阅读 · 0 评论 -
LeetCode C++ 27. Remove Element【Array/Two Pointers】【快慢指针】
Given an array nums and a value val, remove all instances of that value in-place and return the new length. Do not allocate extra space for another array, you must do this by modifying the input array...原创 2020-02-22 19:16:09 · 213 阅读 · 0 评论 -
洛谷 P1618 三连击(升级版)
将 1,2,…,9 共 9 个数分成三组,分别组成三个三位数,且使这三个三位数的比例是 A:B:C,试求出所有满足条件的三个三位数,若无解,输出No!!!。 输入格式 三个数,A,B,C。 输出格式 若干行,每行 3 个数字。按照每行第一个数字升序排列。 输入输出样例 输入 #1 1 2 3 输出 #1 192 384 576 219 438 657 273 546 819 327 654 ...原创 2020-02-18 16:23:28 · 200 阅读 · 0 评论 -
【约瑟夫环】HDU 1276 士兵队列训练问题
Problem Description 某部队进行新兵队列训练,将新兵从一开始按顺序依次编号,并排成一行横队,训练的规则如下:从头开始一至二报数,凡报到二的出列,剩下的向小序号方向靠拢,再从头开始进行一至三报数,凡报到三的出列,剩下的向小序号方向靠拢,继续从头开始进行一至二报数。。。,以后从头开始轮流进行一至二报数、一至三报数直到剩下的人数不超过三人为止。 Input 本题有多个测试数据组,第一行...原创 2020-02-14 23:39:24 · 425 阅读 · 0 评论 -
LeetCode C++ 404. Sum of Left Leaves 【Tree】
404. Sum of Left Leaves 【easy】 Find the sum of all left leaves in a given binary tree. Example: 3 / \ 9 20 / \ 15 7 There are two left leaves in the binary tree, with values 9 and...原创 2020-02-13 18:22:29 · 212 阅读 · 0 评论 -
Leetcode C++ 100. Same Tree 【树】easy
Given two binary trees, write a function to check if they are the same or not. Two binary trees are considered the same if they are structurally identical and the nodes have the same value. Example 1...原创 2020-01-08 20:45:04 · 272 阅读 · 0 评论 -
Leetcode C++ 70. Climbing Stairs 【斐波拉契数列】
You are climbing a stair case. It takes n steps to reach to the top. Each time you can either climb 1 or 2 steps. In how many distinct ways can you climb to the top? Note: Given n will be a positive i...原创 2020-01-06 21:31:52 · 400 阅读 · 0 评论 -
【进制转换】LeetCode C++ 168. Excel Sheet Column Title 和 171. Excel Sheet Column Number
168. Excel Sheet Column Title Given a positive integer, return its corresponding column title as appear in an Excel sheet. For example: 1 -> A 2 -> B 3 -> C ... 26 -> Z 27 -> AA 28 ->...原创 2019-11-23 23:00:42 · 207 阅读 · 0 评论 -
Leetcode C++ 14. Longest Common Prefix
Write a function to find the longest common prefix string amongst an array of strings. If there is no common prefix, return an empty string “”. Example 1: Input: ["flower","flow","flight"] Output: "fl...原创 2019-11-22 20:32:21 · 266 阅读 · 0 评论