算法
收录常见算法
Cyber苦行者
这个作者很懒,什么都没留下…
展开
-
图论
存图方式 // // Created by lanfear on 2021/2/18. // const int N = 1e5; // 1. adjacent matrix ******************************************************************* int graph[N][N]; // 2. adjacency list (array) ***********************************************..原创 2021-03-14 11:59:48 · 146 阅读 · 0 评论 -
深度优先搜索
A-P2036 [COCI2008-2009#2] PERKET #include<bits/stdc++.h> using namespace std; const int N = 50; const int INF = 0x3f3f3f3f; int n,ans = INF; int acid[N],sweet[N]; void DFS(int i,int x,int y){ if(i > n){ if(x == 1 && y == 0)return;原创 2020-05-23 21:21:22 · 275 阅读 · 0 评论 -
宽度优先搜索
第一个真正意义上的BFS 注意点:方向数组初始化不能用小括号!!! #include<bits/stdc++.h> using namespace std; const int N = 500; int ans[N][N]; int n,m,x,y; int dir[][2] = {{1,-2},{2,-1},{2,1},{1,2},{-1,2},{-2,1},{-2,-1},{-1,-2}};//奇怪!!!!! //为什么一定要用中括号括起来 struct node{ int x;原创 2020-05-20 12:29:11 · 181 阅读 · 0 评论 -
暴力枚举类型题小结
A. P2241 统计方形(数据加强版) #include<bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define ms(a,b) memset(a,b,sizeof(a)) #define rush() int T;cin>>T;while(T--) #define ll long long //找规律....... using namespace原创 2020-05-28 15:51:28 · 401 阅读 · 0 评论 -
贪心类型题小结
A. 最小硬币问题 #include<iostream> using namespace std; const int NUM = 3; const int Value[NUM] = {1,2,5}; int main(){ int i,money; int ans[NUM] = {0}; cin>>money; for(i = NUM - 1;i >= 0;i--){ ans[i] = money / Value[i]; money -= ans[i] * V原创 2020-05-28 16:01:43 · 244 阅读 · 0 评论 -
二分类型题小结
(以下题目均来自洛谷LUOGU) A.P2249 【深基13.例1】查找(入门) #include<bits/stdc++.h> #define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0); #define ms(a,b) memset(a,b,sizeof(a)) #define MP make_pair #define rush() int T;cin>>T;while(T--) #define原创 2020-06-03 15:10:58 · 172 阅读 · 0 评论