OJ
OJ算法 大学
吹泡泡的小叮当
唯有热爱,方抵漫长岁月!
展开
-
单源最短路径-----Dijkstra算法
#include<iostream>using namespace std;int a[100][100]; //邻接矩阵int book[10]= {0}; //book数组用来标记哪些点目前是最短的距离int dist[10]; //dist数组用来存储第一个顶点到其余顶点的最短距离const int inf=99999999; //假设这个数表示...原创 2024-04-07 20:20:06 · 108 阅读 · 0 评论 -
超级简洁的的KMP算法
#include <iostream>#include <string>using namespace std;/* P 为模式串,下标从 0 开始 */void GetNext(string P, int next[]){ int p_len = P.size(); int i = 0; // P 的下标 int j = ...原创 2024-04-07 20:20:12 · 91 阅读 · 0 评论 -
最近对问题
问题:最近对问题/*第一种方法:蛮力法解决的最近对问题*/C++代码如下:#include<iostream>using namespace std;#define N 1005int x[N],y[N];int ClosestPoints(int x[],int y[],int n){ int index1,index2;//记录点...原创 2024-04-07 20:29:13 · 577 阅读 · 0 评论 -
711连锁店
题目:在美国有-个连锁店叫7-11店,因为这个商店以前是早晨7点开门,晚上11点关门。有一天,一个顾客在这个店挑选了4样东西,然后到付款处去交钱。营业员拿起计算器,按了一些键,然后说:“总共是$7.11。"这个顾客开了个玩笑说:“哦?难道因为你们的店名叫7-11,所以我就要付$7.11吗?"营业员没有听出这是个玩笑,回答说:“当然不是,我已经把这4样东西的价格相乘才得出这个结果的!"顾客一听非...原创 2020-06-19 06:13:35 · 1085 阅读 · 0 评论 -
娱乐中心建设
#include<iostream>#include<cstdio>#include<cstring>#include<algorithm>using namespace std;const int INF = 0x3f3f3f3f;int max_length[7], sum_length[7] = { 0 };int main...原创 2018-07-17 10:52:02 · 265 阅读 · 0 评论 -
霍夫曼编码
1. 问题分析:设需要编码的字符集为{ d1 , d2 , ⋯ , dn } , 它们出现的频率为{ w1 , w2 , ⋯ , wn } , 应用霍夫曼树构造最短的不等长编码方案。2. 算法实现#include<bits/stdc++.h>using namespace std;typedef struct{ unsigned int weigh...原创 2020-06-19 06:12:47 · 713 阅读 · 1 评论 -
我的八枚硬币问题
实验项目3———8枚硬币问题1.问题分析:这个问题就是要找出这八枚硬币中放入假币,前提是还不知道是偏重还是偏轻,所有,要设计一个高效的算法找出这么假币,并且得知是偏重还是偏轻。假定输入的八枚硬币:a、b、c、d、e、f、g、h把硬币分成三组,从八枚硬币中任取六枚a、b、c、d、e、f,在天平两端各放三枚进行比较。 假设a、b、c三枚放在天平的一端,d、e、f三枚放在天平的另一端,可能出...原创 2020-06-19 06:12:59 · 907 阅读 · 0 评论 -
邻接矩阵的深度以及广度优先遍历
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<queue>#define INF 0x3f3f3f3fusing namespace std;typedef struct{ char vexs[10]; ...原创 2018-07-17 10:40:02 · 832 阅读 · 1 评论 -
对给定的一组权值构造相应的哈夫曼树,计算权值
#include<iostream>#include<stdlib.h>using namespace std;typedef int ElemType;struct BTreeNode{ ElemType data; struct BTreeNode* left; struct BTreeNode* right;};//根据数组 a 中 n 个权值建...原创 2018-07-17 10:50:34 · 18687 阅读 · 1 评论 -
二叉树构造-前序输入,后序,中序输出
#include<iostream>#include<cstring>using namespace std;#define DataType chartypedef struct Node{ DataType data; struct Node* lchild; struct Node* rchild; struct Node...原创 2018-07-17 10:46:56 · 1843 阅读 · 0 评论 -
约瑟夫问题---猴王
超级简单!不需要用链表约瑟夫问题:有n只猴子,按顺时针方向围成一圈选大王(编号从1到n),从第1号开始报数,一直数到m,数到m的猴子退出圈外,剩下的猴子再接着从1开始报数。就这样,直到圈内只剩下一只猴子时,这个猴子就是猴王,编程求输入n,m后,输出最后猴王的编号。#include<iostream>using namespace std;int Josephu...原创 2020-06-19 06:12:34 · 538 阅读 · 0 评论 -
用栈判断回文串
#include <iostream>#include <cstdlib>#include <string>using namespace std;const int MaxSize = 50;struct SqStack{ char data[MaxSize]; int top;};void InitStack(SqStack...原创 2018-07-17 10:45:43 · 862 阅读 · 0 评论 -
多源最短路径--Floyd算法
#include<iostream>#include<cstdio>using namespace std;const int INF = 0x3f3f3f3f;int main(void){ int e[10][10] = { 0 }, dis[10], book[10], i, j, k, n, m, t1, t2, t3; cout << ...原创 2018-07-17 10:40:55 · 361 阅读 · 0 评论 -
Prim算法
#include <iostream>#include <stdlib.h>#include <stdio.h>#include <string.h>using namespace std;#define MAXNUM 9int graph[MAXNUM][MAXNUM];bool isVisited[MAXNUM];int...原创 2018-07-17 10:55:35 · 160 阅读 · 0 评论 -
暴力法、分治法、动态规划法求解最大字段和
实验项目4———最大子段和问题代码:https://www.cnblogs.com/snake-hand/archive/2011/11/26/2454431.html《发现这个博主的代码实在是太棒了》1.问题分析: 给定由n个整数(可能有负整数)组成的序列,求该序列形如的子段和的最大值,当所有整数均为负整数时,其最大子段和为0。2. 算法设计思路暴力法: 对于起点 i,遍历所有长...原创 2020-06-19 06:13:13 · 1365 阅读 · 1 评论 -
Kruskal算法
#include <cstdio>#include <cstdlib>#define MAXN 10000 + 10using namespace std;int par[MAXN], Rank[MAXN];typedef struct{ int a, b, price;}Node;Node a[MAXN];int cmp(const void...原创 2018-07-17 10:56:32 · 830 阅读 · 1 评论