自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 HDU-4027 线段树

一般的线段树模版题改了下, 不需要开lazy数组,而且执行到一定步数后可以剪枝,因为开方是个很快的步骤,后面就一直是1了,这题基本就需要改下update函数就行了#include<cstring>#include<iostream>#include<cstdio>#include<string>#include<vector&gt...

2019-04-01 15:08:00 149

原创 PAT 1067 Sort with Swap(0, i)

#include &lt;cstdio&gt;#include &lt;iostream&gt;#include &lt;vector&gt;#include &lt;algorithm&gt;#include &lt;stdio.h&gt;#include &lt;cstring&gt;#include &lt;stack&gt;#include &lt;queue&a

2019-02-19 20:36:45 129

原创 PAT 1109 Group Photo 集体照

这题可以用双向队列,很容易就解决!具体看代码#include &lt;iostream&gt;#include &lt;vector&gt;#include &lt;algorithm&gt;#include &lt;cstdio&gt;#include &lt;string&gt;#include &lt;queue&gt;#include &lt;unordered_se...

2019-01-07 22:14:10 166

原创 PAT 1090 危险品装箱

这个和甲级的一道题重复了。今天真的不适合写代码吧,一个下午就ac了3道题,头很大。这道题有点像leetcode朋友圈,应该可以用并查集做,我用了map的方法,具体看代码吧。#include &lt;iostream&gt;#include &lt;vector&gt;#include &lt;algorithm&gt;#include &lt;cstdio&gt;#inclu...

2019-01-07 21:07:48 357

原创 Leetcoe 863. All Nodes Distance K in Binary Tree

