自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

memcpy0的博客

自由软件给我自由!

  • 博客(64)
  • 资源 (8)
  • 收藏
  • 关注

原创 洛谷 P1196 [NOI2002]银河英雄传说【带权并查集】

题目背景公元 5801 年,地球居民迁至金牛座 α\alphaα 第二行星,在那里发表银河联邦创立宣言,同年改元为宇宙历元年,并开始向银河系深处拓展。宇宙历 799 年,银河系的两大军事集团在巴米利恩星域爆发战争。泰山压顶集团派宇宙舰队司令莱因哈特率领十万余艘战舰出征,气吞山河集团点名将杨威利组织麾下三万艘战舰迎敌。题目描述杨威利擅长排兵布阵,巧妙运用各种战术屡次以少胜多,难免恣生骄气。在这次决战中,他将巴米利恩星域战场划分成 300003000030000 列,每列依次编号为 1,2,…,300

2020-08-31 18:51:26 334

原创 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 205

原创 HDU 4825 Xor Sum【01字典树/贪心】(两数最大/最小异或和)

Problem DescriptionZeus 和 Prometheus 做了一个游戏,Prometheus 给 Zeus 一个集合,集合中包含了 N 个正整数,随后 Prometheus 将向 Zeus 发起M 次询问,每次询问中包含一个正整数 S ,之后 Zeus 需要在集合当中找出一个正整数 K ,使得 K 与 S 的异或结果最大。Prometheus 为了让 Zeus 看到人类的伟大,随即同意 Zeus 可以向人类求助。你能证明人类的智慧么?Input输入包含若干组测试数据,每组测试数据包含若

2020-08-31 13:48:46 272

原创 HDU 3336 Count the string【KMP的next数组性质】

题目链接:HDU 3336 Count the stringProblem DescriptionIt is well known that AekdyCoin is good at string problems as well as number theory problems. When given a string s , we can write down all the non-empty prefixes of this string.For example: s: "abab". T

2020-08-31 00:26:37 172

原创 【算法学习】字符串 字典树Trie

方法三:字典树。回忆字典树的性质:根结点不包含字符,除根结点外的每个子结点都包含一个字符;从根结点到某一个结点,路径上的字符连接起来,就是该结点对应的字符串;每个结点所有的子结点包含的字符互不相同,即字典树基于公共前缀建树。虽然做这种题有点杀鸡用牛刀的感觉,而且复杂度也不一定好到哪去。就当复习一下。插入和查找一个单词的复杂度是O(m),m是单词长度,n个单词大概是O(mn)。然后查找最长公共前缀...

2020-08-30 14:35:25 235

原创 洛谷 P2580 于是他错误的点名开始了【字典树/Map】

题目背景XS中学化学竞赛组教练是一个酷爱炉石的人。他会一边搓炉石一边点名以至于有一天他连续点到了某个同学两次,然后正好被路过的校长发现了然后就是一顿欧拉欧拉欧拉(详情请见已结束比赛 CON900)。题目描述这之后校长任命你为特派探员,每天记录他的点名。校长会提供化学竞赛学生的人数和名单,而你需要告诉校长他有没有点错名。(为什么不直接不让他玩炉石。)输入格式第一行一个整数 nnn ,表示班上人数。接下来 nnn 行,每行一个字符串表示其名字(互不相同,且只含小写字母,长度不超过 505050 )。

2020-08-30 14:24:48 419

原创 LeetCode C++ 214. Shortest Palindrome【字符串】困难

Given a string s , you are allowed to convert it to a palindrome by adding characters in front of it. Find and return the shortest palindrome you can find by performing this transformation.Example 1:Input: "aacecaaa"Output: "aaacecaaa"Example 2:Input

2020-08-30 03:02:40 225

原创 POJ 2236 Wireless Network【并查集】

DescriptionAn earthquake takes place in Southeast Asia. The ACM (Asia Cooperated Medical team) have set up a wireless network with the lap computers, but an unexpected aftershock attacked, all computers in the network were all broken. The computers are re

