自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 洛谷 P3379 【模板】最近公共祖先(LCA)

题目描述如题,给定一棵有根多叉树,请求出指定两个点直接最近的公共祖先。输入输出格式输入格式:第一行包含三个正整数N、M、S,分别表示树的结点个数、询问的个数和树根结点的序号。接下来N-1行每行包含两个正整数x、y,表示x结点和y结点之间有一条直接连接的边(数据保证可以构成树)。接下来M行每行包含两个正整数a、b,表示询问a结点和b结点的最近公共祖先。输出格式:输出包...

2018-12-08 18:04:36 185

原创 归并排序非递归

#include<cstdio>#include<algorithm>#include<iostream>#include<cstring>#include<queue>#include<cmath>#include<set>#include<vector>using

2018-12-07 23:55:20 138

原创 快速排序

#include<cstdio>#include<algorithm>#include<iostream>#include<cstring>#include<queue>#include<cmath>#include<map>#include<set>#include&

2018-12-07 23:18:15 149

原创 1147 Heaps (30 分)

1147 Heaps (30 分)In computer science, a heap is a specialized tree-based data structure that satisfies the heap property: if P is a parent node of C, then the key (the value) of P is either greater ...

2018-12-07 21:00:31 151

原创 1098 Insertion or Heap Sort (25 分)(插入排序,堆排序)

1098 Insertion or Heap Sort (25 分)According to Wikipedia:Insertion sort iterates, consuming one input element each repetition, and growing a sorted output list. Each iteration, insertion sort remo...

2018-12-07 20:45:18 659

原创 1145 Hashing - Average Search Time (25 分)

1145 Hashing - Average Search Time (25 分)The task of this problem is simple: insert a sequence of distinct positive integers into a hash table first. Then try to find another sequence of integer key...

2018-12-07 17:45:44 101

原创 1078 Hashing (25 分)

1078 Hashing (25 分)The task of this problem is simple: insert a sequence of distinct positive integers into a hash table, and output the positions of the input numbers. The hash function is defined ...

2018-12-07 17:32:14 186

转载 哈希之线性探测法

数据结构实验之查找七:线性之哈希表Time Limit: 1000MS Memory Limit: 65536KBProblem Description根据给定的一系列整数关键字和素数p,用除留余数法定义hash函数H(Key)=Key%p,将关键字映射到长度为p的哈希表中,用线性探测法解决冲突。重复关键字放在hash表中的同一位置。Input连续输入多组数据,每组输入数据第一行...

2018-12-07 17:25:00 478

原创 1066 Root of AVL Tree (25 分)

1066 Root of AVL Tree (25 分)An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they differ by...

2018-12-07 16:38:05 175

原创 1123 Is It a Complete AVL Tree (30 分)

1123 Is It a Complete AVL Tree (30 分)An AVL tree is a self-balancing binary search tree. In an AVL tree, the heights of the two child subtrees of any node differ by at most one; if at any time they ...

2018-12-06 00:06:46 100

原创 1099 Build A Binary Search Tree (30 分)

1099 Build A Binary Search Tree (30 分)A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys...

2018-12-05 23:36:24 191

原创 1110 Complete Binary Tree (25 分)

Given a tree, you are supposed to tell if it is a complete binary tree.Input Specification:Each input file contains one test case. For each case, the first line gives a positive integer N (≤20) wh...

2018-12-05 23:28:03 391

原创 1064 Complete Binary Search Tree (30 分)(完全二叉搜索树)

1064 Complete Binary Search Tree (30 分)A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with key...

2018-12-05 23:22:22 213

原创 1043 Is It a Binary Search Tree (25 分)(判断是不是二叉搜索树)

1043 Is It a Binary Search Tree (25 分)A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys...

2018-12-05 23:14:51 316

原创 PAT甲级1119 Pre- and Post-order Traversals (30 分)

1119Pre- and Post-order Traversals(30 分)Suppose that all the keys in a binary tree are distinct positive integers. A unique binary tree can be determined by a given pair of postorder and inorder t...

2018-12-05 21:23:11 213

原创 PAT甲级1120Tree Traversals(后序中序建树)

1020 Tree Traversals (25 分)Suppose that all the keys in a binary tree are distinct positive integers. Given the postorder and inorder traversal sequences, you are supposed to output the level order ...

2018-12-05 21:16:11 159

原创 堆排序

http://www.cnblogs.com/wanglei5205/p/8733524.html#include<cstdio>#include<iostream>using namespace std;void adjust(int arr[],int len,int index){ int left=2*index+1; int righ...

2018-11-29 17:23:41 93

转载 图dfs和bfs时的时间复杂度

下图摘自严蔚敏的教材:dfs:bfs: 

2018-11-17 21:19:55 3274

原创 PAT甲级-1053 Path of Equal Weight (dfs)

1053 Path of Equal Weight (30 分)Given a non-empty tree with root R, and with weight W​i​​ assigned to each tree node T​i​​. The weight of a path from R to L is defined to be the sum of the weights o...

2018-11-17 21:05:16 160

原创 PAT甲级-1050 String Subtraction(water)

1050 String Subtraction (20 分)Given two strings S​1​​ and S​2​​, S=S​1​​−S​2​​ is defined to be the remaining string after taking all the characters in S​2​​ from S​1​​. Your task is simply to calcu...

2018-11-17 20:37:12 119

原创 PAT甲级-1051 Pop Sequence (stack模拟)

1051 Pop Sequence (25 分)Given a stack which can keep M numbers at most. Push N numbers in the order of 1, 2, 3, ..., N and pop randomly. You are supposed to tell if a given sequence of numbers is a ...

2018-11-17 20:25:50 149

