
算法训练
忆灬凝
这个作者很懒,什么都没留下…
展开
-
蓝桥杯2022砍竹子
遍历每个竹子经历的所有高度,和他前一个竹子经历的所有高度一一比较,如果有相同的,则次数可以-1。每读入一个竹子的高度h,就计算出单独把他砍到1需要的次数和每一次的高度。原创 2023-04-05 22:24:45 · 179 阅读 · 0 评论 -
最长公共子序列LCS
Problem - 1159http://acm.hdu.edu.cn/showproblem.php?pid=1159打印路径原创 2022-12-06 17:48:37 · 136 阅读 · 0 评论 -
Bone Collector_0/1背包问题_DP
Problem - 2602http://acm.hdu.edu.cn/showproblem.php?pid=2602打印选择路径:滚动数组:原创 2022-12-06 13:32:36 · 317 阅读 · 0 评论 -
Coin Change_DP
Problem - 2069http://acm.hdu.edu.cn/showproblem.php?pid=2069原创 2022-12-06 12:08:53 · 205 阅读 · 0 评论 -
第十二届蓝桥杯国赛_巧克力_堆
蓝桥杯2021年第十二届国赛真题-巧克力 - C语言网小蓝很喜欢吃巧克力,他每天都要吃一块巧克力。一天小蓝到超市想买一些巧克力。超市的货架上有很多种巧克力,每种巧克力有自己的价格、数量和剩余的保质期天数,小蓝只吃没过保质期的巧克力,请问小蓝最少花多少钱能……https://www.dotcpp.com/oj/problem2621.html...原创 2022-06-04 19:51:27 · 526 阅读 · 0 评论 -
蓝桥杯2022青蛙过河_二分枚举
P2026 - [蓝桥杯2022初赛] 青蛙过河 - New Online Judgehttp://oj.ecustacm.cn/problem.php?id=2026二分枚举y,于是check的方法为:每一段长度为y的区间内的石头高度总和是否>=2x。如果有一段长度为y的区间不能被经过2x次,那么肯定不行。#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 1e5 +原创 2022-05-12 20:35:16 · 541 阅读 · 0 评论 -
蓝桥杯2022技能升级_二分枚举
P2045 - [蓝桥杯2022初赛] 消除游戏 - New Online Judgehttp://oj.ecustacm.cn/problem.php?id=2045原创 2022-05-12 12:29:56 · 671 阅读 · 0 评论 -
蓝桥杯2022特殊时间_枚举
P2042 - [蓝桥杯2022初赛] 特殊时间 - New Online Judgehttp://oj.ecustacm.cn/problem.php?id=2042#include<bits/stdc++.h>using namespace std;typedef long long ll;int m[13] = {0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};int checkMD(int a[]) { int原创 2022-05-11 09:30:08 · 749 阅读 · 0 评论 -
蓝桥杯2022扫雷_二分枚举
4407. 扫雷 - AcWing题库高质量的算法题库https://www.acwing.com/problem/content/description/4410/暴力。。。能过40%吧#include <bits/stdc++.h>using namespace std;typedef pair<int, int> PLL;typedef long long ll;const int N = 1e5 + 4;map<PLL, int>a;PLL c[原创 2022-05-09 22:53:13 · 482 阅读 · 0 评论 -
蓝桥杯2022统计子矩阵_前缀和
P2036 - [蓝桥杯2022初赛] 统计子矩阵 - New Online Judgehttp://oj.ecustacm.cn/problem.php?id=2036暴力能过80%的数据。。。#include <bits/stdc++.h>typedef long long ll;using namespace std;ll a[512][512] = { 0 };ll sum[512][512] = { 0 }; // sum[i][j]表示从a[1][1]到a[i][j]的原创 2022-05-09 18:27:43 · 483 阅读 · 0 评论 -
蓝桥杯2022积木画_DP
P2037 - [蓝桥杯2022初赛] 积木画 - New Online Judgehttp://oj.ecustacm.cn/problem.php?id=2037#include <bits/stdc++.h>typedef long long ll;using namespace std;const int N = 1e7 + 4;int mod = 1e9 + 7;ll dp[N] = { 0 };ll sum[N] = { 0 };int main() {原创 2022-05-09 16:26:22 · 424 阅读 · 0 评论 -
二分枚举上下界
二分枚举满足条件的最小值,即二分求下界,找第一个满足条件的下标while (left < right) { ll mid = (left + right) >> 1; if (check(mid)) { right = mid; } else { left = mid + 1; }}如果mid满足条件则right = mid,不满足条件则left = mid + 1二分枚举满足条件的最大值,即二分...原创 2022-05-07 10:15:01 · 147 阅读 · 0 评论 -
回文日期_二分
P1518 - [蓝桥杯2020初赛] 回文日期 - New Online Judgehttp://oj.ecustacm.cn/problem.php?id=1518#include <bits/stdc++.h>using namespace std;typedef long long ll;set<int>s;int isRun(int year) { return year % 4 == 0 && year % 100 != 0 || y原创 2022-04-07 17:09:46 · 342 阅读 · 0 评论 -
方格分割_DFS
P1320 - [蓝桥杯2017初赛]方格分割 - New Online Judgehttp://oj.ecustacm.cn/problem.php?id=1320#include <bits/stdc++.h>using namespace std;typedef long long ll;int ans=0;int vis[8][8] = {0};void dfs(int i, int j) { if (i <= 0 || j <= 0 || i >=原创 2022-04-07 12:58:21 · 241 阅读 · 0 评论 -
包子凑数_数论
P1322 - [蓝桥杯2017初赛]包子凑数 - New Online Judgehttp://oj.ecustacm.cn/problem.php?id=1322#include <bits/stdc++.h>using namespace std;typedef long long ll;int a[128]= {0};int vis[10240]= {0};int main() { int n; cin >> n; for(int i=原创 2022-04-06 23:30:18 · 147 阅读 · 0 评论 -
正则问题_递归
P1321 - [蓝桥杯2017初赛]正则问题 - New Online Judgehttp://oj.ecustacm.cn/problem.php?id=1321#include <bits/stdc++.h>using namespace std;typedef long long ll;int Index = 0;string str;int kuoHao() { // 一对括号里至少有一个 | int res = 0; int temp = 0;原创 2022-04-06 22:37:31 · 163 阅读 · 0 评论 -
分巧克力_二分枚举
P1323 - [蓝桥杯2017初赛]分巧克力 - New Online Judgehttp://oj.ecustacm.cn/problem.php?id=1323#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 100004;int n,k;int H[N]= {0},W[N]= {0};int check(int x) { int cnt = 0; .原创 2022-04-06 16:22:12 · 311 阅读 · 0 评论 -
迷宫_DFS
P1317 - [蓝桥杯2017初赛]迷宫 - New Online Judgehttp://oj.ecustacm.cn/problem.php?id=1317#include <bits/stdc++.h>using namespace std;typedef long long ll;string g[12];int vis[12][12]= {0};int res=0;int dfs(int i,int j) { if(i < 0 || j < 0原创 2022-04-06 11:59:09 · 100 阅读 · 0 评论 -
倍数问题_数论
P1366 - [蓝桥杯2018初赛]倍数问题 - New Online Judgehttp://oj.ecustacm.cn/problem.php?id=1366#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 100004;int a[N] = {0};vector<int>s[1024];int main() { cin.tie(0);原创 2022-04-06 00:10:47 · 244 阅读 · 0 评论 -
付账问题_模拟_高精度
P1367 - [蓝桥杯2018初赛]付账问题 - New Online Judgehttp://oj.ecustacm.cn/problem.php?id=1367#include <bits/stdc++.h>using namespace std;typedef long long ll;const int N = 5e5 + 4;double S;int n;vector<double>ms;int main() { ios::sync_with_原创 2022-04-05 22:49:48 · 355 阅读 · 0 评论 -
全球变暖_DFS
P1365 - [蓝桥杯2018初赛]全球变暖 - New Online Judgehttp://oj.ecustacm.cn/problem.php?id=1365#include <bits/stdc++.h>using namespace std;typedef long long ll;int N;char g[1024][1024] = { 0 };int vis[1024][1024] = { 0 };int res = 0;int cover;void dfs原创 2022-04-05 19:37:22 · 199 阅读 · 0 评论 -
糖果_状态压缩DP
P1460 - [蓝桥杯2019初赛]糖果 - New Online Judgehttp://oj.ecustacm.cn/problem.php?id=1460#include <bits/stdc++.h>#define INF 0x3f3f3f3fusing namespace std;typedef long long ll;int dp[1 << 20]; // dp[i]为得到口味为i时需要的最少数量int sg[128] = { 0 }; // sg[i原创 2022-04-04 20:30:06 · 215 阅读 · 0 评论 -
外卖店优先级_模拟_multiset
P1458 - [蓝桥杯2019初赛]外卖店优先级 - New Online Judgehttp://oj.ecustacm.cn/problem.php?id=1458#include <bits/stdc++.h>#define x first#define y secondusing namespace std;typedef long long ll;const int N = 100004;int n, m, t;multiset<int>s[N];b原创 2022-04-04 20:27:40 · 362 阅读 · 0 评论 -
迷宫_BFS
P1455 - [蓝桥杯2019初赛]迷宫 - New Online Judgehttp://oj.ecustacm.cn/problem.php?id=1455#include <bits/stdc++.h>#define x first#define y secondusing namespace std;typedef long long ll;int g[64][64] = { 0 };int vis[64][64] = { 0 };int di[] = { 1, 0原创 2022-04-04 20:22:20 · 343 阅读 · 0 评论 -
AcWing 3999. 最大公约数_欧拉函数求质数个数
3999. 最大公约数 - AcWing题库高质量的算法题库https://www.acwing.com/problem/content/description/4002/#include<bits/stdc++.h>using namespace std;typedef long long ll;int t;ll a, m;int main() { cin >> t; while (t--) { cin >> a >.原创 2022-03-30 16:00:09 · 220 阅读 · 0 评论 -
AcWing3973. 无线网络_二分枚举
3973. 无线网络 - AcWing题库高质量的算法题库https://www.acwing.com/problem/content/3976/切记范围开long long#include <bits/stdc++.h>#define x first#define y secondusing namespace std;typedef long long ll;const int N = 1e5 + 4;int n, m;int a[N] = { 0 }, b[N] = {原创 2022-03-29 16:15:14 · 162 阅读 · 0 评论 -
L2-001紧急救援_最短路径
PTA | 程序设计类实验辅助教学平台千名教师建设,万道高质量题目,百万用户拼题的程序设计实验辅助教学平台https://pintia.cn/problem-sets/994805046380707840/problems/994805073643683840#include <bits/stdc++.h>#define x first#define y second#define INF 0x3f3f3fusing namespace std;typedef long long原创 2022-03-24 15:39:23 · 776 阅读 · 0 评论 -
poj3981_string
http://poj.org/problem?id=3981http://poj.org/problem?id=3981#include <iostream>#define x first#define y secondusing namespace std;typedef long long ll;int main() { // system("chcp 65001"); cin.tie(0); cout.tie(0); // freopen("原创 2022-03-23 15:28:00 · 118 阅读 · 0 评论 -
poj1163_DP从底往上
1163 -- The Trianglehttp://poj.org/problem?id=1163#include <iostream>#define x first#define y secondusing namespace std;typedef long long ll;int dp[128][128] = { 0 };int a[128][128] = { 0 };int main() { // system("chcp 65001"); ..原创 2022-03-22 22:45:49 · 340 阅读 · 0 评论 -
hdu1159_DP_最长公共子序列
#include <bits/stdc++.h>#define x first#define y secondusing namespace std;typedef long long ll;int dp[1024][1024] = { 0 };int main() { // system("chcp 65001"); cin.tie(0); cout.tie(0); freopen("C:/Users/zhaochen/Desktop/input..原创 2022-03-22 22:21:03 · 310 阅读 · 0 评论 -
hdu1257_DP_最长递增子序列
#include <bits/stdc++.h>#define x first#define y secondusing namespace std;typedef long long ll;int a[10240] = { 0 };int n;void f() { int ans = 1; int dp[10240] = { 0 }; // dp[i]是第i个数结尾的最长递增子序列的长度 dp[1] = 1; for (int i =...原创 2022-03-22 22:18:28 · 302 阅读 · 0 评论 -
hdu2069_DP
#include <iostream>#include <string>#include <vector>#include <map>#include <set>#define x first#define y secondusing namespace std;typedef long long ll;const int COIN = 101;const int MONEY = 251;int type[5] = {...原创 2022-03-21 14:40:43 · 104 阅读 · 0 评论 -
力扣1094_差分
力扣https://leetcode-cn.com/problems/car-pooling/class Solution {public: bool carPooling(vector<vector<int>>& trips, int capacity) { int delta[1024] = { 0 }; // delta[j]保存第j站变化的人数 for (int i = 0; i < trips.size(); i原创 2022-03-10 15:55:55 · 216 阅读 · 0 评论 -
归并排序_逆序对
107. 超快速排序 - AcWing题库高质量的算法题库https://www.acwing.com/problem/content/description/109/#include <iostream>using namespace std;typedef long long ll;const int N = 1024000;ll a[N] = { 0 }, t[N] = { 0 }, cnt = 0;void Merge(ll start, ll mid, ll end)原创 2022-03-10 12:56:34 · 75 阅读 · 0 评论 -
树状数组的区间修改
3468 -- A Simple Problem with Integershttp://poj.org/problem?id=3468#include <iostream>#include <string>#include <vector>#include <map>#include <set>#define x first#define y secondusing namespace std;typedef long lo原创 2022-02-21 11:26:57 · 274 阅读 · 0 评论 -
poj2182_线段树(点修改)_树状数组
链接:2182 -- Lost Cowshttp://poj.org/problem?id=2182纯暴力:#include <iostream>#define x first#define y secondusing namespace std;typedef long long ll;const int N = 8004;int ans[N], a[N], pre[N];int main() { // system("chcp 65001"); ci.原创 2022-02-20 16:10:31 · 474 阅读 · 0 评论 -
IDA*_DFS
链接:3134 -- Power CalculusDescriptionStarting withxand repeatedly multiplying byx, we can computex31with thirty multiplications:x2=x×x,x3=x2×x,x4=x3×x, …,x31=x30×x.The operation of squaring can be appreciably shorten the...原创 2022-02-11 13:34:08 · 182 阅读 · 0 评论 -
埃氏筛_欧拉筛素数
单点时限:1.0 s内存限制:512 MB题目描述给出一个有个点的完全图,点的编号为,编号为的点之间的边权为。请求出这张图的最小生成树的代价。完全图:在图论的数学领域,完全图是一个简单的无向图,其中每对不同的顶点之间都恰连有一条边相连。:与的最小公倍数。最小生成树:一个有个结点的连通图的生成树是原图的极小连通子图,且包含原图中的所有个结点,并且有保持图连通的最少的边。最小生成树其实是最小权重生成树的简称。输入格式第一行一个整数,表示有...原创 2021-12-28 14:53:30 · 629 阅读 · 0 评论 -
3008跳格子_dp
单点时限:1.0 s内存限制:512 MB题目描述有个点,编号为,在秒时 c4Lnn 位于点,每秒 c4Lnn 都必须跳到其它点,即 c4Lnn 不能在同一点连续停留秒。求经过秒后,c4Lnn 停留在点的不同方案数。由于答案会很大,请输出答案对取模的结果。输入格式一行四个整数。输出格式一行,一个整数,表示不同方案数。样例input3133output3有以下种方案:#inclu...原创 2021-12-25 10:20:44 · 410 阅读 · 0 评论 -
浙大数据结构01-复杂度2 Maximum Subsequence Sum
Given a sequence ofKintegers {N1,N2, ...,NK}. A continuous subsequence is defined to be {Ni,Ni+1, ...,Nj} where1≤i≤j≤K. The Maximum Subsequence is the continuous subsequence which has the largest sum of its elements. For example, given seq...原创 2021-10-22 22:34:20 · 87 阅读 · 0 评论