
学习笔记
淋雨的蜗牛
这个作者很懒,什么都没留下…
展开
-
STL 二分查找
STL 二分查找用法一(从小到大排序)binary_search(数组名+n1, 数组名+n2, 要查找的值);用法二自定义排序binary_search(数组名+n1, 数组名+n2, 要查找的值,排序规则结构名() );lower _bound ( 查找下界) 用法一T * lower_bound(数组名+n1, 数组名+n2, 值 )大于等于这个数的第一个位置用法二 (自定...原创 2019-07-23 21:09:24 · 228 阅读 · 0 评论 -
关于三分的学习
借鉴优秀的博客关于三分的解释练习题目曲线题解#include<cstdio>#include<algorithm>#include<string>using namespace std;int n;double a[100005], b[100005], c[100005];double check(double x){ double ...原创 2019-08-07 18:59:48 · 168 阅读 · 0 评论 -
关于二分的学习
借鉴的优秀博客关于二分的解释:练习题目:愤怒的牛题解#include<cstdio>#include<cstring>#include<algorithm>using namespace std;int a[100005], n, m;bool check(int x){ int cow = 1; int sum = a[1] + x...原创 2019-08-07 18:48:32 · 169 阅读 · 0 评论 -
动态规划(一)
例题:数字三角形类似于如图的数字三角形寻找一条从顶部到底部的路径,使得路径所经过的数字和最大。 每一步只能往左下或者右下走。只需求出最大和,不必给出路径。代码#include<iostream>#include<algorithm>using namespace std;#define MAX 105int maxsum[MAX][MAX], d[MAX]...原创 2019-08-01 21:10:51 · 145 阅读 · 0 评论 -
关于树的习题
1. 给出一组数的 中序遍历 和 先序遍历 求->后序遍历例如 void solve (int preL, int inL, int postL, int n){ // 先序遍历 中序遍历 后序遍历 总数 if(n == 0) return 0; if(n == 1) post[postL] = pre[preL]; root = pre[preL]; // 先序遍历第...原创 2019-07-26 20:38:19 · 291 阅读 · 0 评论 -
图的遍历 (深度优先搜索 广度优先搜索)
如图所示 将每一盏灯熄灭采用深度优先搜索类似于树的先序遍历void DFS(Vertex V){ Visited [V] = true; // 给每一盏灯做上标记 for(V 的每个邻接点W) if(!=Visited[W]) // 如果没有被标记 DFS(W); // 递归 进行标记 } 广度优先搜索 void BFS(Vertex V){ Visit...原创 2019-07-26 19:12:44 · 433 阅读 · 0 评论 -
C++中map基本操作函数
map的基本操作函数begin( ) 返回指向map头部的迭代器clear( ) 删除所有元素count( ) 返回指定元素出现的次数empty( ) 如果map为空则返回trueend( ) 返回指向map末尾的迭代器equal_range( ) 返回特殊条目的迭代器对erase( ) ...原创 2019-07-31 15:24:55 · 714 阅读 · 0 评论 -
UVa11572 唯一的雪花
左端点为L 右端点为R#include<cstdio>#include<set>#include<algorithm>using namespace std;const int maxn = 1000000 + 5;int A[maxn];int main() { int T, n; scanf("%d", &T); whi...原创 2019-07-31 14:58:33 · 166 阅读 · 0 评论 -
C++中set 的用法
set的各成员函数列表如下:1. begin( )–返回指向第一个元素的迭代器2. clear( )–清除所有元素3. count( )–返回某个值元素的个数4. empty( )–如果集合为空,返回true5. end( )–返回指向最后一个元素的迭代器6. equal_range( )–返回集合中与给定值相等的上下限的两个迭代器7. erase( )–删除集合中的元素8. fi...原创 2019-07-31 14:51:15 · 957 阅读 · 0 评论 -
UVa11054 Gergovia的酒交易
#include<iostream>#include<algorithm>using namespace std;int main() { int n; while(cin >> n && n) { long long ans = 0, a, last = 0; for(int i = 0; i < n; i...原创 2019-07-31 13:34:21 · 321 阅读 · 0 评论 -
使用函数判断完全平方数
#include<stdio.h>#include<math.h>int IsSquare(int n){ int a;if(sqrt(n)==(int)sqrt(n))//判断是否为完全平方数return a;//是 返回aelsereturn 0;}int main(){int n,a;scanf("%d",&n);if(a)//如果是...原创 2018-11-09 13:19:01 · 10812 阅读 · 1 评论 -
max_element
举例输入 三个数 可发现 max_element 可以找得到最大值的下标同理min_element 是找最小值的代码#include<iostream>#include<algorithm>using namespace std;int main(){ int a[10]; for(int i = 0; i < 3; i++){ cin ...原创 2019-07-30 21:22:40 · 185 阅读 · 0 评论 -
stringstream ss()
#include<iostream>#include<string>#include<sstream>using namespace std;int main(){ string line; while(getline(cin, line)) { int sum = 0, x; stringstream ss(line); // 将...原创 2019-07-30 19:46:26 · 5367 阅读 · 2 评论 -
回溯法
模板伪代码void search(int cur){ if(递归边界){ for(int i = 0; i < n; i++) printf(打印); } else for(尝试放置每一个数 i ) if(判断是否被标记过){ A[cur] = i; 标记 = 1 递归搜索 清除 = 0 } }...原创 2019-07-30 16:20:13 · 161 阅读 · 0 评论 -
7.3子集生成
method 1 增量构造法思路: 一次选出一个元素放到集合中代码://A表示原集合 //B表示子集和 //N表示原集合个数 //cur表示当前子集和个数 #include<cstdio>using namespace std;void print_subset(int *A, int *B, int N, int cur){ for(int i = 0; i ...原创 2019-07-29 20:56:34 · 154 阅读 · 0 评论 -
二叉搜索树
什么是二叉搜索树?也称二叉排序树或二叉查找树一颗二叉树可以为空,如果不为空 满足以下性质①左子树所有键值小于根结点的键值②右子树所有键值大于根结点的键值③左、右子树都是二叉搜索树二叉树的查找操作 Find和根结点 x 比较小于 x 继续在左子树中搜索大于 x 继续在右子树中搜索等于 x 搜索完成返回此结点的指针Position IterFind(ElementType X, ...原创 2019-07-24 20:23:21 · 247 阅读 · 0 评论 -
二叉树的遍历
递归遍历1.先序遍历过程① 访问根节点② 先序遍历左子树③ 先序遍历右子树 void PreOrdeTraversal( BinTree BT){ if(BT){ printf("%d", BT->Data); PreOrdeTraversal(BT->Left); PreOrdeTraversal(BT->Right); } }2.后...原创 2019-07-24 16:27:08 · 290 阅读 · 0 评论 -
四种“排序容器” **multiset set multimap map**
STL 中的平衡二叉树四种“排序容器”multiset set multimap map①multiset st; T为数据类型st.insert 插入元素st.find 查找元素st.rease 删除元素代码解释:#include<iostream>#include<cstring>#include<set> using na...原创 2019-07-23 21:28:11 · 156 阅读 · 0 评论 -
排序(冒泡、插入、希尔、堆、归并)
初始各元素的位置将最大的元素调整到最下面,然后继续调整剩下的伪代码:void Heap_Sort(ElementType A[], int N){ for(int i = N/2; i >= 0; i--) // 建立最大堆 PercDown(A, i, N);// 向下过滤的子函数 i->根结点所在的位置 N->当前这个堆一共有多少元素 for(i...原创 2019-08-12 20:23:59 · 141 阅读 · 0 评论