
蓝桥杯
岁忧
(目前更新LeetCode每日一题ing)记录一些平时做的题目,写些小小的心得。
展开
专栏收录文章
- 默认排序
- 最新发布
- 最早发布
- 最多阅读
- 最少阅读
-
第十五届蓝桥杯C/C++程序设计研究生组国赛 国二
这次早上做题脑子不呆呆的了,题目做的挺顺利的,该会的会,不会的不会。果然这段时间早上写题没白写,hhhhhh。虽然旁边的人敲键盘非常大声,还喜欢自造噪音。但好在稳住了心态。填空题两个,大题忘记了,前几道题(好像三四道),应该都能拿下100%。后面几道就是骗分,最后几题太难了本科拿的也是国二,好像也是和国一差十多个人左右,有种宿命感。哎,不过这可是研究生组,大佬还是很强的,拿个国二也很开心啦原创 2024-06-03 10:22:23 · 644 阅读 · 2 评论 -
第十四届蓝桥杯大赛软件赛国赛C/C++研究生组(持续更新ing)
【代码】第十四届蓝桥杯大赛软件赛国赛C/C++研究生组(持续更新ing)原创 2024-05-28 10:34:22 · 1116 阅读 · 0 评论 -
Acwing 算法提高课 第一章 动态规划
题目:1015. 摘花生#include <bits/stdc++.h> using namespace std;typedef long long LL;typedef pair<int ,int >PII;const int N=(1<<11)+10; const int mod=1e9+7; int t,r,c; int a[110][110];int main() { cin>>t; while(t--){ cin>原创 2022-04-05 23:56:29 · 412 阅读 · 0 评论 -
Acwing算法基础课 第五讲 动态规划
题目:2. 01背包问题#include <bits/stdc++.h> using namespace std;typedef long long LL;typedef pair<int ,int >PII;const int N=2e5+10; int n,V;int f[1010]; int main() { scanf("%d%d",&n,&V); int v,w; for(int i=1;i<=n;i++){ cin>原创 2022-04-04 00:15:20 · 1057 阅读 · 0 评论 -
Acwing蓝桥杯省赛专题训练之复杂DP(相关真题和模板题)
题目:1050. 鸣人的影分身题解:相当于有m个苹果n个盘子,问有多少种分法。盘子可以为空,但m个苹果要分完#include <bits/stdc++.h> using namespace std;typedef long long LL;typedef pair<int ,int >PII;const int N=(1<<20)+10;int m,n;LL f[15][15];int main() { int t; scanf("%d",&原创 2022-04-02 15:16:03 · 521 阅读 · 0 评论 -
Acwing蓝桥杯省赛专题训练之数论(相关真题和模板题)
题目:1246. 等差数列题解:数论+最大公约数。#include <bits/stdc++.h> using namespace std;typedef long long LL;typedef pair<int ,int >PII;const int N=1e5+10;int n;int a[N];int gcd(int x,int y){ return y?gcd(y,x%y):x;}int main() { cin>>n; for(i原创 2022-04-01 20:37:47 · 1829 阅读 · 0 评论 -
Acwing蓝桥杯省赛专题训练之贪心(相关真题和模板题)
题目:1055. 股票买卖 II题解:贪心#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<int ,int > PII;const int N=1e5+10;int n;int a[N];int main(){ cin>>n; for(int i=0;i<n;i++){ scanf("%d",&a[i]); } LL原创 2022-03-31 23:49:50 · 1138 阅读 · 0 评论 -
蓝桥杯省赛专题训练之双指针、BFS与图论(相关真题和模板题)
题目:1238. 日志统计题解:双指针。#include <bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<int ,int > PII;const int N=1e5+10;int n,d,k;PII a[N];//queue<int> q[N];int ct[N];bool sta[N];int main() { cin>>n>>原创 2022-03-31 20:08:36 · 1013 阅读 · 0 评论 -
蓝桥杯省赛专题训练之树状数组与线段树(相关真题和模板题)
题目:1264. 动态求连续区间和题解:线段树模板题#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<int,int> PII;const int N=1e5+10;const int mod=100000007;int n,m;int a[N];int p[N<<2];void pushup(int u){ p[u]=p[u<&原创 2022-03-31 01:38:09 · 560 阅读 · 0 评论 -
蓝桥杯省赛专题训练之枚举、模拟与排序(相关真题和模板题)
题目:1210. 连号区间数题解:枚举。复杂度最多为0(10^7)#include<bits/stdc++.h>using namespace std;typedef long long LL;const int N=1e5+10;const int mod=100000007;int n;int a[10010];int main(){ cin>>n; for(int i=0;i<n;i++) scanf("%d",&am原创 2022-03-30 11:47:05 · 1173 阅读 · 0 评论 -
蓝桥杯省赛专题训练之数学与简单DP(相关真题和模板题)
题目:1205. 买不到的数目题解:任意两个数的gcd(n,m)为1,则它俩最大不能表示出来的数为(n-1)*(m-1)-1;若gcd(n,m)不为1,则有无穷多个数不能表示出来。#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<int ,int>PII;const int N=1e5+10;const int mod=1000000009;int n,m;in原创 2022-03-29 22:54:43 · 1048 阅读 · 0 评论 -
蓝桥杯省赛专题训练之二分与前缀和(相关真题和模板题)
题目:789. 数的范围题解:二分模板题。#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<double,double>PII;const int N=1e5+10;const int mod=1000000009;int a[N];int n,q;void findd(int k){ int l=1,r=n; while(l<r){原创 2022-03-29 16:05:16 · 393 阅读 · 0 评论 -
蓝桥杯省赛专题训练之递归与递推训练(相关真题和模板题)
题目:92. 递归实现指数型枚举题解:递归。注意不存在的空行也是需要输出的,否则报错。方法一:#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<double,double>PII;const int N=1e5+10;const int mod=1000000009;int n;int a[20];void dfs(int u,int ct){ i原创 2022-03-28 20:18:36 · 1003 阅读 · 0 评论 -
第十一届蓝桥杯省赛第一场C++A/B组真题
题目:2065. 整除序列题解:模拟。#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<double,double>PII;const int N=1e5+10;const int mod=1000000009;int main(){ LL n; scanf("%lld",&n); while(n){ print原创 2022-03-28 17:57:14 · 1081 阅读 · 0 评论 -
第十二届蓝桥杯省赛第一场C++A/B/C组真题(持续更新中...)
题目:3416. 时间显示题解:模拟+字符串处理#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<double,double>PII;const int N=2e5+10;const int mod=1000000009;LL n;int main(){ cin>>n; n/=1000; int s=n%60; n原创 2022-03-27 22:25:58 · 1356 阅读 · 0 评论 -
第十二届蓝桥杯省赛第二场C++B组真题
题目:3496. 特殊年份题解:模拟+枚举#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<double,double>PII;const int N=2e5+10;const int mod=1000000009;int main(){ int x; int ans=0; for(int i=0;i<5;i++){原创 2022-03-26 23:17:40 · 3019 阅读 · 0 评论 -
acwing(树型dp) 1078. 旅游规划(蓝桥杯)
题目:1078. 旅游规划思路:求出每个结点i的最大子长度和次大子长度(中途可以求出maxd),以及父节点的最大长度,然后再在这三个长度里面选出最大的两个求其和,并判断是否和maxd相等#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<double,double>PII;const int N=2e5+10;const int mod=1000000009;i原创 2022-03-25 00:58:33 · 256 阅读 · 0 评论 -
acwing 1070. 括号配对(蓝桥杯)
题目:1070. 括号配对思路:大佬思路,具有区间性,然后又是可以按边界来更新状态,所以可以考虑区间dp,#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<double,double>PII;const int N=1e5+10;const int mod=1000000009;char a[110];int f[110][110];//f[i][j]中,i表原创 2022-03-25 00:34:31 · 652 阅读 · 0 评论 -
acwing 1226. 包子凑数(蓝桥杯)
题目:1226. 包子凑数思路:先对每种a[i]进行求最大公约数res,如果res!=1,那么存在无穷个不能表示的,当res==1时,说明只有有些歌数不能表示出来。对于任意两个满足gcd(x,y)=1的x,y,其不能表示出来的最大数为(x-1)*(y-1)-1,而100以内 互质的最大的两个数为99和98,因此不能表示的最大数不超过10000,然后进行完全背包即可#include<bits/stdc++.h>using namespace std;typedef long long原创 2022-03-25 00:12:41 · 222 阅读 · 0 评论 -
acwing(矩阵乘法+快速幂) 1303. 斐波那契前 n 项和(蓝桥杯)
题目:1303. 斐波那契前 n 项和大佬思路#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<double,double>PII;const int N=1e5+10;const int mod=1000000009;LL n,m;LL s[3][3]={{2,0,-1},{1,0,0},{0,1,0}};void mult1(LL x[3],LL原创 2022-03-24 23:54:03 · 243 阅读 · 0 评论 -
acwing(树状dp)1220. 生命之树(蓝桥杯)
题目:1220. 生命之树思路:树状dp,#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<double,double>PII;const int N=1e5+10;const int mod=1000000009;int n;int a[N];vector<int >g[N];LL f[N];void dfs(int u,int fa)原创 2022-03-24 17:22:05 · 505 阅读 · 0 评论 -
acwing(区间dp+GOOD )1222. 密码脱落(蓝桥杯)
题目:1222. 密码脱落思路:大佬思路,这是一道区间dp的题,判断边界是否相等,因为求的是最小,所以要先把f置为无穷大#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<double,double>PII;const int N=(1<<20)+10;const int mod=1000000009;char a[1010];int f[101原创 2022-03-24 16:27:53 · 600 阅读 · 0 评论 -
acwing(dp+GOOD) 1047. 糖果(蓝桥杯)
题目:1047. 糖果思路:dp,对于第i件糖果有两种选择,选或者不选,不选就是f[i][j]=f[i-1][j],选的话f[i][j]=max(f[i][j],f[i-1][((j-a[i])%m+m)%m]+a[i])。这里我们需要注意的是存在不合法的状态,所以先将f[i][j]里的值都置为负无穷,然后分析发现最开始只有f[0][0]的状态合法,将其置为0即可#include<bits/stdc++.h>using namespace std;typedef long long原创 2022-03-24 15:32:38 · 196 阅读 · 0 评论 -
acwing(dp集合GOOD )1050. 鸣人的影分身(蓝桥杯)
题目:1050. 鸣人的影分身思路:该问题等价于将m个苹果放置在无序的n个盘子里有多少种方法#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<double,double>PII;const int N=(1<<20)+10;const int mod=1000000009;int f[15][15];//f[i][j],i表示的是苹果数量,j表示的是原创 2022-03-24 15:01:23 · 174 阅读 · 0 评论 -
acwing(GOOD)1295. X的因子链(蓝桥杯)
题目:1295. X的因子链**思路:先线性筛法求出2^20之前所有的质数,并同时记录下每个m的最小质素,然后再去对x进行质因数分解,每个质数的次方pi之和cnt为最长的长度(pi+p2+…+pn=cnt),然后进行全排列,求出有多少种cnt!/(p1!p2!..pn!),#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<double,double>PII;cons原创 2022-03-23 22:32:04 · 241 阅读 · 0 评论 -
acwing 1246. 等差数列(蓝桥杯)
题目:1246. 等差数列思路:先升序排序,然后都和第一项取差值,然后对这n-1个差值进行求最大公约数res,当res!=0时,最少的项数=(a[n-1]-a[0])/res+1,若res==0,则最小的项数为n#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<double,double>PII;const int N=1e5+10;const int mod=1原创 2022-03-23 21:57:55 · 397 阅读 · 0 评论 -
acwing 1248. 灵能传输(蓝桥杯)
题目:1248. 灵能传输思路:仔细分析后会发现对某一点i操作,有影响的是si-1和si换了一个位置,也就是说只有s0和sn不能移动,然后对s0~sn进行排序。安排si在合适的位置即可大佬的思路#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<double,double>PII;const int N=3e5+10;const int mod=1000000原创 2022-03-23 20:57:29 · 389 阅读 · 0 评论 -
acwing 1247. 后缀表达式(蓝桥杯)
题目:1247. 后缀表达式思路:对于后缀表达式,只要没有负号,那就是所有数相加即可。当有负号时,sum就是先+最大值,然后-最小值,中间的数都取绝对值加在sum里即可。说白了就是有负号的话,除了最小值不能反转,其余可反可不反大佬详解#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<double,double>PII;const int N=2e5+10;con原创 2022-03-23 20:31:21 · 629 阅读 · 0 评论 -
acwing 1239. 乘积最大(蓝桥杯)
题目:1239. 乘积最大#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<double,double>PII;const int N=1e5+10;const int mod=1000000009;int n,k;int a[N];int main(){ cin>>n>>k; for(int i=0;i<n;i原创 2022-03-23 20:06:40 · 596 阅读 · 0 评论 -
acwing 1235. 付账问题(蓝桥杯)
题目:1235. 付账问题思路:大佬思路#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<double,double>PII;const int N=5e5+10;const int mod=100000007;int n;LL s;int a[N];int main(){ cin>>n>>s; for(int i原创 2022-03-22 21:54:52 · 483 阅读 · 0 评论 -
acwing 112. 雷达设备(蓝桥杯)
题目:112. 雷达设备思路:先算出可以覆盖每个小岛的区间l,r,然后按r来排序进行贪心即可#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<double,double>PII;const int N=1e5+10;const int mod=100000007;int n,d;PII a[1010];int main(){ cin>>n原创 2022-03-22 21:36:07 · 219 阅读 · 0 评论 -
acwing104. 货仓选址(蓝桥杯)
题目:104. 货仓选址思路:选在中位数的地方即可#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<int,int >PII;const int N=1e5+10;const int mod=100000007;int n;int a[N];int main(){ cin>>n; for(int i=0;i<n;i++){原创 2022-03-22 21:00:55 · 239 阅读 · 0 评论 -
acwing 1055. 股票买卖 II(蓝桥杯+贪心)
题目:1055. 股票买卖 II#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<int,int >PII;const int N=1e5+10;const int mod=100000007;int main(){ int n; int a[100100]; cin>>n; for(int i=1;i<=n;原创 2022-03-22 20:56:24 · 203 阅读 · 0 评论 -
acwing 826. 单链表(模板题+链式前向星)
题目:826. 单链表#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<int,int >PII;const int N=1e5+10;const int mod=100000007;int m;int head=-1;int e[N],ne[N],cnt=1;void add(int u){ e[cnt]=u; ne[cnt]=head;原创 2022-03-22 20:51:35 · 700 阅读 · 0 评论 -
acwing 1207. 大臣的旅费(蓝桥杯)
题目:1207. 大臣的旅费思路: 先从1出发找到距离该点最大的点m,再从m出发找到距离m最大的点z即可,其中可得最大的距离ans方法一:dfs#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<int,int >PII;const int N=1e5+10;const int mod=100000007;int n;vector<PII> g[原创 2022-03-22 20:39:47 · 363 阅读 · 0 评论 -
acwing 1233. 全球变暖(蓝桥杯)
题目:1233. 全球变暖思路:dfs,在dfs时判断周围是否都是陆地,是的话,这次dfs就不会被淹#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<int,int >PII;const int N=1e5+10;const int mod=100000007;char a[1010][1010];bool sta[1010][1010];int fx[4原创 2022-03-22 18:30:52 · 186 阅读 · 0 评论 -
acwing 1096. 地牢大师(蓝桥杯)
题目:1096. 地牢大师#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<int,int >PII;const int N=1e5+10;const int mod=100000007;char a[105][105][105];bool sta[105][105][105];int l,r,c;typedef struct Node{ int原创 2022-03-22 18:10:54 · 153 阅读 · 0 评论 -
acwing 1240. 完全二叉树的权值(蓝桥杯)
题目:1240. 完全二叉树的权值#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<int,int >PII;const int N=1e5+10;const int mod=100000007;int n;int a[N];int main(){ cin>>n; for(int i=1;i<=n;i++){原创 2022-03-22 17:43:07 · 1565 阅读 · 0 评论 -
acwing(GOOD) 1224. 交换瓶子(蓝桥杯)
题目:1224. 交换瓶子思路:大佬的思路#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<int,int >PII;const int N=1e4+10;const int mod=100000007;int n;int a[N];bool sta[N];int main(){ cin>>n; for(int i=1;i&原创 2022-03-22 17:26:26 · 241 阅读 · 0 评论 -
acwing 1113. 红与黑(蓝桥杯)
题目:1113. 红与黑#include<bits/stdc++.h>using namespace std;typedef long long LL;typedef pair<int,int >PII;const int N=1e5+10;const int mod=100000007;int fx[4]={0,0,1,-1},fy[4]={1,-1,0,0};int w,h;char a[25][25];int main(){ while(cin原创 2022-03-20 18:04:43 · 393 阅读 · 0 评论