![](https://img-blog.csdnimg.cn/20201014180756922.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
数据结构
touso
这个作者很懒,什么都没留下…
展开
-
单向环形链表实现约瑟夫问题
package com.atguigu.linkedlist;public class Josephu { public static void main(String[] args) { CircleSingleLinkedList circleSingleLinkedList=new CircleSingleLinkedList(); circleSingleLinkedList.addBoy(5); circleSingleLinkedLis原创 2021-12-01 14:01:16 · 458 阅读 · 0 评论 -
双向链表基本操作
package com.atguigu.linkedlist;public class DoubleLinkedList { public static void main(String[] args) { HeroNode2 heroNode1=new HeroNode2(0,"2","2"); HeroNode2 heroNode2=new HeroNode2(3,"3","3"); HeroNode2 heroNode3=new HeroNo原创 2021-11-30 20:29:34 · 392 阅读 · 0 评论 -
单向链表各种操作
package com.atguigu.linkedlist;import java.util.Stack;public class SingleLinkedList { public static void main(String[] args) { HeroNode heroNode1=new HeroNode(0,"2","2"); HeroNode heroNode2=new HeroNode(3,"3","3"); HeroNode原创 2021-11-30 19:55:47 · 421 阅读 · 0 评论 -
数组实现队列与循环队列
数组实现队列package com.atguigu.queue;import java.util.Scanner;public class ArrayQueueDemo { public static void main(String[] args) { ArrayQueue arrayQueue=new ArrayQueue(4); char key=' '; Scanner scanner=new Scanner(System.in);原创 2021-11-29 19:31:02 · 293 阅读 · 0 评论 -
二维数组与稀疏数组相互转换
package com.atguigu.sparsearray;public class SparseArray { public static void main(String[] args) { //创建二维数组 int chessArr1[][]=new int[11][11]; chessArr1[1][2]=1; chessArr1[2][3]=2; System.out.println("原始二维数组")原创 2021-11-28 17:48:33 · 227 阅读 · 0 评论 -
点的距离(LCA)
点的距离#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxn=2e5;int x,y,dep[maxn],f[maxn][25],n;int nxt[maxn<<1],first[maxn<<1],go[maxn<<1],tot;void add(int u,int v){ nxt[++tot]原创 2020-10-21 20:53:42 · 221 阅读 · 0 评论 -
敌兵布阵 线段树(树状数组)
链接小小的模板题线段树:#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;int tree[200101];int n;void build(int l,int r,int p){ if(l==r) { scanf("%d",&tree[p]); return ; } int mid=(l+r)>>1; build(l原创 2020-10-15 21:27:21 · 80 阅读 · 0 评论 -
替罪羊树
每个节点储存的信息1.左右子树编号2.当前节点的值3.以当前节点为根的树的大小和实际大小(实际大小为没有删除标记的节点数量)4.删除标记插入和删除后要判断是否需要重构,从根节点开始向刚刚操作的节点找,如果找到了一个需要重构的节点,那么就暴力重构以它为根的子树。重构条件:当前节点的左子树或右子树的大小大于当前节点的大小乘上一个平衡因子a,或者以当前节点为根的子树内被删除的节点数量大于树...原创 2020-04-27 22:06:34 · 153 阅读 · 0 评论 -
一维树状数组
click here1。单点修改,区间查询#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxn=2e6+10;typedef long long ll;ll a[maxn];int n;int lowbit(int x){ return x&(-x);}void update(int x,ll val){ fo原创 2020-10-08 21:42:29 · 56 阅读 · 0 评论 -
二维树状数组
借此写一下二维树状数组1.单点修改,区间查询click here区间查询,因为a[i][j]表示从(i,j)到(0,0)的所有值之和,因此需要减去多计算的部分#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxn=4100;int n,m;typedef long long ll;ll a[maxn][maxn];int low原创 2020-10-08 20:24:11 · 57 阅读 · 0 评论 -
HDU 3966 Aragorns Story
题目模板#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int inf=0x3f3f3f3f;const int maxn=2e5+10;struct node{ int t,nxt;}edge[maxn];int head[maxn],cnt;void init(int n){ cnt=0; memset(head,-1,siz原创 2020-10-07 20:11:54 · 94 阅读 · 0 评论 -
Balanced Lineup POJ - 3264
求区间最值问题题意:求区间最大值与最小值之差#include<stdio.h>#include<string.h>#include<math.h>#include<algorithm>using namespace std;const int maxn=2e6+10;int Log[maxn],ma[maxn][20],mi[maxn][20],a[maxn];int n,m;int main(){ scanf("%d%d",&原创 2020-10-04 14:39:22 · 46 阅读 · 0 评论 -
Matrix POJ - 2155
树状数组题意:给定一个矩阵,有两种操作,一种是对于其子矩阵进行取反操作,另一种是查询某一个位置的值。思路:这一题是二位树状数组的模板题可能是不熟练的原因吧,做题的时候花费了很长时间#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;const int maxn=1100;typedef long long ll;int a[maxn][maxn];int原创 2020-10-04 09:01:46 · 84 阅读 · 0 评论 -
Balanced Lineup POJ-3264(线段树)
For the daily milking, Farmer John’s N cows (1 ≤ N ≤ 50,000) always line up in the same order. One day Farmer John decides to organize a game of Ultimate Frisbee with some of the cows. To keep things ...原创 2019-08-02 18:48:11 · 83 阅读 · 0 评论 -
Mayor‘s posters POJ-2528(线段树+离散化)
The citizens of Bytetown, AB, could not stand that the candidates in the mayoral election campaign have been placing their electoral posters at all places at their whim. The city council has finally d...原创 2019-08-05 08:10:05 · 85 阅读 · 0 评论 -
Distinct Characters Queries(树状数组)
ou are given a string s consisting of lowercase Latin letters and q queries for this string.Recall that the substring s[l;r] of the string s is the string slsl+1…sr. For example, the substrings of “c...原创 2019-10-06 10:08:47 · 266 阅读 · 0 评论 -
Little Elephant and Array
莫队模板题题意:区间查询,每次查询指定区间内出现次数与其值相等的数的个数。#include<stdio.h>#include<string.h>#include<algorithm>using namespace std;#include<math.h>#define debug coutconst int maxn=1e5+100;int in[maxn],app[maxn],bel[maxn],ans[maxn];struct node原创 2020-09-28 21:48:39 · 64 阅读 · 0 评论