自定义博客皮肤VIP专享

*博客头图:

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

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

博客底图:

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

栏目图:

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

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

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

原创 springboot启动报错

2023-10-30 13:42:08 149

原创 树的直径&

模板题,让你求距离最远的两个节点的距离,那么就是树的直径。树的直径怎么求,首先随便从一点u开始搜索找到离他最远的点t1,再从该点t1,搜索出离t1最远的点t2,t1跟t2就是树上最远两点。详细证明参考这篇博客。树上最远两点(叶子结点)的距离。这里推荐dfs求树的直径。值更大,求直径最远标记的两个点的中点距离就是答案。求出所有节点离他最远的节点距离。

2023-10-14 17:58:39 189

原创 基础查缺 归并排序+尺取法

归并排序 尺取法

2022-10-20 11:23:06 400 1

原创 如何造数据&对拍

ACM如何造题目数据和对拍

2022-09-30 10:51:04 626

原创 Danil and a Part-time Job (dfs序 + 线段树)

传送门Description给你一棵树, 每个节点都是一盏灯,有开和关的状态,有两种操作:1、查询以u为根节点的子树,有多少个节点(包括根节点)亮着。2、更改以u为根节点的子树,亮->暗,暗->亮(包括根节点)亮着。Solution先用dfs序将树处理成线段树可以维护的状态, 然后线段树维护即可。push_up里面没有写push_down,调了半天。。。时间复杂度:求dfs序O(n),维护线段树O(logn)Code#include <bits/stdc++.h.

2022-05-22 15:08:36 121

原创 POJ3321 Apple Tree dfs序列模板

#include <iostream>#include <cstring>#include <vector>using namespace std;const int N = 1e5 + 10;int n, m;int idx, in[N], out[N], mp[N];int c[N], vis[N];struct node { int to, nex;}e[N << 1];int cnt, head[N];void a

2022-05-22 13:18:17 102

原创 Codeforces Round #770 (Div. 2) ABC题解

比赛传送门题目目录A、Reverse and ConcatenateB、 Fortune TellingC、OKEAA、Reverse and Concatenate题意:就是给你一个字符串,然后经过k次翻转能得到多少种不同的字符串,他问的其实是一次变化的可能数。思路:如果这个串是回文串,无论怎么变化都是一种,如果这个串不是回文串,经历过一次变化也会变成回文串所以答案显然易见:原串是回文串或者操作为0的情况下:1否则是:2 int t; read(t); while

2022-02-07 10:47:21 351

原创 NOIP借教室 (线段树无脑维护区间最小值)

线段树维护的信息就是区间最小值,进行教室的订单的时候,将相应的区间减去值就可以了,然后查询区间是否出现小于0的数,出现了则不满足,即是答案。#include <bits/stdc++.h>#define go continue#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#define fory(i,a,b) for(int i = a; i <= b; ++i)using namespace std

2022-02-05 19:45:37 349

原创 炸鸡块君与FIFA22 线段树 (2022牛客寒假集训营1)

维护三棵线段树,当前%3余数是多少时的得分,进行push_up的时候,右区间对区间的贡献的影响需要加上左区间的影响。具体看代码,清晰易懂#include <bits/stdc++.h>#define endl '\n'#define go continue#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#define fory(i,a,b) for(int i = a; i <= b; ++i)/..

2022-02-03 15:44:22 128

原创 维护区间最大连续子段和 (线段树)

link#include <bits/stdc++.h>#define go continue#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#define fory(i,a,b) for(int i = a; i <= b; ++i)using namespace std;template <typename T> inline void read(T& t){

2022-02-02 21:31:09 422

原创 最大数(线段树)

link#include <bits/stdc++.h>#define go continue#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#define fory(i,a,b) for(int i = a; i <= b; ++i)//-----#define int long long//-----using namespace std;template <typename T&g

2022-02-02 14:38:31 276

原创 单调队列模板&滑动窗口

