水题
文章平均质量分 64
viva_la_vida__
这个作者很懒,什么都没留下…
展开
-
dfs全排列总结
首先考虑遍历的终止条件,就是每个digit都访问到了的情况,所以我们使用index来记录目前访问了几位digit。这个题是一个二叉树问题,对于列表里的每个元素,我们都可以选择加入或不加入列表。遇到这样的题首先可以画图。全排列分为两种,2叉树和k叉树,这题就是个k叉树。由此我们可以把他转换成dfs问题,只要把k叉树遍历即可。在访问时用cur 字符串来记录当前遍历路径所生成的字符串。使用dfs 即可,因为有回溯所以每次加完了需要pop。比如输入“23”,即可画出下图。原创 2022-08-25 02:46:17 · 340 阅读 · 1 评论 -
leetcode 二分总结
模板,不会出现死循环,可以找到第一个值。原创 2022-08-24 01:57:50 · 121 阅读 · 0 评论 -
python string related
【代码】python string related。原创 2022-08-23 10:55:00 · 163 阅读 · 0 评论 -
Heapq
3.使用最小堆,堆size为k。当堆满时,用minHeap[0]来获取最小元素,如果当前元素比最小元素大,就把这个元素加入堆。2.重写heapq比较方法 注意class的写法。1.用hashmap记录每个词出现的频率。4.最后把堆里的元素放到res里并取反。原创 2022-08-23 03:43:43 · 84 阅读 · 0 评论 -
python指针
这个题主要就是注意要加dummy head。有了dummy head, 在while的时候就可以让head的next从两个里面选一个,而不用从循环外单独选头结点。5.把上一个节点的下一个指向新的第一个节点。3.把第一个节点的下一个指向第三个节点。4.把第二个节点的下一个指向第一个节点。7.移动上一个节点指针到下一个节点。交换相邻节点,首先要建一个头结点。6.移动当前指针到下一个节点。原创 2022-08-23 03:35:06 · 1974 阅读 · 0 评论 -
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 · 113 阅读 · 0 评论 -
[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 · 322 阅读 · 0 评论 -
[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 · 64 阅读 · 0 评论 -
[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 · 656 阅读 · 0 评论 -
nefu1299 替换字符串
替换字符串Problem:1299Time Limit:1000msMemory Limit:65535KDescription给出一个只含 a b 字符的串,问不断将串中的 “ab” 字串替换为 “bba” 至少需要几次可以结束替换。Input一原创 2018-01-20 14:56:08 · 867 阅读 · 0 评论 -
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 · 159 阅读 · 0 评论 -
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 · 169 阅读 · 0 评论 -
水题
hdu 5645 DZY Loves Balls他有nn个球,装进一个大盒子里。每个球上面都写着一个整数。有一天他打算从盒子中挑两个球出来。他先均匀随机地从盒子中挑出一个球,记为AA。他不把AA放回盒子,然后再从盒子中均匀随机地挑出一个球,记为BB。如果AA上的数字严格大于BB上的数字,那么他就会感到愉悦。现在告诉你每个球上的数字,请你求出他感到愉悦原创 2017-05-04 10:56:35 · 241 阅读 · 0 评论 -
cf find the bone
#include #include#includeusing namespace std;int a[100005];int main(){ int n,m,k; while(cin>>n>>m>>k) { memset(a,0,sizeof(a)); for(int i=0;i {原创 2017-05-15 16:26:55 · 307 阅读 · 0 评论 -
cf B - Vladik and Complicated Book
B. Vladik and Complicated Booktime limit per test2 secondsmemory limit per test256 megabytesinputstandard inputoutputstandard outputVladik had started reading a原创 2017-05-30 16:01:18 · 341 阅读 · 0 评论 -
hdu1257一道水题??
最少拦截系统Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 40828 Accepted Submission(s): 15970Problem Description某国为了防御敌国的导弹袭击,发展出原创 2017-05-19 15:12:33 · 184 阅读 · 0 评论 -
hdu5890 Find small A 二进制
As is known to all,the ASCII of character 'a' is 97. Now,find out how many character 'a' in a group of given numbers. Please note that the numbers here are given by 32 bits’ integers in the computer.T原创 2017-06-30 18:36:52 · 273 阅读 · 0 评论 -
最少拦截系统 HDU - 1257
某国为了防御敌国的导弹袭击,发展出一种导弹拦截系统.但是这种导弹拦截系统有一个缺陷:虽然它的第一发炮弹能够到达任意的高度,但是以后每一发炮弹都不能超过前一发的高度.某天,雷达捕捉到敌国的导弹来袭.由于该系统还在试用阶段,所以只有一套系统,因此有可能不能拦截所有的导弹. 怎么办呢?多搞几套系统呗!你说说倒蛮容易,成本呢?成本是个大问题啊.所以俺就到这里来求救了,请帮助计算一下最少需要多少套拦截系原创 2017-08-17 10:15:39 · 234 阅读 · 0 评论 -
Tic-Tac-Toe FZU - 2283
Kim likes to play Tic-Tac-Toe.Given a current state, and now Kim is going to take his next move. Please tell Kim if he can win the game in next 2 moves if both player are clever enough.Here “next原创 2017-08-17 11:06:59 · 288 阅读 · 0 评论 -
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 · 399 阅读 · 0 评论 -
二分
二分查找Problem:956 Time Limit:1000msMemory Limit:65536KDescription有n(1<=n<=1000005)个整数,已经按照从小到大顺序排列好,现在另外给一个整数x,请找出序列中第1个大于x的数的下标!Input原创 2017-05-23 15:38:02 · 157 阅读 · 0 评论