数据结构/算法
十二分热爱
这个作者很懒,什么都没留下…
展开
-
顺序表示的线性表--------顺序表
顺序表具有以下特征,逻辑上相邻的元素,在物理上也是相邻的,只要确定了第一个元素的起始位置,线性表上的任一元素都可以随机存取因此线性表的顺序存储结构是一种随机存取的存储结构【存储结构】#include ListSize 100typedef struct{DataType list[ListSize];int length;}SeqList;【基本运算】!!!使用结构体指针变量的时候用箭头,非指针变...原创 2018-05-05 22:45:42 · 161 阅读 · 0 评论 -
1048 Find Coins (25 分)(二分或哈希)
Eva loves to collect coins from all over the universe, including some other planets like Mars. One day she visited a universal shopping mall which could accept all kinds of coins as payments. However,...原创 2018-11-02 12:14:03 · 169 阅读 · 0 评论 -
哈夫曼树(优先队列实现)
#include<iostream>#include<cstdio>#include<queue>using namespace std;int main(){ int t; cin>>t; while(t--){ priority_queue<long long ,vector<long...原创 2018-11-03 15:47:38 · 1187 阅读 · 0 评论 -
1039 Course List for Student(散列)
Zhejiang University has 40000 students and provides 2500 courses. Now given the student name lists of all the courses, you are supposed to output the registered course list for each student who comes ...原创 2018-10-31 12:42:15 · 179 阅读 · 0 评论 -
单词数(stringstream分割单词)
lily的好朋友xiaoou333最近很空,他想了一件没有什么意义的事情,就是统计一篇文章里不同单词的总数。下面你的任务是帮助xiaoou333解决这个问题。Input有多组数据,每组一行,每组就是一篇小文章。每篇小文章都是由小写字母和空格组成,没有标点符号,遇到#时表示输入结束。Output每组只输出一个整数,其单独成行,该整数代表一篇文章里不同单词的总数。Sample In...原创 2018-10-26 14:51:07 · 639 阅读 · 0 评论 -
数据结构与算法系列 目录
原创:https://www.cnblogs.com/skywang12345/p/3603935.html 数据结构和算法目录表 C C++ Java 线性结构 1. 数组、单链表和双链表 2. Linux内核中双向链表的经典实现 数组、单链表和双链表 数组、单链表和双链表 栈 栈 栈 ...转载 2018-08-05 16:08:31 · 210 阅读 · 0 评论 -
求链式线性表的倒数第K项
#include<stdio.h>#include<stdlib.h> typedef struct node* node; struct node{ int data; struct node* next; }; int main(){ int n;int d;int c=0; scanf("%d",&n); node head=...原创 2018-07-27 19:24:57 · 1479 阅读 · 0 评论 -
两个有序链表序列的合并
已知两个非降序链表序列S1与S2,设计函数构造出S1与S2合并后的新的非降序链表S3。输入格式:输入分两行,分别在每行给出由若干个正整数构成的非降序序列,用−1表示序列的结尾(−1不属于这个序列)。数字用空格间隔。输出格式:在一行中输出合并后新的非降序链表,数字间用空格分开,结尾不能有多余空格;若新链表为空,输出NULL。输入样例:1 3 5 -12 4 6 8 10 ...原创 2018-07-28 16:46:38 · 5642 阅读 · 0 评论 -
质因子分解
容易发生错误:1main函数开头忘记调用Find_prime函数2find_prime函数中把i>maxn误写成i<=maxn3没有处理大于sqrt(n)部分的质因子;4在枚举质因子的过程中发生死循环,5没有在循环外定义变量来储存sqrt(n),而在循环条件中直接计算sqrt(n)#include <iostream>#include<math.h>#i...原创 2018-06-07 09:35:30 · 414 阅读 · 0 评论 -
分数的四则运算
1分数的表示struct Fraction{ //分数 int up,down; //分子,分母}; 2分数的化简Fraction reduction(Fraction result){ if(result.down<0){ //分母为负数,令分子分母都变为相反数 result.up=-result.up; result...原创 2018-06-06 13:49:16 · 493 阅读 · 0 评论 -
最大公约数&&最小公倍数
求解最大公约数一般常用欧几里得算法(辗转相除法)因此a和b的公约数与b和a%b的公约数完全相等,故最大公约数也相等即gcd(a,b)=gcd(b,a%b)。递归边界:gcd(a,0)=a;#include <iostream>#include<cstdio>//求最大公约数的辗转相除递归写法int gcd(int a,int b){ if(b==0)return ...原创 2018-06-06 13:27:51 · 229 阅读 · 0 评论 -
铁轨问题(栈操作)
问题:某城市有一个火车站,铁轨铺设如图6-1所示。有n节车厢从A方向驶入车站,按进站顺序编号为1~n。你的任务是让它们按照某种特定的顺序进入B方向的铁轨并驶出车站。为了重组车厢,你可以借助中转站C。这是一个可以停放任意多节车厢的车站,但由于末端封顶,驶入C的车厢必须按照相反的顺序驶出C。对于每个车厢,一旦从A移入C,就不能再回到A了;一旦从C移入B,就不能回到C了。换句话说,在任意时刻,只有两种选...原创 2018-06-06 10:59:38 · 1984 阅读 · 0 评论 -
栈
栈的顺序存储结构#define maxsize 100typedef struct{ Elemtype data[maxsize]; int top;}sqstack;int InitStack(sqstack *s){ //创建一个空栈由指针s指向 if((s=(sqstack *)malloc(sizeof(sqstack)))==NULL) return ERROR; ...原创 2018-05-23 22:01:59 · 98 阅读 · 0 评论 -
静态链表
定义一个静态链表typedef struct{ DataType data; int cursor; }SLinkList[maxsize]; SLinkList S; void Init_SLinkList(SLinkList S) { S[0].cursor=0; } int Length_SLinkList(SLinkList S) { int l,c; l=0; c...原创 2018-05-23 09:41:17 · 171 阅读 · 0 评论 -
双向链表
双向链表结点的定义如下:typedef struct DLnode{DataType data;struct DLnode *prior,*next;}DLNode,*DLinkList;在双向链表中,若p为指向表中某一结点的指针,则显然有:p->next->prior=p->prior->next=p;在双向链表中,对于只需要设计一个方向的指针操作,如Get_DLin...原创 2018-05-22 18:55:00 · 407 阅读 · 0 评论 -
单链表
单链表的结点存储结构定义如下:typedef struct Node{Datatype data;struct Node *next;}LNode,*LinkList;LNode是结点类型,LinkList指向Lnode类型结点的指针类型,即LinkList等同于LNode*要完成申请一块LNode类型的存储单元的操作,则需执行如下语句:p=(LinkList)malloc(sizeof(LNod...原创 2018-05-21 23:33:24 · 2678 阅读 · 0 评论 -
HDU 1047 Integer Inquiry(高精度加法)
One of the first users of BIT's new supercomputer was Chip Diller. He extended his exploration of powers of 3 to go from 0 to 333 and he explored taking various sums of those numbers.``This supercom...原创 2018-12-07 19:19:12 · 150 阅读 · 0 评论