- 博客(27)
- 资源 (1)
- 收藏
- 关注
原创 18_最长公共子串
#include <algorithm>#include <cstdio>#include <cstring>#include <iostream>using namespace std;const int MAXI = 1e4;int dp[MAXI][MAXI];int LCS(char* s1, char* s2){ int ans = 0; for (int i = 1; i <= strlen(s1); i++
2021-12-11 18:55:08
262
原创 17_最长公共子序列
#include <algorithm>#include <cstdio>#include <cstring>#include <iostream>using namespace std;const int MAXI = 1e4;int dp[MAXI][MAXI];void LCS(char* s1, char* s2){ for (int i = 1; i <= strlen(s1); i++) for (i
2021-12-11 17:04:31
155
原创 16_归并排序
#include <algorithm>#include <cstdio>#include <cstring>#include <iostream>using namespace std;const int MAXI = 1e4;void merge(int* array, int low, int mid, int high){ if (low >= high) { return; } int*
2021-12-11 16:21:03
81
原创 15_二分查找
#include <stdio.h>#include <stdlib.h>const int MAXN = 1e4;int array[MAXN];int binarySearch(int *arr, int key, int length) { int left = 0; //左边界 int right = length - 1; //右边界 while (left <= right) { int middle = (left + right) / 2;
2021-12-07 21:34:49
80
原创 14_斐波那契数列的非递归写法
#include <stdio.h>#include <stdlib.h>typedef long long ll;const int MAXN = 1e4;ll a[MAXN];void get_Fibonacci(ll n) { for (int i = 0; i < MAXN; i++) { if (i <= 1) a[i] = 1; else a[i] = a[i - 1] + a[i - 2]; }}int main() { ge
2021-12-07 16:39:08
236
原创 13_斐波那契数列的递归写法
#include <stdio.h>#include <stdlib.h>typedef long long ll;ll Fibonacci(ll n) { if (n <= 1) return 1; return Fibonacci(n - 1) + Fibonacci(n - 2);}int main() { ll n; printf("你要斐波那契数列的第几项?\n"); scanf("%lld", &n); printf("%lld",
2021-12-07 16:34:40
114
原创 12_Hanio(汉诺塔)
#include <stdio.h>#include <stdlib.h>void move(char no, char from, char to) { printf("将 %d 号盘子从 %c 移动到 %c\n", no, from, to);}void hanoi(int n, char p1, char p2, char p3) { if (n == 1) {//只有一层的情况 move(n, p1, p3); return; } //将p3看作中
2021-12-07 16:21:06
112
原创 11_普通快速排序
#include <stdio.h>#include <stdlib.h>#define MAXZISE 100#define ElemType intint Partition(ElemType A[], int low, int high){ ElemType pivot = A[low]; while (low < high) { while (low < high && A[high] >= piv
2021-12-05 10:48:15
406
原创 10_优化KMP算法
/*** @Author: 郑潮安yyds* @Time: 2021/12/2 22:15.* @Filename: Kmp.cpp * @Software: CLion*/#include <iostream>#include <cstring>#define MaxSize 1000using namespace std;typedef struct { char data[MaxSize]; int length; /
2021-12-03 14:41:04
110
原创 9_普通KMP算法
/*** @Author: 郑潮安yyds* @Time: 2021/12/2 22:15.* @Filename: Kmp.cpp * @Software: CLion*/#include <iostream>#include <cstring>#define MaxSize 1000using namespace std;typedef struct { char data[MaxSize]; int length; /
2021-12-03 14:06:33
86
原创 8_Floyd算法
/*** @Author: 郑潮安yyds* @Time: 2021/12/2 18:47.* @Filename: Floyd.cpp* @Software: CLion*/#include <stdio.h>#include <stdlib.h>#define MAXN 100#define INF 0x3f3f3f3ftypedef struct struct_graph { char vexs[MAXN]; int vexnum;//顶
2021-12-02 21:36:33
111
原创 7_Dijkstra算法
/*** @Author: 郑潮安yyds* @Time: 2021/12/2 18:47.* @Filename: Dijkstra.cpp * @Software: CLion*/#include<queue>#include<iostream>#include<algorithm>#include <cstring>using namespace std;const int N = 100;//城市的个数可修改const int
2021-12-02 19:18:27
800
原创 6_Kruskal算法
/*** @Author: 郑潮安yyds* @Time: 2021/12/2 16:30.* @Filename: union_find_set.cpp * @Software: CLion*/#include<bits/stdc++.h>using namespace std;const int MAXN = 1060;int n, m, conedEdge, sumLength, s[MAXN], height[MAXN];int usedEdgeIndex[MAX
2021-12-02 18:19:48
103
原创 5_Prim算法
/*** @Author: 郑潮安yyds* @Time: 2021/12/2 15:24.* @Filename: Prim.cpp * @Software: CLion*///最小生成树——Prime//邻接矩阵 无向图/**邮箱:unique_powerhouse@qq.com*blog:https://me.youkuaiyun.com/hzf0701*注:文章若有任何问题请私信我或评论区留言,谢谢支持。**/#include<bits/stdc++.h> //
2021-12-02 16:24:34
132
原创 常用代码模板系列文章目录
文章目录0、文件输入1、高精度加2、高精度乘3、快读0、文件输入freopen("C:\\Users\\30414\\Desktop\\洛谷新生\\input.in","r",stdin);1、高精度加#include <cstring>#include <iostream>using namespace std;char aa[64], bb[64], cc[64];int a[64], b[64], c[64];int ans[64 * 3];int add
2021-11-30 15:51:39
157
原创 4_输入快读
int read(){//快读 int x=0,f=1; char c=getchar(); while(c<'0'||c>'9'){ if(c=='-') f=-1; c=getchar(); } while(c>='0'&&c<='9'){ x=x*10+c-'0'; c=getchar(); } return x*f;}
2021-11-30 15:33:16
112
原创 2_高精度加
//高精度加#include <cstring>#include <iostream>using namespace std;char aa[64], bb[64], cc[64];int a[64], b[64], c[64];int ans[64 * 3];int add() { int len_a = strlen(aa); int len_b = strlen(bb); int len_c = strlen(cc); int tt
2021-11-30 15:31:44
128
原创 3_高精度乘
// 高精度乘法#include <iostream>#include <string>#define N 1000using namespace std;int main() { char num1[N]; char num2[N]; int data1[N]; int data2[N]; int result[N * 2]; memset(data1, 0, sizeof(data1)); memset(data2, 0, sizeof(data2)
2021-11-30 15:29:41
771
原创 江南大学考研专业课851算法与程序设计_2012年真题
文章目录第一题:思路:答案:第二题:思路:答案:第三题:思路:答案:第四题:思路:答案:第五题:思路:答案:总结第一题:编写一个函数,求数列1-1/2+1/3-1/4…+1/n,利用主函数调用这个函数并输出结果。思路:题目并不难,用一个变量作为分母逐次增加,再用一个变量作为符号逐次跳变,求和注意精度即可。答案:#include<iostream>using namespace std;void solve(double *ans,int n) { double deno=1
2021-04-13 15:33:20
7434
1
原创 feof函数的滞后性
代码中的while循环是这样写的:while (fscanf(fa, "%c", &ch) != EOF) { fprintf(fc, "%c", ch); if (fscanf(fb, "%c", &ch) != EOF) { fprintf(fc, "%c", ch); }}若代码中的while循环按照这样的方式来写的话:while(!feof(fa)){ ch = fgetc(fa); fputc
2021-04-13 14:04:33
266
原创 exit()与return的区别
在main中return v;的效果与exit(v);几乎相同。声明于C语言的stdlib.h中,C++的cstdlib中。exit(0):正常运行程序并退出程序;exit(1):表示异常退出.这个1是返回给操作系统的。exit(x):(x不为0)都表示异常退出exit()的参数会被传递给一些操作系统,包括UNIX,Linux,和MS DOS,以供其他程序使用。return():返回函数,若在主函数中,则会退出函数并返回一值。主要区别如下1. return返回函数值,是关键字; ex
2021-04-13 11:32:34
633
原创 AtCoder Beginner Contest 188-D题-Snuke Prime-题解
AtCoder Beginner Contest 188-D题-Snuke Prime-题解题目链接:D - Snuke Prime.心得体会本题主要应用了差分,差分的好处就是:只需要改变差分数组首和尾的值即可实现原数组中一段的数据都加上或者减去一个值,时间复杂度大大降低。选用map容器而不是直接使用数组的好处是:不用记录第一个项目开始时间和最后一个项目结束时间,中间也会少遍历很多次,节省时间和空间。为了避免数据过大,所以全部采用了long long。下面附上AC代码:#include <
2021-01-17 20:41:45
331
1
原创 牛客练习赛76-A题-校园活动-题解
牛客练习赛76-A题题解题目链接: A-校园活动.心得体会先用字符串接收队列,注意不能用int,long long 都不行,存不下的。大体思路就是前缀和吧。这题重要是一点是:每个人都得分组!#include <bits/stdc++.h>using namespace std;typedef long long ll;int sums[1003];int main() { int n; cin >> n; string t; cin >&
2021-01-16 17:27:35
426
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人