2020-08-29 19:57:50 171

原创 POJ 2492 A Bug‘s Life【种类并查集】

DescriptionBackgroundProfessor Hopper is researching the sexual behavior of a rare species of bugs. He assumes that they feature two different genders and that they only interact with bugs of the opposite gender. In his experiment, individual bugs and t

2020-08-29 15:35:55 163

原创 POJ 1703 Find them, Catch them【种类并查集】

DescriptionThe police office in Tadu City decides to say ends to the chaos, as launch actions to root up the TWO gangs in the city, Gang Dragon and Gang Snake. However, the police first needs to identify which gang a criminal belongs to. The present quest

2020-08-29 13:43:33 118

原创 LeetCode C++ 657. Robot Return to Origin【字符串】简单

There is a robot starting at position (0, 0) , the origin, on a 2D plane. Given a sequence of its moves, judge if this robot ends up at (0, 0) after it completes its moves.The move sequence is represented by a string, and the character moves[i] represents

2020-08-29 12:50:39 187

原创 【算法学习】高级数据结构2 种类并查集

文章目录1. 种类并查集2. 实际例题1. 种类并查集如果说一般的并查集,维护的是等价、连通关系,例如朋友的朋友是朋友。那么种类并查集,维护的就是对立关系:敌人的敌人是朋友,或者更宽泛的说,是多个种类集合间的一种循环对称的关系。常见的做法是将原并查集扩大一倍规模,并划分为两个种类。在同种类的并查集中合并,和原始的并查集没什么区别,仍然表达 他们是朋友 这个含义。在不同种类的并查集中进行合并,表达的则是 他们是敌人 这个含义。例如,要维护 4 个元素的种类并查集,要开 8 个单位的空间:用 1-

2020-08-29 02:21:23 402

原创 洛谷 P2024 [NOI2001]食物链【种类并查集】

题目描述动物王国中有三类动物 A,B,C ,这三类动物的食物链构成了有趣的环形。A 吃 B ,B 吃 C ,C 吃 A 。现有 N 个动物,以 1-N 编号。每个动物都是 A,B,C 中的一种,但是我们并不知道它到底是哪一种。有人用两种说法对这 N 个动物所构成的食物链关系进行描述:第一种说法是 1 X Y ,表示 X 和 Y 是同类。第二种说法是 2 X Y ,表示 X 吃 Y 。此人对 N 个动物,用上述两种说法,一句接一句地说出 K 句话,这 K 句话有的是真的,有的是假的。当一句话满

2020-08-29 02:16:47 252

原创 洛谷 P1525 关押罪犯【种类并查集】

题目描述SSS 城现有两座监狱,一共关押着 NNN 名罪犯,编号分别为 1−N1-N1−N 。他们之间的关系自然也极不和谐。很多罪犯之间甚至积怨已久,如果客观条件具备则随时可能爆发冲突。我们用“怨气值”(一个正整数值)来表示某两名罪犯之间的仇恨程度,怨气值越大,则这两名罪犯之间的积怨越多。如果两名怨气值为 ccc 的罪犯被关押在同一监狱,他们俩之间会发生摩擦,并造成影响力为 ccc 的冲突事件。每年年末,警察局会将本年内监狱中的所有冲突事件按影响力从大到小排成一个列表,然后上报到 SSS 城 ZZZ

2020-08-28 22:43:52 319

原创 【算法学习】高级数据结构1 并查集

文章目录1. 并查集操作的简单实现(1) 初始化(2) 合并(3) 查找(4) 统计集合个数2. 题目示例并查集/不相交集(Disjoint Set)是一种巧妙而实用的数据结构,主要用于处理一些不相交集合的合并问题,是等价类的实际应用。经典的示例用连通子图、最小生成树、最近公共祖先(Lowest Common Ancestors, LCA)等等。并查集将编号为 1~n 的 nnn 个对象分为不相交的集合,在这个集合中,并查集的操作有初始化,合并,查找。下面给出并查集的简单实现。1. 并查集操作的简单实

2020-08-28 02:22:15 282

