自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+
  • 博客(114)
  • 收藏
  • 关注

原创 dfs全排列总结

首先考虑遍历的终止条件,就是每个digit都访问到了的情况,所以我们使用index来记录目前访问了几位digit。这个题是一个二叉树问题,对于列表里的每个元素,我们都可以选择加入或不加入列表。遇到这样的题首先可以画图。全排列分为两种,2叉树和k叉树,这题就是个k叉树。由此我们可以把他转换成dfs问题,只要把k叉树遍历即可。在访问时用cur 字符串来记录当前遍历路径所生成的字符串。使用dfs 即可,因为有回溯所以每次加完了需要pop。比如输入“23”,即可画出下图。

2022-08-25 02:46:17 314 1

原创 leetcode 二分总结

模板,不会出现死循环,可以找到第一个值。

2022-08-24 01:57:50 113

原创 python string related

【代码】python string related。

2022-08-23 10:55:00 155

原创 Heapq

3.使用最小堆,堆size为k。当堆满时,用minHeap[0]来获取最小元素,如果当前元素比最小元素大,就把这个元素加入堆。2.重写heapq比较方法 注意class的写法。1.用hashmap记录每个词出现的频率。4.最后把堆里的元素放到res里并取反。

2022-08-23 03:43:43 73

原创 python指针

这个题主要就是注意要加dummy head。有了dummy head, 在while的时候就可以让head的next从两个里面选一个,而不用从循环外单独选头结点。5.把上一个节点的下一个指向新的第一个节点。3.把第一个节点的下一个指向第三个节点。4.把第二个节点的下一个指向第一个节点。7.移动上一个节点指针到下一个节点。交换相邻节点,首先要建一个头结点。6.移动当前指针到下一个节点。

2022-08-23 03:35:06 1936

原创 763. Partition Labels

To find a substring that satisfies the description, we need to find the substring that, for each letter in the string, the last position of those letters should be smaller or equal to i. We can use hashmap to store each letter's last position. Time/ space.

2022-08-18 11:47:51 102

原创 左闭右开总结

边界值是需要注意的,贯彻左闭右开思想,左指针一直在当前被计算的位置,右指针在该区间往后一个位置。

2022-07-18 13:26:30 184

原创 prefix sum

则找到hashmap里有prefix【i】-target这个值时,就把计算进结果里。一边遍历树一边计算prefixsum一边把当前值prefixsum值加入map。需要注意的是遍历完了一条路径去另一条时要把之前的节点删除。

2022-07-18 13:22:34 94

原创 回溯递归总结

和上面的题一样,对于一个节点,它需要的是左右子树返回的结果,返回到了叶子节点是否正好等于targetsum,我们就可以在往下走的时候每次减去当前节点的val,看剩下的子路径和是否相等。对于此类问题应该思考从当前层向下面的左右子树要什么。我们需要的是左右子树分别的路径,然后在他们前面加上本层节点。...

2022-07-18 13:15:27 71

原创 python 语法

1.python self代表类的实例,在刷leetcode的时候可以当成全局变量使用 2.pass by reference/pass by value pass by reference: mutable objects array,dict, set, deque, heapq, treenode pass by value: immutable integer,string,tuple3.sort

2022-07-12 13:02:42 332

原创 排序算法总结

1.quickSort: time: o(Nlogn) O(N^2) space: O(logN)2.QuickSelect time: O(N) O(N^2) space: O(1) ---> O(N) call stack3.mergeSort time:o(Nlogn) space: O(logN+N) ---> O(N)4.heapsort time:O(klogN+N)

2022-07-12 12:59:07 229

原创 [leetcode]指针

707.Design Linked ListDesign your implementation of the linked list. You can choose to use a singly or doubly linked list.A node in a singly linked list should have two attributes:valandnext.valis the value of the current node, andnextis a point...

2022-02-11 08:16:28 308

原创 [leetcode]滑动窗口

209.Minimum Size Subarray SumGiven an array of positive integersnumsand a positive integertarget, return the minimal length of acontiguous subarray[numsl, numsl+1, ..., numsr-1, numsr]of which the sum is greater than or equal totarget. If there i...

2022-02-05 03:21:43 54

原创 [leetcode]双指针法

1.27 Remove ElementGiven an integer arraynumsand an integerval, remove all occurrences ofvalinnumsin-place. The relative order of the elements may be changed.Since it is impossible to change the length of the array in some languages, you must in...

