- 博客(36)
- 收藏
- 关注
原创 算法笔记第九章 树
根据树的后序遍历与中序遍历求解树的层序遍历。代码如下:#define _CRT_SECURE_NO_WARNINGS#include<cstdio>#include<queue>#include<algorithm>#include<cstring>using namespace std;const int maxn = 100;int a[maxn], b[maxn];int N;struct node { int data; n.
2021-12-18 12:18:16
560
原创 第八章搜索
1.DFS深度优先搜索(由栈实现):#define _CRT_SECURE_NO_WARNINGS#include<cstdio>#include<vector>#include<iostream>const int maxn = 10010;int n,k,x,maxsumsqr=-1,A[maxn];using namespace std;vector<int> ans, temp;void DFS(int index, int now
2021-12-13 19:24:04
545
原创 算法笔记第六章 C++STL
容器的end()方法,返回一个迭代器,需要注意:这个迭代器不指向实际的元素,而是表示末端元素的下一个元素,这个迭代器起一个哨兵的作用,表示已经处理完所有的元素。1.vector[ ] 迭代器vector::iterator it; it就是一个迭代器,可将其赋值为vi.begin();是指针[ ] push_back()在vector后加一个元素[ ] pop_back()在vector最后删除一个元素[ ] size()返回vector的元素个数[ ] clear()清楚vector中的所有元
2021-11-21 20:52:20
725
原创 算法笔记区间贪心
#define _CRT_SECURE_NO_WARNINGS#include<cstdio>#include<algorithm>using namespace std;struct zuobiao { int x; int y;}zuo[100];bool cmp(zuobiao x, zuobiao y) { if (x.x != y.x) { return x.x > y.x; } else { return x.y < y.y;.
2021-10-26 16:00:06
94
原创 算法笔记第四章递归
全排列问题:实现C代码:#define _CRT_SECURE_NO_WARNINGS#include<cstdio>int n;int p[100];int hashtable[100] = {false};void generatep(int index) { if (index==n+1) { for (int i = 1; i <= n; i++) { printf("%d", p[i]); } printf("\n"); } for (i
2021-10-25 16:29:33
78
原创 算法笔记散列hash
实现C代码如下:#define _CRT_SECURE_NO_WARNINGS#include<cstdio>#include<cstring>int hashtable[26*26*26+10];int hashfunc(char c[],int len) { int id = 0; for (int i = 0; i < len; i++) { id = id * 26 + (c[i] - 'A'); } return id;}int main..
2021-10-23 18:19:32
74
原创 算法笔记第四章排序
使用sort()函数进行排序时,输入的参数为排序开始的地址与结束地址的后一位。要algortthm头文件,并且using namespace std
2021-10-23 13:39:27
83
原创 算法笔记第三章(2)
漏了一道题:实现C代码:#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>void ret(int a[], int k,int n) { int flag = -1; for (int i = 0; i < n; i++) { if (a[i] == k) { printf("%d", i); flag = 1; break; } } if (flag == -1) { printf("%d",
2021-10-19 20:26:45
100
原创 算法笔记练习第三章(1)
卡拉兹猜想实现C代码:#define _CRT_SECURE_NO_WARNINGS#include<stdio.h>int callatz(int x){ int count = 0; while (x != 1) { if (x % 2 == 0) { x = x / 2; } else { x = (3 * x + 1) /2; } count += 1; } return count;}int main() { int x,flag
2021-10-16 19:42:16
87
原创 Python错题
Python里的/不是整除!!!!将Python中的数值进行按位分割时可以用字符串的形式并结合eval,使程序更加简单else不与if对齐可以使第二层循环结束再判断条件,适合求素数等...
2020-03-15 09:57:07
144
原创 高数错题
求一个点关于一平面的对称点,先求出这个平面的法向量,并将其转换为参数方程,代入平面方程式求出交点,并通过中点坐标公式算出对称点。给出直线的一般式可以通过运算向量积来得到直线的方向向量。要判断两直线是否相交可以联立直线的一般方程,若有唯一解则两直线相交。求点到直线的距离,经过点做一个平面垂直与直线再求出交点,两点间的距离即为点到直线的距离。直线的方向向量可以通过向量积的方式计算出来。在某一...
2020-03-12 20:36:46
1097
原创 学Python日常
endswith函数Python rstrip()方法Python isupper()方法Python capitalize()方法Python title()方法Python ljust()方法Python rjust()方法Python replace()方法Python zfill()方法Python rpartition() 方法Python partition()...
2020-03-09 15:55:42
104
原创 学python日常
Python PyInstaller安装和使用教程Python PyInstaller安装和使用教程range在使用【】后就无需再在之前加上range
2020-02-29 18:57:15
61
原创 学习日常
和差化积公式sin α+sinβ=2sin[(α+β)/2]·cos[(α-β)/2]sin α-sin β=2cos[(α+β)/2]·sin[(α-β)/2]cos α+cos β=2cos[(α+β)/2]·cos[(α-β)/2]cos α-cos β=-2sin[(α+β)/2]·sin[(α-β)/2]和差化积公式sinαsinβ=-[cos(α+β)-cos(α-β)]...
2020-02-26 20:49:03
96
原创 日常
混合使用getchar()函数与scanf()函数的注意点getchar()不会跳过空格、制表符、换行符而scanf()会。输入验证使用putchar()函数将要求输入整数的程序的错误输入字符打印出来...
2020-02-14 20:01:56
87
原创 日常
接受正整数输入并输出小于等于该数的全部素数#include<stdio.h>int qiusushu(int shuru);int main(void){ int shuru,n,i; printf("请输入一个正整数:"); while(scanf("%d",&shuru)) { if(shuru<=0) { printf("\n请输入正确...
2020-02-13 19:35:14
83
原创 日常
今天写了一个小人工智障代码#include<stdio.h>#include<string.h>#define bei 1.5#define qian 0.15#define xu 0.20#define yu 0.25void hanshu1(int time);void hanshu2(int time);void hanshu3(int time)...
2020-02-12 19:30:53
104
原创 日常
switch运用switch函数的时候最好在case语句后加一个break,不然的话程序就会从满足条件的那一条开始把后面的所有case都执行一遍。
2020-02-11 19:47:55
99
原创 日常
设计程序计算输入的字符数,单词数与行数。代码#include<stdio.h>#include<ctype.h>#include<stdbool.h>#define stop '|'int main(void){ int duanju,prev; char ch; int zifushu=0,hangshu=0,dancishu=0; ...
2020-02-09 18:06:22
92
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人