原创 洛谷 P3367 【模板】并查集

不错过任何一道模板题!

2020-08-28 02:20:16 175

原创 洛谷 P1886 滑动窗口 /【模板】单调队列

题目描述有一个长为 nnn 的序列 aaa ,以及一个大小为 kkk 的窗口。现在这个从左边开始向右滑动,每次滑动一个单位,求出每次滑动后窗口中的最大值和最小值。例如:The array is [1,3,-1,-3,5,3,6,7], and k=3 。输入格式输入一共有两行,第一行有两个正整数 n,kn,kn,k 。 第二行 nnn 个整数,表示序列 aaa 。输出格式输出共两行,第一行为每次窗口滑动的最小值,第二行为每次窗口滑动的最大值。输入输出样例输入 #18 31 3 -1 -3

2020-08-28 00:35:43 140

原创 LeetCode 455. 分发饼干【贪心,排序,双指针】简单

Assume you are an awesome parent and want to give your children some cookies. But, you should give each child at most one cookie. Each child i has a greed factor gi , which is the minimum size of a cookie that the child will be content with; and each cooki

2020-08-27 22:10:31 287 2

原创 洛谷 P5788 【模板】单调栈

题目描述给出项数为 nnn 的整数数列 a1…na_{1 \dots n}a1…n​ 。定义函数 f(i)f(i)f(i) 代表数列中第 iii 个元素之后第一个大于 aia_iai​ 的元素的下标,即 f(i)=min⁡i<j≤n, aj>ai{j}f(i)=\min_{i<j\leq n,\ a_j > a_i} \{j\}f(i)=mini<j≤n, aj​>ai​​{j} 。若不存在,则 f(i)=0f(i)=0f(i)=0 。试求出 f(

2020-08-27 21:42:00 1363

原创 LeetCode C++ 491. Increasing Subsequences【DFS】中等

Given an integer array, your task is to find all the different possible increasing subsequences of the given array, and the length of an increasing subsequence should be at least 2 .Example:Input: [4, 6, 7, 7]Output: [[4, 6], [4, 7], [4, 6, 7], [4, 6, 7

2020-08-27 01:39:04 205

原创 LeetCode C++ 17. Letter Combinations of a Phone Number【DFS/Backtracking】中等

Given a string containing digits from 2-9 inclusive, return all possible letter combinations that the number could represent.A mapping of digit to letters (just like on the telephone buttons) is given below. Note that 1 does not map to any letters.Examp

2020-08-27 01:24:10 316

原创 HDU 1711 Number Sequence【字符串】

Problem DescriptionGiven two sequences of numbers : a[1], a[2], … , a[N], and b[1], b[2], … , b[M] (1 <= M <= 10000, 1 <= N <= 1000000). Your task is to find a number K which make a[K] = b[1], a[K + 1] = b[2], … , a[K + M - 1] = b[M]. If there

2020-08-27 01:02:57 168

原创 LeetCode C++ 257. Binary Tree Paths【Tree】简单

Given a binary tree, return all root-to-leaf paths.Note: A leaf is a node with no children.Example:Input: 1 / \2 3 \ 5Output: ["1->2->5", "1->3"]Explanation: All root-to-leaf paths are: 1->2->5, 1->3题意:给定一个二叉树,返回所有从

2020-08-26 23:27:55 239

原创 HDU 1686 Oulipo【String/KMP】

Problem DescriptionThe French author Georges Perec (1936–1982) once wrote a book, La disparition, without the letter ‘e’. He was a member of the Oulipo group. A quote from the book:Tout avait Pair normal, mais tout s’affirmait faux. Tout avait Fair norm

2020-08-26 22:55:20 186

原创 LeetCode C++ 1392. Longest Happy Prefix【字符串(KMP)】困难

A string is called a happy prefix if is a non-empty prefix which is also a suffix (excluding itself).Given a string s . Return the longest happy prefix of s .Return an empty string if no such prefix exists.Example 1:Input: s = "level"Output: "l"Expla

2020-08-26 19:56:09 251

原创 LeetCode C++ 226. Invert Binary Tree【Tree】简单

Invert a binary tree.Example:Input: 4 / \ 2 7 / \ / \1 3 6 9Output: 4 / \ 7 2 / \ / \9 6 3 1Trivia:This problem was inspired by this original tweet by Max Howell:Google: 90% of our engineers use the

2020-08-26 19:19:42 246

原创 HDU 2087 剪花布条【KMP】

Problem Description一块花布条,里面有些图案,另有一块直接可用的小饰条,里面也有一些图案。对于给定的花布条和小饰条,计算一下能从花布条中尽可能剪出几块小饰条来呢?Input输入中含有一些数据,分别是成对出现的花布条和小饰条,其布条都是用可见ASCII字符表示的,可见的ASCII字符有多少个,布条的花纹也有多少种花样。花纹条和小饰条不会超过 1000 个字符长。如果遇见 # 字符,则不再进行工作。Output输出能从花纹布中剪出的最多小饰条个数,如果一块都没有,那就老老实实输出 0

2020-08-26 18:51:42 197

原创 洛谷 P3375 【模板】KMP字符串匹配

题目描述给出两个字符串 s1s_1s1​​ 和 s2s_2s2​ ​,若 s1s_1s1​​ 的区间 [l,r][l, r][l,r]子串与 s2s_2s2​ 完全相同,则称 s2s_2s2​​ 在 s1s_1s1​​ 中出现了,其出现位置为 lll 。现在请你求出 s2s_2s2​​ 在 s1s_1s1​ 中所有出现的位置。定义一个字符串 sss 的 border 为 sss 的一个非 sss 本身的子串 ttt ,满足 ttt 既是 sss 的前缀,又是 sss 的后缀。对于 s2s_2s2​

2020-08-26 15:20:00 444

原创 LeetCode C++ 347. Top K Frequent Elements【优先队列】中等

Given a non-empty array of integers, return the k most frequent elements.Example 1:Input: nums = [1,1,1,2,2,3], k = 2Output: [1,2]Example 2:Input: nums = [1], k = 1Output: [1]Note:You may assume k is always valid, 1 ≤ k ≤ number of unique elemen

2020-08-26 00:11:34 283

原创 LeetCode C++ 279. Perfect Squares【BFS/动态规划/数学】中等

Given a positive integer n , find the least number of perfect square numbers (for example, 1, 4, 9, 16, ... ) which sum to n .Example 1:Input: n = 12Output: 3 Explanation: 12 = 4 + 4 + 4.Example 2:Input: n = 13Output: 2Explanation: 13 = 4 + 9.题意

2020-08-25 21:11:56 363

原创 洛谷 P3901 数列找不同【莫队】

题目描述现有数列 A1,A2,…,ANA_1,A_2,\ldots,A_NA1​,A2​,…,AN​,QQQ 个询问 (Li,Ri)(L_i,R_i)(Li​,Ri​) ,询问 ALi,ALi+1,…,ARiA_{L_i} ,A_{L_i+1},\ldots,A_{R_i}ALi​​,ALi​+1​,…,ARi​​ 是否互不相同。输入格式第一行,两个整数 N,QN,QN,Q 。第二行,NNN 个整数 A1,A2,…,ANA_1, A_2, \ldots , A_NA1​,A2​,…,AN​ 。接下来

2020-08-25 12:58:12 251

原创 LeetCode C++ 459. Repeated Substring Pattern【字符串】简单(KMP)

Given a non-empty string check if it can be constructed by taking a substring of it and appending multiple copies of the substring together. You may assume the given string consists of lowercase English letters only and its length will not exceed 10000 .E

2020-08-25 02:39:07 210

原创 【算法学习】分块算法 莫队

文章目录1. 莫队概述2. 挪动区间3. 某种顺序和离线处理4. 莫队算法框架5. 应用题今天要学习的算法是莫队算法基础版本。1. 莫队概述莫队是一种解决区间问题的离线算法。它的思想很简单,本质上就是通过挪动区间的方式按照某种顺序,离线处理区间查询操作。它的时间复杂度是 O(nn)\text{O(n}\sqrt{n})O(nn​) ,是一种效率不错的算法,可以解决几乎所有的区间查询问题(需要离线),只要对时间复杂度的要求不是那么苛刻。2. 挪动区间假设有这样的一道题:对于一个数列,每次给出一个

2020-08-24 23:17:06 380

原创 洛谷 P2709 小B的询问【莫队】

小B有一个长为 nnn 的整数序列 aaa ,值域为 [1,k][1,k][1,k] 。他一共有 mmm 个询问,每个询问给定一个区间 [l,r][l,r][l,r] ,求:∑i=1kci2\sum\limits_{i=1}^k c_i^2i=1∑k​ci2​其中 cic_ici​ 表示数字 iii 在 [l,r][l,r][l,r] 中的出现次数。小B请你帮助他回答询问。输入格式第一行三个整数 n,m,kn,m,kn,m,k 。第二行 nnn 个整数,表示小B的序列。接下来的 mmm 行,每行两

2020-08-24 23:00:33 211

原创 LeetCode 237. Delete Node in a Linked List【链表】简单

Write a function to delete a node (except the tail) in a singly linked list, given only access to that node.Given linked list – head = [4,5,1,9] , which looks like following:Example 1:Input: head = [4,5,1,9], node = 5Output: [4,1,9]Explanation: You a

2020-08-23 15:37:18 309

原创 LeetCode C++ 24. Swap Nodes in Pairs【链表】中等

Given a linked list, swap every two adjacent nodes and return its head.You may not modify the values in the list’s nodes, only nodes itself may be changed.Example:Given 1->2->3->4, you should return the list as 2->1->4->3.题意:给定一个链表,两

2020-08-23 14:50:13 231

原创 LeetCode C++ 203. Remove Linked List Elements【链表】简单

Remove all elements from a linked list of integers that have value val.Example:Input: 1->2->6->3->4->5->6, val = 6Output: 1->2->3->4->5题意:从一个单链表中删除所有等于给定值的结点。思路1:迭代删除+无虚拟头结点。代码:class Solution {public: ListNode*

2020-08-23 13:15:07 199

原创 LeetCode 206. 反转链表, LCR 024. 反转链表【链表,递归】简单

Reverse a singly linked list.Example:Input: 1->2->3->4->5->NULLOutput: 5->4->3->2->1->NULLFollow up:A linked list can be reversed either iteratively or recursively. Could you implement both?题意:递归或者迭代地翻转一个单链表。思路1:迭代翻转单

2020-08-23 00:23:49 309 1

原创 LeetCode C++ 100. Same Tree【Tree/DFS/BFS】简单

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:Input: 1 1 / \ / \

2020-08-21 01:09:30 236

原创 LeetCode C++ 111. Minimum Depth of Binary Tree【DFS/BFS】简单

Given a binary tree, find its minimum depth.The minimum depth is the number of nodes along the shortest path from the root node down to the nearest leaf node.Note: A leaf is a node with no children.Example:Given binary tree [3,9,20,null,null,15,7] ,

2020-08-21 00:59:56 218

西电软件工程概论考前复习题

西电软件工程概论考前复习题

2022-06-25

chapter1_7.zip

Orange's操作系统一书的相关资源,1-7章,个人在Ubuntu虚拟机上运行过

2021-07-15

rubyinstaller-devkit-3.0.1-1-x64.exe

官网下载太慢,这里是我分享的安装包

2021-06-30

编程小白的第一本Python入门书

一个实用主义的开发者,带你快速走进Python编程的大门。

2018-04-30

Coursera机器学习笔记

吴恩达教授的Coursera机器学习笔记整理一到一十八章全

2018-04-22

Python编程

很有趣的一本Python书,学完后可以做各种项目了,对入门的读者是很大的提升

2018-04-22

简明Python教程

简明Python教程,讲解了Python2编程的各个方面,虽然论述和代码实例都很简洁,但是讲解清晰,是不错的入门书籍

2018-04-22

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除