链接: 模板题数组模拟队列基本操作//在队尾插入元素 队友弹出元素int q[N],hh,tt = -1;//插入q[++tt] = x;//弹出hh++//判空hh <= tt ? not empty : empty//队头 队尾q[hh]q[tt]#include <bits/stdc++.h>#define fory(i,a,b) for(int i = a; i <= b; ++i)using namespace std;tem

2022-01-29 16:51:40 532

原创 单调栈模板&数组模拟优化

链接: 模板题链接.STL做法,简单易懂,但是太慢了,后面有优化#include <bits/stdc++.h>using namespace std;const int N = 3e6 + 10;int n, a[N], b[N];stack<int> st;signed main() { scanf("%d", &n); for(int i = 1; i <= n; i++) scanf("%d", &a[i]);

2022-01-29 11:07:45 894

原创 单源最短路 dijkstra算法模板

链接: 模板题不能处理带负边权的情况/*邻接矩阵存图1、从源点开始每次选取一个离点集距离最近的点t 添加到集合中2、利用t点对集合中的点进行松弛操作,进行更新时间复杂度o(n²)*/#include <bits/stdc++.h>#define go continue#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#define fory(i,a,b) for(int i = a; i <=

2022-01-28 11:25:03 1107

原创 小沙的算术 分块 (2022牛客寒假集训营2)

链接: link.题解思路:分块的思想,加法的一块,乘法的放在一块,然后对于该块进行更新的时候,使用逆元的方式进行更新(加法的块和乘法的块,都可以用逆元去进行处理)#include <bits/stdc++.h>#define int long long#define go continue#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);#define forl(i,a,b) for(int i = ..

2022-01-27 16:12:54 245

原创 LIS最长上升子序列模板

链接: link.解法一:动态规划思路:暴力朴素解法,不解释,暴力dp,f[i]表示以第i个元素结尾的最大lis值f[i] = max(f[j]+1)复杂度o(n²) 数据量大点就不能接受了#include <bits/stdc++.h>using namespace std;const int N = 1009;int n;int a[N],f[N];signed main(){ ios::sync_with_stdio(false);

2022-01-18 11:00:13 397

原创 线性dp-数字三角形

解法一:个人认为最好的解法,也是最容易懂的,自底而上dp,是最好的方式,f[1][1]直接就是答案#include <bits/stdc++.h>#define int long longusing namespace std;const int N = 600;int n;int f[N][N];signed main(){ ios::sync_with_stdio(false); cin>>n; for(in.

2022-01-18 09:44:07 272

原创 分组背包模板

链接: link#include <bits/stdc++.h>using namespace std;const int N = 1e3 + 9;int n, m, v[N][N], w[N][N], s[N];int f[N];signed main() { ios::sync_with_stdio(false); cin >> n >> m; for(int i = 1; i <= n; i++) {

2022-01-16 16:25:15 273

原创 NOIP均分纸牌(贪心)

#include <bits/stdc++.h>using namespace std;int n,a[10010],s,avg;signed main(){ cin>>n; for(int i =1;i<=n;i++){ cin>>a[i]; avg+=a[i]; } avg/=n; for(int i =1;i<=n;i++){ if(a[i]==avg) co

2022-01-14 15:21:51 143

原创 C++字符串k进制数转化成十进制数字

记录一下,之前都是遍历乘对应的的次方,这个算法更快int cnt(string s, int b) { int ok = 0; for(auto c : s) ok = ok * b + (c - '0'); return ok;}

2022-01-14 12:06:36 480

原创 牛客xiao白月赛43 D题 有趣的区间

链接: link.思路:提供一种非常通俗易懂的做法,数组里的每个数奇数看成1 偶数 0,计算连续0区间能构成的子区间数,加起来,用总的区间数减去他。(因为只要区间里面含有1,结果都是奇数,只要把都是0的区间数挖掉就行)长度为n的区间子区间个数为n*(n+1)/2#include <bits/stdc++.h>#define int long longusing namespace std;const int N = 5e5 + 10;int n, a[N];signed m

2022-01-14 11:00:28 138

原创 矩阵快速幂模板

