![](https://img-blog.csdnimg.cn/20201014180756927.png?x-oss-process=image/resize,m_fixed,h_64,w_64)
算法
文章平均质量分 55
ZehMin_Ho
热爱学习,热爱生活
展开
-
每日学习小记
map与unordered_map的差别:前者是一个由红黑树实现,具有排序功能,而且有非严谨的平衡功能,而后者则是通过hash去实现的,单纯的需要查询功能,用后者能快不少,而前者由于红黑树的结构,每个节点还需要存储他的父亲节点,和它的颜色,要增加空间复杂度。...原创 2020-05-07 10:20:36 · 103 阅读 · 0 评论 -
关于有向负权图 p1807
有两种方案:①bellman_ford ②bellman_ford的优化算法spfa直接放代码①#include <iostream>using namespace std;struct edge{ int x, y, w;}es[50010];int distence[1510];//bellman_ford这个算法其实有点类似于Floyd算法...原创 2020-04-24 14:59:17 · 266 阅读 · 0 评论 -
洛谷 p1044 dp 栈
#include <iostream>#include <cstdio>using namespace std;int main(){ int i, j; int n; cin >> n; long long c[20][20];//c[i][j]即出栈i个,进栈j个 for (j = 0; j <= n...原创 2020-03-31 16:33:10 · 169 阅读 · 1 评论 -
大量数字数据的读入技巧 快速读入
inline int read()//这是一个读入数字的快读{ int x=0,f=1; char ch=getchar(); while(ch<'0'||ch>'9'){ if(ch=='-') f=-1; ch=getchar(); } while(ch>='0'&&a...原创 2020-03-24 09:22:59 · 615 阅读 · 0 评论 -
洛谷 关于p1433
关于这个题目,第一时间我想到的是深度优先搜索,但是最后一个点产生了TLE,贴上代码#include <iostream>#include <cmath>#include <iomanip>using namespace std;int n;double point[16][2] = { 0 };int visited[16];doub...原创 2020-03-20 16:47:28 · 163 阅读 · 0 评论 -
洛谷p1162 bfs
#include <iostream>#include <queue>using namespace std;int map[40][40] = {0};//0代表未染色,1代表染色了,3代表边界外染色int n;struct node { int x; int y;}n1;queue<node> q;void bfs(int...原创 2020-03-17 09:31:41 · 122 阅读 · 0 评论 -
洛谷 p1080 国王游戏 高精度问题
先上代码!#include <iostream>#include <algorithm>#include <cstdio>#include <cstring>using namespace std;FILE* stream;struct p{ int l; int r; int l_r;}ps[1000000];b...原创 2020-03-13 11:43:36 · 198 阅读 · 0 评论 -
洛谷历险记 p1059
其实这个题目很简单,主要是我用的方法比较有意思#include <iostream>#include <string>#include <cmath>#include <algorithm>#include <set>using namespace std;int main() { int N; cin >...原创 2020-03-08 15:50:42 · 67 阅读 · 0 评论 -
洛谷历险记 p1086 sort函数用法
#include <iostream>#include <string>#include <cmath>#include <algorithm>using namespace std;struct node{ int row; int column; int peanuts;}a[500];bool cmp(node...原创 2020-03-06 11:42:17 · 105 阅读 · 0 评论 -
洛谷历险记 p1031 贪心算法
#include <iostream>#include <algorithm>#include <queue>using namespace std;int main() { int n; int a[10000]; int ans = 0; int avg; int sum = 0; cin >> n; for (...原创 2020-03-05 11:33:38 · 131 阅读 · 0 评论 -
洛谷历险记p1540 queue的使用
#include <iostream>#include <queue>using namespace std;#define sign(a){a>0 ? 1:-1}int main() { int m, n; int temp; bool flag = false; int count = 0; cin >> m >>...原创 2020-03-04 08:52:55 · 180 阅读 · 0 评论 -
洛谷p1464
宏定义函数习得!其实宏定义函数就相当于简单的替换。#define W_MEN(a,b,c)(w_men[a][b][c] ? w_men[a][b][c]:w_men[a][b][c]=w(a,b,c))其实当return W_MEN(a,b,c)时就相当于returnw_men[a][b][c] ? w_men[a][b][c]:w_men[a][b][c]=w(a,b,c)...原创 2020-03-02 07:37:57 · 172 阅读 · 0 评论 -
洛谷p2089
毫无疑问,又是一个dfs,不过这次要求将方案先输出,最后再输出方案个数,那我就要找个东西存我的方案,由于是10位的,且开始可能为3,那么就没办法用int数组来存了,我的话做了字符数组来存,由于3的10次方是5900多,即有5900多种搭配,所以我初始化了一个大小为100000的char数组,上代码。#include <iostream>#include <string...原创 2020-02-27 09:02:39 · 260 阅读 · 0 评论 -
洛谷p1579 +线性筛法(欧拉筛法)的个人理解
先上题目:一般而言,对于求质数,素数,有三种方法(~~抱歉,是我只知道三种~~)①首先!最简单的是,对一个数从2到其平方跟,检测是否能够整除,均不能被整除,素数出现!bool prime(int x){ for (int j=2;j<=sqrt(x);j++) if (x%j==0) return false; return true;}②其...原创 2020-02-26 10:59:44 · 604 阅读 · 0 评论 -
洛谷历险记3
p1028:题目提示使用递归做的,代码如下void dfs(int num) { if (num == 0) { sum++; return; } int temp = num / 2; while (temp>-1) { dfs(temp); temp--; }}但是,这段代码会导致超时,原因是其时间复杂度为0(N^2),而且并没有复用其中的...原创 2020-02-25 10:46:41 · 73 阅读 · 0 评论 -
洛谷历险记2
遇到一个有意思的题目P1008,先贴代码#include <iostream>#include <cmath>#include <iomanip>using namespace std;int result[9];int used[9];void test() { int num1 = result[0] * 100 + result...原创 2020-02-22 18:25:55 · 104 阅读 · 1 评论 -
洛谷历险记1(小数精确问题)
p1422关于精度问题:要求最后的取值要精确到小数点后一位。 //fea = ((int)((fea * 10) + 5 ))/10.0; 错误示范 fea = int((fea * 10) + 0.5) / 10.0;注释的一行是错误的代码分析:例如最后得到的是一个1.05的double类型,1.05*10=10.5,再加5则影响了小数点后一位的精度,实则应该在小数点后的第...原创 2020-02-22 15:40:30 · 142 阅读 · 0 评论 -
算法第四版学习(chapter1.3)
前几天,回了老家,怠惰了几天,把云图看了,还看了一季的King of the hill ,简直爽爆,回来了,又要开始学习了,今天我们来学习几种极为常见的数据结构,分别是背包、队列还有栈。1.3.1:知识点:泛型:在java中,我们可以规定集合类型的一个关键属性,像这样(Bag<pig> bag=new Bag<pig>),那么这个包就只能往里放pig类型的对象,...原创 2018-08-20 21:58:03 · 363 阅读 · 0 评论 -
算法第四版学习(chapter1.4)part1
马上开始今天的学习,今天的内容是算法分析,算法的一个评估环节,当我们在设计、使用一个算法的时候,一个算法的好坏往往与它的运行时间(时间复杂度),运行所需空间(空间复杂度)挂钩,首先来学习时间复杂度问题。 书中一开始提到一个例子,讲的是计算从数组中抽取三个数,统计三个数加起来等于0的个例,然后进行返回。文章之中给出的ThreeSum,典型的暴力算法,逐个遍历,在P112,我遇到了...原创 2018-08-22 21:15:41 · 990 阅读 · 0 评论 -
算法第四版学习(chapter1.2)
话不多说,开始今天的学习,今天来到数据抽象这一章节,果然算法这本书,真的非常适合算法初学者,在java语言中,数据抽象即将数据视为某种对象,能很好的,更直观的的处理自己的数据。 首先来整理一下核心知识点: 1.2.1: ①为什么我们要使用抽象数据类型呢:这有一部分就是java封装的思想,你不需要知道我内部是怎么实现的,我给你相应的API...原创 2018-08-06 20:41:10 · 339 阅读 · 0 评论 -
算法第四版学习(chapter1.1)
这是我个人真正意义上的第一篇blog,今天我来讲一下,我在这个暑假学习的一本书,算法(第四版)。 第一章主要讲述了一些标准工具的用法,这本书提供了一个标准库,我们可以在他的网上下载下来,或者我这里也可以链接: https://pan.baidu.com/s/1Y89qdn5SWQ3KQfiF08ruPw 密码: xsc7我所遇到的难题:1.1.25:使用数学归纳法证明欧几里得算...原创 2018-08-01 23:26:58 · 724 阅读 · 0 评论