2022-02-05 02:50:45 645

转载 nump linspace 使用

linspace的功能最初是从MATLAB中学来的,用此来创建等差数列。近期用Python的时候发现也有这个功能,提供相应功能的是numpy。关于MATLAB中的功能就不再进行赘述了,接下来把我可能用到的Python用法来简单做一个小节。编写如下代码:  1 #!/usr/bin/python  2   3 import numpy as np  4   5 x1 = np...

2018-10-14 14:42:04 164

原创 hdu4022 bombing map+multiset

It’s a cruel war which killed millions of people and ruined series of cities. In order to stop it, let’s bomb the opponent’s base. It seems not to be a hard work in circumstances of street battles, ho...

2018-04-08 16:37:37 178

原创 The Frog's Games HDU - 4004 二分

The annual Games in frogs' kingdom started again. The most famous game is the Ironfrog Triathlon. One test in the Ironfrog Triathlon is jumping. This project requires the frog athletes to jump over th...

2018-04-03 20:53:14 194

原创 Apple Tree poj3321 树状数组+DFS序

Apple TreeTime Limit: 2000MS Memory Limit: 65536KTotal Submissions: 32666 Accepted: 9812DescriptionThere is an apple tree outside of kaka's house. Every autumn, a lot of apples will grow in the tree. ...

2018-03-22 18:50:01 165

原创 Sonya and Queries CodeForces - 714C 字典树

Today Sonya learned about long integers and invited all her friends to share the fun. Sonya has an initially empty multiset with integers. Friends give her tqueries, each of one of the following type:...

2018-03-17 18:38:35 223

原创 Vasiliy's Multiset CodeForces - 706D 字典树

D - Vasiliy's Multiset CodeForces - 706D 01字典树模板题自己都没做出来。。多看看理解一下吧#include <iostream>#include<cstdio>#include<cstring>using namespace std;const int maxn=200005;int tot;int roo...

2018-03-17 18:25:59 135

原创 codeforces 923B producing snow

B. Producing Snowtime limit per test1 secondmemory limit per test256 megabytesinputstandard inputoutputstandard outputAlice likes snow a lot! Unfortunately, thi

2018-03-13 20:30:42 681 1

原创 CS Course HDU - 6186

Little A has come to college and majored in Computer and Science. Today he has learned bit-operations in Algorithm Lessons, and he got a problem as homework. Here is the problem: You are g

2018-01-29 11:33:14 151

原创 nefu1248智力异或 字典树

智力异或Problem:1248Time Limit:2000msMemory Limit:65535KDescription有一个数列包含n个正整数a[1]~a[n](1<=n<1e5,0<=a[i]<1e9),现在有q次操作(q<1e5),每次操作是以下

2018-01-29 11:18:47 187

原创 nefu 1316 Ela的回文串 manacher