目录一、代码模板二、模板题1.P3390 【模板】矩阵快速幂2.P1962 斐波那契数列一、代码模板#include <bits/stdc++.h>#define int long longusing namespace std;const int mod = 1e9 + 7;const int N = 1e2 + 9;int n, m;struct node { int c[N][N]; //*运算符重载} A, B; //A就是题目输入的 B就是单位矩阵node

2022-01-13 15:22:27 74

原创 离散化模板

#include <bits/stdc++.h>using namespace std;const int N = 1e3 + 10;int n, d[N]; //n个数 离散化后数组struct node { int x, id; bool operator<(const node& t)const { //按照值小的排前面 值相同先出现的排前面 可调整 return x == t.x ? id < t.id : x

2022-01-13 15:11:44 84

原创 二分+秦九韶算法 求凸点

链接: 原题题意就是给定一个区间,[l,r],保证函数中间有凸点,求导+秦九韶算法+二分。秦九韶算法的公式,可将多项式的计算时间复杂度降到o(n)方#include <bits/stdc++.h>using namespace std;const int N = 100;const double eps = 1e-10;int n;double l, r, a[N];//秦九韶公式的计算,每一个多项式的值都根据比自己高一次的值来进行计算inline double f(do

2022-01-13 11:19:14 219

原创 codeforces/contest/1624 div3题解ABCD

目录A、Plus One on the SubsetB、Make APC、Division by Two and PermutationD、Palindromes Coloring链接: linkA、Plus One on the Subset思路:差分排序就好了#include <bits/stdc++.h>#define int long longusing namespace std;const int N = 1e2 + 9;int n, a[N];bool cmp(i

2022-01-11 14:57:48 292

原创 蓝桥杯基础题集训练三

目录1、报时助手2、1、报时助手大模拟//a ber#include <bits/stdc++.h>using namespace std;map<int, string> ok;int n, m;void init() { ok[0] = "zero"; ok[1] = "one"; ok[2] = "two"; ok[3] = "three"; ok[4] = "four"; ok[5] = "five";

2022-01-09 16:39:38 301

原创 蓝桥杯 基础训练-2n皇后问题

解题思路:蓝桥杯不错的一道暴力题,直接两个dfs暴搜就行,每次放一行,枚举列,如果先放白色的,那么放置完记得把地图标为不可放置,这样再跑黑色皇后的时候,就不会出现重复的放置。talk is cheap, show me the code//a ber#include <bits/stdc++.h>using namespace std;const int N = 1e2 + 10;int n, ok, mp[N][N];int v1[N], v1x[N], v1y[N]; //

2022-01-09 10:15:57 343

原创 快速幂模板

//a ber#include <bits/stdc++.h>using namespace std;const int mod = 1e7 + 9;int fp(int a, int b) { int res = 1; while(b) { if(b & 1) res = (res * a) % mod; b >>= 1; a = (a * a) % mod; } return res;

2022-01-08 22:46:04 120

原创 素数筛模板

//a ber#include <bits/stdc++.h>using namespace std;const int N = 1e7 + 5;int p[N];int vis[N];//vis[i]=0 素数void ola(int n){ int cnt = 0; for (int i = 2; i <= n; i++){ if (vis[i] == 0) p[cnt++] = i; for (int j = 0; p[j

2022-01-08 22:16:00 338

原创 蓝桥杯 基础训练-素数环

思路:直接dfs就好,但是得加个剪枝,就是奇数个的情况不能形成素数环。剪枝:任意两个相邻的数,不可能都是奇数,也不可能都是偶数,因为这样他们的和都不是素数,奇数个数一定有偶数个奇数,必然会出现两个相邻的奇数(包括首尾),这样就不符合条件了,加上这个剪枝就好了。#include <bits/stdc++.h>using namespace std;const int N = 1e2 + 7;int ok, p[N], vis[N], cnt, a[N], f, n, v[N];voi

2022-01-08 16:32:21 411

原创 线段树 模板二 :单点查询 区间修改

模板题传送门#include<bits/stdc++.h>#define ll long longusing namespace std;const int MAXN = 100005;ll a[MAXN];int ok;struct tnode { int l, r; ll lazy;};struct Segment_Tree { tnode t[4 * MAXN]; void build(int root, int l, int r) {

