算法与数学
学习记录
睡觉对我很重要
菜鸡一个
展开
-
图论(并查集 最小生成树 最短路径 关键路径)
并查集/** 并查集的应用**/#include<iostream>#include<cstdio>#include<string>#include<queue>#include<map>#define MAXN 1000int matrix[MAXN][MAXN]; // 定义距离int parent[MAXN]; // 其父亲节点using namespace std;void _init(){原创 2022-02-22 19:27:48 · 248 阅读 · 0 评论 -
高级数据结构 (树 , 队列 , 哈希表)
/*二叉树 相关:(1) 二叉的后序递归遍历(2)通过中序先序构造二叉树 */#include<iostream>#include<cstdio>#include<string>using namespace std;struct TreeNode{ char data; TreeNode * left; TreeNode *right;};void Visit(TreeNode* t){ cout<原创 2022-02-16 17:27:17 · 276 阅读 · 0 评论 -
搜索(深度与广度优先)
/*搜索 : 农夫约翰找牛的问题bfs*/#include<queue>#include<cstdio>#include<iostream>using namespace std;const int MAXN =10001;struct Status { int n ,t ; Status ( int n , int t) : n(n) ,t(t){}};bool visit[MAXN];int BFS( int n , int原创 2022-02-08 22:08:20 · 428 阅读 · 0 评论 -
贪心算法实例&随笔
问题一 : 背包问题 但是是允许并不将一个物品全部装满/*贪心问题 :这个问题与 01 背包问题的最大区别就是 并不是0 1*/#include<iostream>#include<vector>#include<stdio.h>#include<cstdio>#include<algorithm>using namespace std;struct JavaBean{ double weight; d原创 2022-02-06 22:12:08 · 428 阅读 · 0 评论 -
oj-三&随笔
随笔 :今天写项目的时候 解决了一个bug ,就是javaweb下载文件出现中文时候的乱码问题。在这里插入代码片 String filename= req.getParameter("filename"); ServletContext servletContext =this.getServletContext(); filename= new String(filename.getBytes("ISO-8859-1"),"UTF-8");...原创 2022-01-25 22:51:19 · 391 阅读 · 0 评论 -
oj笔记2(关于一些基本的数据结构)
栈的应用/*date : 1.17 括号匹配问题*/#include<iostream>#include<stack>#include<cstdio>#include<string>#include<cstring>using namespace std;stack<char>operator_stack;stack<char>result_stack;int main(){ string原创 2022-01-19 17:15:05 · 288 阅读 · 0 评论 -
oj笔记(关于一些遇到的问题)
stl–vector应用实例#include <iostream>#include<vector>#include<algorithm>using namespace std;vector<int> odd ;vector<int> even;bool _judge_odd( int a){ return (a%2==1);}void _print(){ for(int i=0; i<odd.size原创 2022-01-08 22:08:06 · 479 阅读 · 0 评论 -
最优加工顺序问题--贝尔曼规+回溯
通过贝尔曼规则得出以下的结论:(1)第一个机器加工时间越小加工顺序越前(2)第二个机器的加工时间越小加工顺序越后(3)第一个机器加工时间小于第二个的在前面(4)与(3)反之在后面// 回溯#include <iostream>#include <bits/stdc++.h>using namespace std;int t1, t2;int n;int x[10];int bestp;int bestx[10];int time[10][2];void原创 2021-02-04 21:59:04 · 944 阅读 · 0 评论 -
旅行商问题 (分枝定界)
#include <iostream>#include <bits/stdc++.h>using namespace std;int G[10][10];int bestp;int bestx[10];int n;//层数struct Node{ int weight; int level; int x[10]; Node() { memset(x, 0, sizeof(x)); } Node(原创 2021-01-27 19:34:53 · 139 阅读 · 0 评论 -
0 1 背包问题(回溯以及分枝定界)
0 1 背包问题就是一个整数规划问题。下面给出整数规划的求解步骤活结点集合选择一个分支节点拓展,如果是空的话原创 2021-01-10 14:56:19 · 314 阅读 · 0 评论 -
哈希表
#include <iostream>using namespace std;#define MAX 1000int hash[MAX];void init(int p){ for (int j = 0; j < p; j++) { hash[j] = -1; }}int flag;int main(){ int n, p; cin >> n >> p; int num; in原创 2020-09-05 13:23:41 · 110 阅读 · 0 评论 -
stl的sort理解应用
#include<bits/stdc++.h>using namespace std;const int maxn=1e5+5;struct stu{ int no; char name[10]; int score; }Node[maxn];bool cmp1(stu a, stu b){ return a.no <b.no;}bool cmp2(stu a, stu b){ if(strcmp(a.name,b.name) != 0) // 如果是相同的话原创 2020-08-06 15:41:59 · 101 阅读 · 0 评论 -
社交网络的节点计算(动态规划)
#include <iostream>#include <stdlib.h>using namespace std;int weight[10001][10001];int n, m;#define N 10000void init(){ for (int i = 1; i <= n; i++) { for (int j = 1; j <= n; j++) { if (i == j)原创 2020-08-05 22:38:12 · 334 阅读 · 0 评论 -
最短路径例子
#include<iostream>#include<stack>using namespace std;#define INF 0xffffff int n,m,c1,c2; int edge[510][510]; int weight[510]; int dist[510]; int num[510]; int w[510]; int s[510]; //存储已访问的点集int path[510];原创 2020-08-03 11:29:50 · 503 阅读 · 0 评论 -
自定义队列的例子
#include <iostream>#include <bits/stdc++.h>using namespace std;vector<int> adj[101];int in[101];void topsort(int n){ int *que; int next; que = new int[n + 1]; int font, real; int m; font = real = 0; for (原创 2020-08-01 21:41:52 · 96 阅读 · 0 评论 -
地下迷宫
#include <iostream>#include <bits/stdc++.h>using namespace std;#define N 1001int co=0;int flag;int flag2[2*N];int que[N][N];//数量int op[2*N];void print_tree(int start, int n){ flag2[start]=1; for (int j = 1; j <= n; j++)原创 2020-07-29 20:25:38 · 167 阅读 · 0 评论 -
目录树
/*参考文档:https://blog.csdn.net/qq_35440678/article/details/80147601 https://blog.csdn.net/qq_42623428/java/article/details/82961479*/#include <iostream>#include <string>#include <bits/stdc++.h>#include <cstring>using namespac原创 2020-07-27 21:42:20 · 138 阅读 · 0 评论 -
priority_queue 理解应用
/*priority_queue 理解应用https://blog.csdn.net/lyw_321/article/details/78069794*/#include <iostream>#include <queue>#include <cstdio>#include <string>using namespace std;struct node{ int weight; char s[11]; // 重载运原创 2020-07-25 18:37:23 · 69 阅读 · 0 评论 -
stl 中的 priority_queue
定义: priority_queue< Type, Container,Functional > ,即 ,数据类型,容器类型(默认是vector),比较的方法。默认是大顶堆// 升序priority_queue < int ,vector greater >q;// 降序priority_queue< int ,vector ,less < int > >q;#include<iostream>#include<queue>原创 2020-07-24 17:25:44 · 81 阅读 · 0 评论 -
树的练习
#include <iostream>#include <cstring>#include <vector>using namespace std;bool isMirror;vector<int> pre;vector<int> post;void dfs(int root, int tail){ if (root > tail) return; int i = root + 1; i原创 2020-07-22 09:26:09 · 105 阅读 · 0 评论 -
map小例子
#include <iostream>#include <map>#include <string>#include <cstring>using namespace std;map<string, int> StringToint;char p[10][11];int spaces[10];//定义空格数量bool x_child_y(int x, int y){ // x是不是y的 孩子 if (spaces[x] -原创 2020-07-20 16:11:04 · 210 阅读 · 0 评论 -
并查集应用
#include <iostream>using namespace std;#define N 3000#define M 3000int root[N];int result[M];void init(int n){ for (int i = 1; i <= n; i++) { root[i] = i; // 初始化 }}int getroot(int k){ if (root[k] != k)原创 2020-07-16 23:02:43 · 74 阅读 · 0 评论 -
树种统计
/** 树种统计 map 用法:https://www.cnblogs.com/fnlingnzb-learner/p/5833051.html*/#include<iostream>#include<map>#include<string>using namespace std;int main(){//map<string,int> str;map<string,int>::iterator it;int n;s原创 2020-07-15 16:14:02 · 292 阅读 · 0 评论 -
计算前缀表达式的值
/** 参考(https://blog.csdn.net/qq_42325947/java/article/details/104219251)*/#include <iostream>#include <stack>#include <string>using namespace std;stack <double> st;int main(){ string s; getline(cin, s); for (int i = s.s原创 2020-07-15 11:56:32 · 257 阅读 · 0 评论 -
表达式转换
#include<stack>#include <stdio.h>#include <stdlib.h>#include <string.h> #include<iostream> using namespace std;stack<char> op;int flag;int main(){ char stack[50]; char str[50]; scanf("%s", str); i原创 2020-07-12 10:46:25 · 127 阅读 · 0 评论 -
Floyd算法
/** date : 2020 .7.9* theme : floyd算法(1) 弗洛伊德算法的最外层k保证顺序即可(2) 弗洛伊德算法是基本的动态规划思想,所作的是不断的更新i j 之间的距离 ,所有的节点都要被修改,最后才是正确的,因此如果是计算一个特定的点的话,并不推荐 时间复杂度在o(n三次方), 可以考虑结合vector一起使用。 */#include <iostream>#define N 10#define INF 100int p[N][N];int p1原创 2020-07-09 16:37:16 · 85 阅读 · 0 评论 -
7-31 笛卡尔树的判断
这个主要是对二叉树的遍历,并不困难/** data :2020.7.8 * theme:路径 */#include <iostream>#include <cstdlib>using namespace std;#define N 1005int judge[N];int cont = 0;struct node{ int k1; int k2; int left; int right; int parent;};s原创 2020-07-09 08:15:47 · 176 阅读 · 0 评论 -
新冠肺炎SEIR模型(修正版)
初始模型 seir模型clear;clc;N=1400000000;I=1;R=0;D=0; E=0;S=N-I;r=5;r11=0;a=0.11;B=0.05;B1=0.04;count=0;y=0.02;r2=15;k=0.025373;T=20:1000;for idx =1:length(T)-1 if(idx>=25) r=1; r2=1; B=0.01; y=0.6;原创 2020-06-22 16:46:32 · 13726 阅读 · 9 评论 -
欧拉回路的判断
定理无向图G具有一个欧拉路,当且仅当G是连通的,并且有0个或者是2个奇数度节点。定理简要证明必要性:可以先将G的节点、路径编号。记为v1,v2,v3,...vnv_{1},v_2,v_3,...v_nv1,v2,v3,...vn ,e1,e2,...,ene_1,e_2,...,e_ne1,e2,...,en假设G具有欧拉路,那么G必然是连通的,不妨假设从v1,e1v_1,...原创 2020-04-30 16:31:23 · 413 阅读 · 0 评论 -
线性规划与整数规划小结
线性规划1 线性规划问题 以及可行域与基本可行解(1)一般形式 :minZminZminZ =C1C_1C1X1X_1X1+ C2C_2C2X2X_2X2+C3C_3C3X3X_3X3+…+CnC_nCnXnX_nXna11a_{11}a11x1x_1x1+a12a_{12}a12x2x_2x2+a13a_{13}a13x3x_3x3+…+a1na_{1n}a1...原创 2020-04-16 17:26:29 · 3849 阅读 · 1 评论 -
关键路径
#include<iostream>using namespace std;#define N 100#define INF 1000int G[N][N];//记录时间int wantime[N];//最早发生时间int zaotime[N];//最晚发生时间int in[N];// 入度int out[N];//出度void make( int n ){fo...原创 2020-04-12 22:08:53 · 80 阅读 · 0 评论 -
Dijkstra--vector实现
//使用vector 实现Dijkstra算法#include<iostream>#include<vector>#define N 501#define INF 1000using namespace std;struct node {int next;int cost ;int dis;};vector<node> mynode[50...原创 2020-04-11 12:02:18 · 395 阅读 · 0 评论