原创 PAT甲级-1052 Linked List Sorting (25 分)

1052 Linked List Sorting (25 分)A linked list consists of a series of structures, which are not necessarily adjacent in memory. We assume that each structure contains an integer key and a Nextpointer...

2018-11-16 21:40:02 119

原创 PAT甲级1048 Find Coins (25 分)(二分)

1048 Find Coins (25 分)Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coi...

2018-11-15 20:02:04 308

原创 PAT甲级1045 Favorite Color Stripe(最长不下降子序列)

1045 Favorite Color Stripe (30 分)Eva is trying to make her own color stripe out of a given one. She would like to keep only her favorite colors in her favorite order by cutting off those unwanted pi...

2018-11-13 21:11:20 157

原创 PAT甲级 1044 Shopping in Mars(二分查找)

1044 Shopping in Mars (25 分)Shopping in Mars is quite a different experience. The Mars people pay by chained diamonds. Each diamond has a value (in Mars dollars M$). When making the payment, the cha...

2018-11-13 20:08:21 217

原创 pat-1043二叉搜索树

1043 Is It a Binary Search Tree (25 分)A Binary Search Tree (BST) is recursively defined as a binary tree which has the following properties:The left subtree of a node contains only nodes with keys...

2018-11-12 17:20:03 126

原创 zcmu-1756 台球碰撞(正交分解)

Problem D: 台球碰撞Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 91  Solved: 37[Submit][Status][Web Board]Description在平面直角坐标系下,台球桌是一个左下角在(0,0),右上角在(L,W)的矩形。有一个球心在(x,y),半径为R的圆形母球放在台球桌上(整个球都在台球桌内)。...

2018-10-11 20:25:25 279

原创 已知二叉树前序中序,求后序输出

Problem C: 二叉树遍历Time Limit: 1 Sec  Memory Limit: 32 MBSubmit: 53  Solved: 37[Submit][Status][Web Board]Description二叉树的前序、中序、后序遍历的定义:前序遍历:对任一子树,先访问跟,然后遍历其左子树,最后遍历其右子树;中序遍历:对任一子树,先遍历其左子树,然后访问根...

2018-10-08 21:08:55 217

原创 hdu-6324 Grab The Tree

Problem F. Grab The Tree Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) Total Submission(s): 1058    Accepted Submission(s): 680   Problem Descri...

2018-09-17 14:58:09 136

原创 zoj-4054 Traveling on the Axis

题目链接#include<cstdio>#include<algorithm>#include<iostream>#include<cstring>using namespace std;typedef long long ll;ll f[100005];ll sum[100005];int main(){ ll t;...

2018-09-17 14:25:27 256

原创 Spare Tire

题目链接//题目大意:输入n,m,zhao找出1~n中与m互质的的数,将这些数当作a数组的下标,求和;//思路:打表得出,a[i]=i*i+i;质因数不超过10个,所以先找出m的质因数,然后找出1~n中与m不互质的的数,容斥一下,得出答案#include<cstdio>#include<algorithm>#include<iostream&gt...

2018-09-11 16:10:12 434

原创 逆元

什么是逆元:对于a和p(a与p互质),若a*b≡1(mod p),则b称为a的逆元; 费马小定理:假如p是质数,且gcd(a,p)=1,那么 a^(p-1)≡1(mod p) 应用:假设a,b的范围为【1,1e5】,p=1e9+7,求(a/b)%p;b,p满足费马小定理,所以b^(p-1)≡1(mod p),即b*b^(p-2)≡1(mod p);根据逆元din...

2018-09-11 14:01:44 144

原创 Ryuji doesn't want to study(线段树)

Ryuji is not a good student, and he doesn't want to study. But there are n books he should learn, each book has its knowledge a[i]a[i].Unfortunately, the longer he learns, the fewer he gets.That m...

2018-09-11 13:05:54 219

原创 hdu-6447 YJJ's Salesman(离散化+树状数组)

Problem Description YJJ is a salesman who has traveled through western country. YJJ is always on journey. Either is he at the destination, or on the way to destination. One day, he is going...

2018-09-07 20:34:36 167

原创 poj-3254 Corn Fields(状态压缩dp)

Corn FieldsTime Limit: 2000MS   Memory Limit: 65536K Total Submissions: 20342   Accepted: 10679 DescriptionFarmer John has purchased a lush new rectangular pasture composed of M by...

2018-09-07 18:38:28 142

原创 hdu-1003 Character Encoding(容斥+组合数)

Character Encoding Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1855    Accepted Submission(s): 718   Problem Description...

2018-08-25 20:25:11 144

原创 hdu-6435 CSGO

Problem J. CSGO Time Limit: 4000/2000 MS (Java/Others)    Memory Limit: 524288/524288 K (Java/Others) Total Submission(s): 635    Accepted Submission(s): 334   Problem Description Y...

2018-08-23 20:25:12 374

原创 hdu-6406 Taotao Picks Apples

Time Limit: 2000/2000 MS (Java/Others)    Memory Limit: 131072/131072 K (Java/Others) Total Submission(s): 1778    Accepted Submission(s): 547   Problem Description There is an apple tree...

2018-08-17 16:55:35 200

原创 Tragedy Words

As is known to all, Wells doesn't have a good command of English. As a result, some unfamiliar words, which may cause sadness of Wells, is called tragedy words. In more detail, a word will be defined ...

2018-08-17 16:42:15 130

原创 hdu-1166 敌兵布阵(线段树单点更新模板题)

敌兵布阵 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 122834    Accepted Submission(s): 51442   Problem Description C国的死对头A国...

2018-08-15 10:28:03 132

空空如也

空空如也

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

TA关注的人

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