随笔分类 -  算法

上一页 1 ··· 5 6 7 8 9 10 下一页
随手写的
摘要:https://www.acwing.com/problem/content/1247/ 简单模拟水题一道 #include<algorithm> #include<cstring> #include<iostream> #include<cstdio> using namespace std; i 阅读全文
posted @ 2022-10-05 10:53 风乐 阅读(18) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/1238/先用桶装有数的for(int i=1;i<=n;i++) cnt[a[i]]++;cnt[i]表示前i个数有数的,有就为1,无就为0再利用递推计算一下前缀和s[i]s[i]=cnt[0]+cnt[1]+cnt[2 阅读全文
posted @ 2022-10-04 18:55 风乐 阅读(252) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/1212/简答模拟水题一道要注意的是题目给的条件是1~N的排列,不会有重复数字,那么稍加思考即可有,若排列排序后递增,则有排列中的Max-Min+1=序列长度,如此充要条件则可判断此排列为递增区间 #include<bit 阅读全文
posted @ 2022-10-03 22:11 风乐 阅读(29) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/1216/ 定义f[i][j]为考虑前i个d,余数为j的count数需要注意的是,根据理解推得的公式,有多种等效形式我这里为n*x+1*d1+2*d2+3*d3+........+(n-1)*dn-1 + n*a;对于每一 阅读全文
posted @ 2022-10-03 18:23 风乐 阅读(29) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/description/1214/ 先说暴搜做法结果:会超时..能过三个点,但是是一种思路 #include<algorithm> #include<iostream> #include<iostream> #includ 阅读全文
posted @ 2022-09-28 21:13 风乐 阅读(36) 评论(0) 推荐(0)
摘要:最基础的最长上升子序列问题这里用的是dp做法定义f[i]为从1~i的所有上升子序列最大的长度双重循环,以a[i]为最后一个数,枚举所有小于a[i]的数a[j]作为序列的倒数第二个数,根据f[i]的定义,对于所有情况,最长子序列的长度即为f[i]=f[j]+1(f[j]为所有合法情况下的最大值) #i 阅读全文
posted @ 2022-09-27 23:51 风乐 阅读(25) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/description/1017/ #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> using namespace std 阅读全文
posted @ 2022-09-27 00:04 风乐 阅读(30) 评论(0) 推荐(0)
摘要:引用一下大佬的解答https://www.acwing.com/solution/content/1374/ 01背包问题这里是2023/2/26日更新的,因为发现之前的理解稍微有点绕新的:从集合的角度出发,题目要求用背包对每个物品进行选择装入,并且还要判断是否满足体积要求集合:每个物品都有装与不装 阅读全文
posted @ 2022-09-24 16:17 风乐 阅读(111) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/1218/ 大水题233 简单数理分析即可知 由n瓶饮料,可以产生n个瓶盖 , 又可以用n个瓶盖换取n/3(下取整)瓶饮料,如此反复换取,直至瓶盖不足3个为止 #include<cstdio> #include<algor 阅读全文
posted @ 2022-09-21 22:47 风乐 阅读(19) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/description/1213/ 脑经急转弯类型,主要要想出来的是两两相遇可以看成是小球无损碰撞,即[ 穿过 ],因为前后两者之间的状态一致 分析后总结,若不满足感染,则仅有初始蚂蚁1只 若满足感染条件则为left+ri 阅读全文
posted @ 2022-09-21 21:18 风乐 阅读(29) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/101/ #include<algorithm> #include<cstdio> #include<cstring> #include<iostream> using namespace std; const int N 阅读全文
posted @ 2022-09-08 11:48 风乐 阅读(29) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/798/ #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> using namespace std; int n, m, q 阅读全文
posted @ 2022-09-07 16:03 风乐 阅读(36) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/797/ #include<cstring> #include<algorithm> #include<cstdio> #include<iostream> using namespace std; const int N 阅读全文
posted @ 2022-09-07 10:49 风乐 阅读(25) 评论(0) 推荐(0)
摘要:https://www.acwing.com/problem/content/1229/ #include<cstdio> #include<algorithm> #include<cstring> #include<iostream> using namespace std; int n, k; 阅读全文
posted @ 2022-09-07 10:22 风乐 阅读(20) 评论(0) 推荐(0)
摘要:一道经典卡特兰数列题 P1044 [NOIP2003 普及组] 栈 卡特兰数列原理: 令h(1)=1,catalan 数满足递归式: h(n)= h(1)*h(n-1) + h(2)*h(n-2) + ... + h(n-1)h(1) (其中n>=2) 该递推关系的解为:h(n)=c(2n-2,n- 阅读全文
posted @ 2022-06-20 17:35 风乐 阅读(42) 评论(0) 推荐(0)
摘要:P1002 [NOIP2002 普及组] 过河卒 一道入门dp //二维数组dp #include<bits/stdc++.h> #define MAXN 22 using namespace std; long long f[MAXN][MAXN]; int ctrl[MAXN][MAXN],n, 阅读全文
posted @ 2022-06-19 11:30 风乐 阅读(30) 评论(0) 推荐(0)
摘要:二进制链表转整数 int getDecimalValue(ListNode* head) { int res=0,j=0; while(head) { res = (res << 1) + head->val; head=head->next; } return res; } 简单的位运算即可 阅读全文
posted @ 2022-06-11 09:58 风乐 阅读(35) 评论(0) 推荐(0)
摘要:数字三角形 #include<bits/stdc++.h> using namespace std; int r; int a[1005][1005]; int dp[1005][1005]; int main() { cin >> r; for(int i=1;i<=r;i++) for(int 阅读全文
posted @ 2022-06-09 18:53 风乐 阅读(41) 评论(0) 推荐(0)
摘要:function dfsTemplate(root) { //存储最终结果 let res; //初始化当前结果 let start; //构造递归函数dfs,通常参数为当前节点和当前结果 let dfs = function (node, currentResult) { //终止条件返回判断 i 阅读全文
posted @ 2022-05-29 16:25 风乐 阅读(111) 评论(0) 推荐(0)
摘要:快排 #include<iostream> #include<algorithm> using namespace std; int n,num[10005]; void qsort(int l,int r) { int i=l,j=r,flag=num[(i+r)/2]; while(i<=j) 阅读全文
posted @ 2022-05-29 15:54 风乐 阅读(27) 评论(0) 推荐(0)

上一页 1 ··· 5 6 7 8 9 10 下一页