dfs和bfs版本,不过我是先转化成图的,以为效率会低很多,没想到还打败了90多的人/** * Definition for a binary tree node. * struct TreeNode { * int val; * TreeNode *left; * TreeNode *right; * TreeNode(int x) : val(...

2019-01-06 18:46:35 128

原创 PAT 1144 The Missing Numbe

我是用哈希表做的。有几个细节要注意下的,a的范围。#include &lt;cstdio&gt;#include &lt;iostream&gt;#include &lt;vector&gt;#include &lt;algorithm&gt;#include &lt;stdio.h&gt;#include &lt;cstring&gt;#include &lt;stack&g

2019-01-03 23:20:56 188

原创 PAT 快速排序

记录每个位置之前和之后的最大最小值。#include &lt;cstdio&gt;#include &lt;algorithm&gt;#include &lt;vector&gt;using namespace std;vector&lt;int&gt; v;int main(){ int n; scanf("%d",&amp;n); for (int ...

2019-01-03 15:21:51 255

原创 PAT 1127ZigZagging on a Tree

leetcode上有一题和这个基本一样,感觉这题有点水。#include &lt;cstdio&gt;#include &lt;iostream&gt;#include &lt;cmath&gt;#include &lt;algorithm&gt;#include &lt;vector&gt;#include &lt;queue&gt;using namespace std;...

2019-01-02 22:50:46 181

原创 PTA Root of AVL Tree

就是基础的avl操作#include &lt;cstdio&gt;#include &lt;iostream&gt;#include &lt;cmath&gt;#include &lt;algorithm&gt;#include &lt;vector&gt;#include &lt;queue&gt;using namespace std;typedef struct n...

2019-01-02 22:49:08 188

原创 leetcode 有序链表转换二叉搜索树

一个思路是先转成数组,还有就是用快慢指针确定链表的中点,还是二分的思想,递归,代码写得很烂好吧/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} ...

2018-12-27 15:05:59 152

原创 Student List for Course

调了好久,最后一个点一直超时,借鉴了下别人的。#include &lt;iostream&gt;#include &lt;cstdio&gt;#include &lt;cmath&gt;#include &lt;vector&gt;#include &lt;algorithm&gt;#include &lt;queue&gt;#include &lt;set&gt;#incl

2018-12-22 19:32:41 145

原创 Build A Binary Search Tree

静态数组,不多说了#include &lt;iostream&gt;#include &lt;cstdio&gt;#include &lt;cmath&gt;#include &lt;vector&gt;#include &lt;algorithm&gt;#include &lt;queue&gt;using namespace std;const int MAXN = 1...

2018-12-22 16:37:15 136

原创 Complete Binary Search Tree

#include &lt;iostream&gt;#include &lt;cstdio&gt;#include &lt;cmath&gt;#include &lt;vector&gt;#include &lt;algorithm&gt;using namespace std;const int MAXN = 10010;vector&lt;int&gt; v;int ar...

2018-12-22 16:14:10 133

原创 PAT Tree Traversals Again

用了两种方法,一个是复原了二叉树,一个是直接根据前中序求后序。#include &lt;cstdio&gt;#include &lt;iostream&gt;#include &lt;vector&gt;#include &lt;algorithm&gt;#include &lt;stdio.h&gt;#include &lt;cstring&gt;#include &lt;s...

2018-12-21 14:36:50 154

原创 PAT Invert a Binary Tree

我是先复原了二叉树,再对其进行遍历。这里有个技巧,%*c可以读取换行符,然后存储到一个结构数组里,方便后面构造二叉树,这里读取的时候要左右颠倒,因为题目就是要翻转二叉树,干脆读取的时候就翻转了。后面就很基础了。#include &lt;cstdio&gt;#include &lt;iostream&gt;#include &lt;vector&gt;#include &lt;...

2018-12-21 13:52:04 133

原创 PAT 输出PATest

用了哈希表的思想,但最后一个测试点一直没过,为什么啊啊啊啊啊#include &lt;cstdio&gt;#include &lt;stdio.h&gt;#include &lt;iostream&gt;#include &lt;algorithm&gt;#include &lt;cstring&gt;#include &lt;queue&gt;using namespace s...

2018-12-19 17:36:23 300

原创 PAT 1029 旧键盘

#include &lt;stdio.h&gt;int hash_table[130] = {0};int main(){// printf("hello\n"); char s1[90]; char s2[90]; gets(s1); gets(s2); for (int i=0; i&lt;strlen(s2); i++) { ...

2018-12-18 20:34:19 116

原创 PAT Boys vs Girls c++

#include &lt;iostream&gt;#include &lt;cstdio&gt;#include &lt;cstring&gt;#include &lt;algorithm&gt;#include &lt;stdlib.h&gt;#include &lt;vector&gt;using namespace std;struct student{ char...

2018-12-18 09:56:52 168

原创 PAT 1011 World Cup Betting

#include &lt;iostream&gt;#include &lt;cstdio&gt;#include &lt;cstring&gt;#include &lt;algorithm&gt;#include &lt;stdlib.h&gt;#include &lt;vector&gt;using namespace std;double first[3];double ...

2018-12-18 09:41:30 131

原创 leetcode Sort List

没想到什么好办法,要将O(ologn)时间里完成,我先遍历一遍将链表存储到数组里,再对数组进行排序,排序方法写了快排和归并的,过是能过,但是时间要140ms,最快的就是直接对链表进行归并排序,第一次写比较难受,用快慢指针来分成两个链表,具体思想还是和数组的归并排序一样。/** * Definition for singly-linked list. * struct ListNode {...

2018-12-17 15:40:19 140 1

原创 leetcode Remove Duplicates from Sorted List II

我的做法比较差吧,用了4个指针,分了好几个情况,还是太菜了。具体做法就是先存储当前结点的值和后面的进行比较,直到next到不同的值,再对current的val值更新成next的val值,有几个特殊的点想了比较久,就变成下面判断比较复杂的情况。。。/** * Definition for singly-linked list. * struct ListNode { * int ...

2018-12-17 15:12:09 100

原创 leetcode 存在重复

bool containsDuplicate(int* nums, int numsSize) { if(numsSize == 0 || numsSize == 1) return false; int temp[numsSize]; temp[0] = nums[0]; int count = 1; for(int i=1;i&lt;n...

2018-12-15 14:23:45 217

原创 leetcode 旋转数组

题目说到要用3种以上方法,又有一个要求是O(1)空间复杂度,有一种要用原地算法了,稍微复杂一点这里第一个是构造辅助数组void rotate(int* nums, int numsSize, int k) { k = k % numsSize; if(!k) return; int temp[numsSize]; int index = 0...

2018-12-15 13:51:26 139

原创 leetcode 从排序数组中删除重复项

原地算法int removeDuplicates(int* nums, int numsSize) { // if(numsSize == 1) // return 1; if(numsSize == 0) return 0; int index = 0; for(int i=1;i&lt;numsSize;i++){ ...

2018-12-15 13:23:58 96

原创 leetcode Minimum Distance Between BST Nodes

/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */void help(struct TreeNode* root,int *pre,int *re...

2018-12-14 23:57:46 145

原创 leetcode Validate Binary Search Tree 验证二叉搜索树

自己第一次想用递归写,但这里很容易错误,因为每次都只是判断当前子树和父结点值大小关系,容易忽略根结点值的大小,就换了c++用中序遍历每次把值放进vector 但这个解法有点垃圾,就去论坛看了别人的代码,学到了很多,第一个代码O(n)的复杂度,left其实就是最小值,right是最大值。/** * Definition for a binary tree node. * struct Tr...

2018-12-14 23:14:10 130

原创 PAT The Black Hole of Numbers

#include &lt;iostream&gt;#include &lt;cstdio&gt;#include &lt;string&gt;#include &lt;algorithm&gt;using namespace std;bool cmp(int a,int b){ return a&gt;b;}void to_array(int n,int num[]){...

2018-12-14 17:36:39 113

原创 1042 Shuffling Machine

#include &lt;cstdio&gt;#include &lt;iostream&gt;#include &lt;cstring&gt;int cards[55];void init(){ for (int i=1; i&lt;55; i++) cards[i] = i;}char shape[] = {'S','H','C','D','J'};...

2018-12-14 15:49:42 110

原创 leetcode nvert Binary Tree 翻转二叉树

/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */struct TreeNode* invertTree(struct TreeNode* root...

2018-12-13 18:49:51 131

原创 leetcode Maximum Depth of N-ary Tree

/*// Definition for a Node.class Node {public: int val; vector&lt;Node*&gt; children; Node() {} Node(int _val, vector&lt;Node*&gt; _children) { val = _val; childr...

2018-12-13 16:23:32 113

原创 leetcode 104. Maximum Depth of Binary Tree 二叉树的深度

/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */int maxDepth(struct TreeNode* root) { if(!roo...

2018-12-13 16:12:47 126

原创 leetcode 100. Same Tree 相同的树

/** * Definition for a binary tree node. * struct TreeNode { * int val; * struct TreeNode *left; * struct TreeNode *right; * }; */bool isSameTree(struct TreeNode* p, struct TreeNo...

2018-12-13 16:03:56 117

原创 leetcode Symmetric Tree 对称二叉树

 /** * Definition for a binary tree node. * struct TreeNode { *     int val; *     struct TreeNode *left; *     struct TreeNode *right; * }; */bool judge(struct TreeNode *left,struct TreeN...

2018-12-13 15:51:17 111

原创 leetcode 旋转链表

具体思路就是先遍历链表求出长度,然后对k取余。通过3个指针实现旋转链表/** * Definition for singly-linked list. * struct ListNode { * int val; * struct ListNode *next; * }; */struct ListNode* rotateRight(struct ListNod...

2018-12-13 15:35:24 143

原创 leetcode Add Two Numbers

/** * Definition for singly-linked list. * struct ListNode { * int val; * ListNode *next; * ListNode(int x) : val(x), next(NULL) {} * }; */class Solution {public: ListNode* a...

2018-12-13 14:56:58 95

原创 1012 数字分类

data=list(map(int,input().split()))a1=0a2=0a2_count=0a3=0a4=0a4_count=0a5=0out=''for each in data[1:]: if each % 5==0 and each % 2==0: a1+=each if each % 5==1: a2_count+=1 a2+=each*(...

2018-12-12 21:57:34 148

原创 1008 数组元素循环右移问题

a=input().split()data=input().split()for i in range(int(a[1])): data=[data[-1]]+data[:-1]for i in range(len(data)-1): print(data[i],end=' ')print(data[-1])#include &lt;iostream&gt;#include ...

2018-12-12 21:35:28 168

原创 PAT乙级1046 划拳

#include &lt;iostream&gt;#include &lt;cstdio&gt;int main(){ int n; scanf("%d",&amp;n); int a,b,c,d; int x = 0; int y = 0; while (n--) { scanf("%d%d%d%d",&amp;a,&amp...

2018-12-12 17:47:13 140

原创 PAT 乙级1026 程序运行时间

#include &lt;iostream&gt;#include &lt;cstdio&gt;int main(){ int start,end; scanf("%d%d",&amp;start,&amp;end); int t = end-start; int hours = t / 360000; t = t-(t / 360000)*3600...

2018-12-12 17:42:19 186

原创 PAT 乙级1016 部分A+B

data=input().split()n1=data[0].count(data[1])n2=data[2].count(data[3])s1=n1*data[1]s2=n2*data[3]if s1=='': s1=0if s2=='': s2=0s=int(s1)+int(s2)print(s)python3和c的#include &lt;iostream&g...

2018-12-12 17:26:11 133 1

空空如也

空空如也

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

TA关注的人

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