Ela的回文串Problem:1316Time Limit:1000msMemory Limit:65535KDescriptionEla在算法课上学习了回文串,但是她不想在回文串中出现她不喜欢的字符。现在Ela告诉我们她喜欢的字符是{A, H, I, M, O, T, U, V, W,

2018-01-28 10:28:41 184

原创 K-th Number POJ - 2104 主席树

You are working for Macrohard company in data structures department. After failing your previous task about key insertion you were asked to write a new data structure that would be able to return quic

2018-01-23 11:23:25 165

原创 博弈入门

巴什博弈:只有一堆n个物品,两个人轮流从这堆物品中取物,规定每次至少取一个,最多取m个。最后取光者得胜。显然,如果n=m+1,那么由于一次最多只能取m个,所以,无论先取者拿走多少个,后取者都能够一次拿走剩余的物品,后者取胜。因此我们发现了如何取胜的法则:如果n=(m+1)r+s,(r为任意自然数,s≤m),那么先取者要拿走s个物品,如果后取者拿走k(≤m)个,那么先取者再拿走m+1-k个,

2018-01-22 20:31:29 305

原创 nefu1299 替换字符串

替换字符串Problem:1299Time Limit:1000msMemory Limit:65535KDescription给出一个只含 a b 字符的串,问不断将串中的 “ab” 字串替换为 “bba” 至少需要几次可以结束替换。Input一

2018-01-20 14:56:08 858

原创 Triple HDU - 5517 二维树状数组

Given the finite multi-set AA of nn pairs of integers, an another finite multi-set BBof mm triples of integers, we define the product of AA and BB as a multi-set C=A∗B={⟨a,c,d⟩∣⟨a,b⟩∈A, ⟨c,d

2018-01-20 11:00:16 190

原创 Bazinga HDU - 5510

Ladies and gentlemen, please sit up straight. Don't tilt your head. I'm serious. For nn given strings S1,S2,⋯,SnS1,S2,⋯,Sn, labelled from 11 to nn, you should find the largest i (1≤i≤n)i

2018-01-17 11:29:43 285

原创 Black And White HDU - 5113 dfs+剪枝

In mathematics, the four color theorem, or the four color map theorem, states that, given any separation of a plane into contiguous regions, producing a figure called a map, no more than four colors a

2018-01-17 10:48:13 136

原创 hdu 5975 Aninteresting game Time Limit: 2000/1000 MS (Java/Others) Memory LimiAninteresting game

Aninteresting gameTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 541    Accepted Submission(s): 219Problem DescriptionLet’s pla

2018-01-13 20:30:15 285

原创 Regular Number--hdu5972

Regular NumberTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 1644    Accepted Submission(s): 445Problem DescriptionUsing regula

2018-01-13 18:45:27 256

原创 病毒侵袭 HDU - 2896

当太阳的光辉逐渐被月亮遮蔽,世界失去了光明,大地迎来最黑暗的时刻。。。。在这样的时刻,人们却异常兴奋——我们能在有生之年看到500年一遇的世界奇观,那是多么幸福的事儿啊~~ 但网路上总有那么些网站,开始借着民众的好奇心,打着介绍日食的旗号,大肆传播病毒。小t不幸成为受害者之一。小t如此生气,他决定要把世界上所有带病毒的网站都找出来。当然,谁都知道这是不可能的。小t却执意要完成这不能的任务,他说

2017-12-04 20:42:50 577

转载 unique()

unique()函数是一个去重函数,STL中unique的函数 unique的功能是去除相邻的重复元素(只保留一个),还有一个容易忽视的特性是它并不真正把重复的元素删除。他是c++中的函数,所以头文件要加#include,具体用法如下:    int num[100];   unique(num,mun+n)返回的是num去重后的尾地址,之所以说比不真正把重复的元素删除,其实是,该

2017-11-30 18:54:52 308

原创 【USACO】2004 Open MooFest 奶牛集会

Description约翰家的N头奶牛每年都会参加“哞哞大会”。哞哞大会是世界奶牛界的盛事。集会上 的活动很多,比如堆干草,跨栅栏,摸牛仔的屁股等等。当然,哞哞大叫肯定也包括在内。奶牛们的叫声很大,很多奶牛在参加多年活动之后,实际上已经失去了一部分的听力。奶牛们已经站在了一条直线上,i号奶牛的坐标为Xi,她只能听到大于Vi的声音。每头奶 牛的位置坐标都是唯一的。 如果i号和j号奶牛

2017-11-29 21:08:38 435

原创 The Little Girl who Picks Mushrooms HDU - 4422

当n当n=4时 两种情况 1.选已采集的两包蘑菇,跟待采集的1包凑成1024的整数倍,让剩下的最多已存在3包能凑成整数倍,待采集的那一包跟已采集的凑成1024N=5时判断有没有3包组成1024的整数倍即可。但是n为4或5时有个很坑的地方就是可以给仙女0个。#include #include#includeusing namespace std; int ma

2017-11-29 20:44:58 155

原创 Split the Rectangle  HDU - 4429

Split the RectangleTime Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 717    Accepted Submission(s): 256Problem DescriptionAlice co

2017-11-29 20:43:37 182

原创 Hierarchical Notation ZOJ - 3826

In Marjar University, students in College of Computer Science will learn EON (Edward Object Notation), which is a hierarchical data format that uses human-readable text to transmit data objects consis...

2017-11-03 19:35:29 173

原创 Known Notation ZOJ - 3829

Do you know reverse Polish notation (RPN)? It is a known notation in the area of mathematics and computer science. It is also known as postfix notation since every operator in an expression follows al

2017-11-02 10:20:27 163

原创 Luba And The Ticket CodeForces - 845B

Luba has a ticket consisting of 6 digits. In one move she can choose digit in any position and replace it with arbitrary digit. She wants to know the minimum number of digits she needs to replace in o

2017-09-09 11:36:31 391

空空如也

空空如也

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

TA关注的人

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