- 博客(9)
- 收藏
- 关注
原创 Dijkstra算法
应用Dijkstra算法能得到某一个点到其他点的最短路径。介绍输入数据:6 61 4 11 2 21 6 42 5 54 3 22 6 1算法简介有两个集合,S1-已经确定最短路径的点,S2-候选点每一轮while循环会从S2中挑出距离x最近的一个点作为real_x加入S1,并利用real_x来更新其他点到x的路径步骤演练以x = 1 为例,表格中蓝色表示已经加入S...
2018-11-20 11:38:16
143
转载 manacher's algorithm寻找最长回文子串
manacher’s algorithm寻找最长回文子串#include <vector>#include <iostream>#include <string>using namespace std;string Manacher(string s) { // Insert '#' string t = "$#&q
2018-10-18 21:51:50
125
原创 1003. Emergency和1030. Travel Plan
两者题目本质上是一样的,都是要找到最小的复合要求的方案,但是后者要求打印出路径。1003:每个城市都有搜救队,两个城市之间有距离,给定两个城市,求S到D的最短路径一共有几条和这些方案下能集结到的最大搜救队个数。比如:Sample Input5 6 0 21 2 1 5 30 1 10 2 20 3 11 2 12 4 13 4 1Sample Output2 4sample inp...
2018-03-07 14:46:45
155
原创 字符串哈希
将字符串转化成整数,比如是BOB类型的字符串int getID(char *a){ int id=0; for(int i=0;i<3;i++){ id=id*26+a[i]-'A'; } return id;}
2018-02-28 13:36:22
231
原创 1064. Complete Binary Search Tree
//完全二叉搜索树,用数组存储,下标从1开始,左儿子为下标*2,右儿子为下标*2+1;//利用BST中序遍历的性质,将排好序的元素一一插入,最后按照下标遍历扫描一遍即可#include <stdio.h>#include <stdlib.h>int compare(const void*a,const void *b){ return (*(int*)a-*(int*)b)...
2018-02-24 09:24:01
142
原创 PAT 1094. The Largest Generation
用邻接表存储图,然后BFS70~78这几行的代码必须放在while(rear!=front)这个循环的尾端,防止最大代位于末端时而由于front=rear已成立而跳出循环从而没有更新#include <stdio.h>#include <stdlib.h>#define max 100typedef struct ArcNode{ struct ArcNode *next;...
2018-02-23 09:25:44
176
原创 1004. Counting Leaves
1004. Counting LeavesA family hierarchy is usually presented by a pedigree tree. Your job is to count those family members who have no child.InputEach input file contains one test case. Each case star...
2018-02-08 15:36:59
184
转载 浙大mooc给出的调用qsort方法
/* 快速排序 - 直接调用库函数 *//*(前者小于后者输出1,前者大于后者输出-1)——是为降序*//*(前者小于后者输出-1,前者大于后者输出1)——是为升序*///助记方法:哪种情况下输出1,升降序便与该种情况吻合( 假设a在序列后,b在序列前) #include /*---------------简单整数排序---------------
2018-01-30 16:44:45
166
原创 基于浙大mooc给出的改进快排程序
void quick_sort(int *a,int left,int right){ if(right-left>=cutoff){ //cutoff于此处为区分快速排序和插入排序的阈值,数据较多时选择快排 int pivo=getpivot(a,left,right); int i=left+1,j=right-2,tmp; while
2018-01-30 16:39:34
227
空空如也
空空如也
TA创建的收藏夹 TA关注的收藏夹
TA关注的人