2022-01-08 15:08:13 159

原创 蓝桥杯基础题集训练二

目录1、阶乘计算2、高精度加法3、Huffuman树1、阶乘计算#include <bits/stdc++.h>using namespace std;const int N = 1e5 + 9;int n, f[N];signed main() { f[0] = 1; scanf("%d", &n); for(int i = 2; i <= n; i++) { int add = 0; for(int j = 0

2022-01-07 21:59:27 363

原创 蓝桥杯基础题集训练一

目录1、字母图形2、01字串3、Fibonacci数列4、圆的面积5、十六进制转八进制6、十六进制转十进制7、十进制转十六进制1、字母图形//a ber#include <bits/stdc++.h>using namespace std;int n, m;char a[100][100];signed main() { scanf("%d%d", &n, &m); //打印第一行 for(int i = 0; i < m; i++)

2022-01-06 21:44:06 398

原创 线段树 模板一:单点修改 区间查询

模板题链接//线段树 单点修改 区间查询#include <bits/stdc++.h>#define int long longusing namespace std;const int N = 1e5 + 7;int n, m, a[N];struct node { int l, r, sum; //一条线段 边界 值};struct segment_tree { node t[N << 2]; //节点 一般开四倍容量 int

2022-01-06 15:53:36 159

原创 2022-1-5训练

目录1、智乃酱的区间乘积2、牛牛的猜球游戏3、智乃酱的双塔问题4、NOIP积木大赛 道路铺设5、Dragon of Loowater1、智乃酱的区间乘积tag:线段树 逆元 前缀和https://ac.nowcoder.com/acm/problem/225632//a ber#include <bits/stdc++.h>#define int long longusing namespace std;const int mod = 1e9 + 7;const int N =

2022-01-05 17:11:03 2716

原创 codeforces/contest/1613 ABC题解

链接: 传送门.A0的个数有1e6 所以不能直接比,分类讨论,注意细节就好,如果一个数小于另外一个数且0的个数又比它大,看他消耗多少个0能比它大,且剩下的个数0合法void solve(){ scanf("%d%d%d%d",&x1,&p1,&x2,&p2); if(x1==x2){ if(p1==p2) { puts("=");return ; }else if(p1>p2){

2021-12-02 10:14:56 547

原创 二分(整数二分,浮点数二分模板)

二分写起来这是让人头疼的东西一、整数二分int bs1(int l, int r) { while(l < r) { int mid = (l + r) >> 1; //如果满足某种性质,答案在左半边 if(check(mid)) r = mid; else l = mid + 1; } return l;}int bs2(int l,int r){ while(l<r){

2021-11-22 17:01:36 327

原创 codeforces/contest/1589 ABC题解

https://codeforces.com/contest/1589A:两个数分别是-n方和m方,代入进行推导,就是一个平方差公式。void solve() { _read(u),_read(v); cout<<-u*u<<" "<<v*v<<"\n";}B贪心,尽量分成三个的,加个2取余3即可int u, v; _read(u), _read(v); cout<<(u*v+2)/3<<

2021-11-14 19:39:35 290

原创 codeforces/contest/1605 ABC题解

https://codeforces.com/contest/1605A://由于可以转移,最终都可以1 1 1这种比例,如果不是%3==0,0 1 1,差1void test() { int a,b,c; _read(a),_read(b),_read(c); if((a+b+c)%3==0) puts("0"); else puts("1");}B:`//暴力遍历就可以,10序列下标计入答案,排序输出void solve() { _read(n),

2021-11-13 11:56:47 751

原创 HDU-5533 Dancing Stars on Me

http://acm.hdu.edu.cn/showproblem.php?pid=5533暴力跑出所有可能边的长度,然后看有没有出现n次的长度,符合题意,可以不用sqrt算具体的长度,容易出现精度问题。#include<bits/stdc++.h>#define _rep(i,a,b) for( int i=(a); i<=(b); ++i)#define _down(i,a,b) for( int i=(a); i>=b; i--)using namespace std

2021-11-08 09:50:28 74

空空如也

空空如也

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

TA关注的人

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