
数据结构
文章平均质量分 72
处变不惊
这个作者很懒,什么都没留下…
展开
-
盛大游戏杯 调和序列
这次的题目用的是截图,我没有它的文档版,只是看这个题目有意思,发一下,自己也练习使用了vector,题目主要的思路就是构建序列+降序排序,题目卡人的地方就是对边界的处理,判断s与序列中元素个数的大小#include<stdio.h>#include<string.h>#include<stdlib.h>#include<iostream...原创 2018-02-25 17:04:23 · 390 阅读 · 0 评论 -
烽火传递
描述 Description 烽火台又称烽燧,是重要的防御设施,一般建在险要处或交通要道上。一旦有敌情发生,白天燃烧柴草,通过浓烟表达信息:夜晚燃烧干柴,以火光传递军情。在某两座城市之间有n个烽火台,每个烽火台发出信号都有一定的代价。为了使情报准确的传递,在m个烽火台中至少要有一个发出信号。现输入n、m和每个烽火台发出的信号的代价,请计算总共最少需要话费多少代价,才能使敌军来袭之原创 2016-09-15 21:59:53 · 1733 阅读 · 1 评论 -
HDU 3415 Max Sum of Max-K-sub-sequence
Problem DescriptionGiven a circle sequence A[1],A[2],A[3]......A[n]. Circle sequence means the left neighbour of A[1] is A[n] , and the right neighbour of A[n] is A[1].Now your job is to calcula原创 2016-09-16 16:35:36 · 211 阅读 · 0 评论 -
单调队列初学:
突然想起来学点关于数据结构的东西了,虽然我没太用到这个单调队列,但是还是想学,因为他很神奇,平白无故的降了一个复杂度,下面贴出我学的博客我们从最简单的问题开始:给定一个长度为N的整数数列a(i),i=0,1,...,N-1和窗长度k.要求: f(i) = max{a(i-k+1),a(i-k+2),..., a(i)},i = 0,1,...,N-1转载 2016-08-27 11:06:18 · 471 阅读 · 0 评论 -
广告印刷
【问题描述】 最近,afy决定给TOJ印刷广告,广告牌是刷在城市的建筑物上的,城市里有紧靠着的N个建筑。afy决定在上面找一块尽可能大的矩形放置广告牌。我们假设每个建筑物都有一个高度,从左到右给出每个建筑物的高度H1,H2…HN,且0【输入文件】中的第一行是一个数n (n第二行是n个数,分别表示每个建筑物高度H1,H2…HN,且0【输出文件】输出文原创 2016-09-15 21:17:07 · 1401 阅读 · 1 评论 -
FOJ 1894 志愿者选拔
世博会马上就要开幕了,福州大学组织了一次志愿者选拔活动。参加志愿者选拔的同学们排队接受面试官们的面试。参加面试的同学们按照先来先面试并且先结束的原则接受面试官们的考查。面试中每个人的人品是主要考查对象之一。(提高人品的方法有扶老奶奶过街,不闯红灯等)作为主面试官的John想知道当前正在接受面试的同学队伍中人品值最高的是多少。于是他请你帮忙编写一个程序来计算。 Inp原创 2016-09-13 23:25:28 · 519 阅读 · 0 评论 -
烽火传递
描述 Description 烽火台又称烽燧,是重要的防御设施,一般建在险要处或交通要道上。一旦有敌情发生,白天燃烧柴草,通过浓烟表达信息:夜晚燃烧干柴,以火光传递军情。在某两座城市之间有n个烽火台,每个烽火台发出信号都有一定的代价。为了使情报准确的传递,在m个烽火台中至少要有一个发出信号。现输入n、m和每个烽火台发出的信号的代价,请计算总共最少需要话费多少代价,才能使敌军来袭之时,情报原创 2016-09-13 20:27:14 · 583 阅读 · 0 评论 -
合并果子
题目描述:在一个果园里,多多已经将所有的果子打了下来,而且按果子的不同种类分成了不同的堆。多多决定把所有的果子合成一堆。每一次合并,多多可以把两堆果子合并到一起,消耗的体力等于两堆果子的重量之和。可以看出,所有的果子经过n-1次合并之后,就只剩下一堆了。多多在合并果子时总共消耗的体力等于每次合并所耗体力之和。因为还要花大力气把这些果子搬回家,所以多多在合并果子时要尽可能地节省体原创 2016-09-13 20:00:35 · 482 阅读 · 0 评论 -
HDU 3530 Subsequence
Problem DescriptionThere is a sequence of integers. Your task is to find the longest subsequence that satisfies the following condition: the difference between the maximum element and the minimum el原创 2016-08-27 15:50:11 · 431 阅读 · 0 评论 -
归并排序 简单版
下面是我整理刘汝佳算法的代码,按照自己格式改了改,还有另一种比较适合自己#include#include#include#include #include #includeusing namespace std;const int N=10000+2;int A[N];int T[N];void Merge_sort(int l,int r){ if (r-l>1原创 2016-09-19 21:24:32 · 251 阅读 · 0 评论 -
Kruskal算法模板 HDU 1233
Problem Description某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离。省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可),并要求铺设的公路总长度为最小。请计算最小的公路总长度。 Input测试输入包含若干测试用例。每个测试用例的第1行给出村庄数目N ( 当原创 2016-09-26 18:42:51 · 324 阅读 · 0 评论 -
哈夫曼编码与解码
#include#include#include#define MAXNUM 60typedef struct{char ch;int weight; //权值,这个字符出现的频率int parent;int left;int right;}HuffNode;typedef struct{char code[MAXNUM];int start;}HuffCode原创 2018-01-09 17:42:17 · 1450 阅读 · 1 评论 -
poj 2299 Ultra-QuickSort
DescriptionIn this problem, you have to analyze a particular sorting algorithm. The algorithm processes a sequence of n distinct integers by swapping two adjacent sequence elements until the seque原创 2017-05-03 17:12:22 · 336 阅读 · 0 评论 -
poj 2337 Catenyms
DescriptionA catenym is a pair of words separated by a period such that the last letter of the first word is the same as the last letter of the second. For example, the following are catenyms: d原创 2017-05-03 11:41:01 · 303 阅读 · 0 评论 -
poj 2230 Watchcow
DescriptionBessie's been appointed the new watch-cow for the farm. Every night, it's her job to walk across the farm and make sure that no evildoers are doing any evil. She begins at the barn, mak原创 2017-05-03 09:25:47 · 273 阅读 · 0 评论 -
poj 2387 Til the Cows Come Home
Bessie is out in the field and wants to get back to the barn to get as much sleep as possible before Farmer John wakes her for the morning milking. Bessie needs her beauty sleep, so she wants to get b原创 2017-04-12 21:43:50 · 240 阅读 · 0 评论 -
poj 1364 King
DescriptionOnce, in one kingdom, there was a queen and that queen was expecting a baby. The queen prayed: ``If my child was a son and if only he was a sound king.'' After nine months her child was原创 2016-11-11 12:12:46 · 241 阅读 · 0 评论 -
poj 1201 Intervals
DescriptionYou are given n closed, integer intervals [ai, bi] and n integers c1, ..., cn. Write a program that: reads the number of intervals, their end points and integers c1, ..., cn from th原创 2016-11-11 12:16:02 · 227 阅读 · 0 评论 -
HDU 3415 Max Sum of Max-X-sub-sequence
Problem DescriptionGiven a circle sequence A[1],A[2],A[3]......A[n]. Circle sequence means the left neighbour of A[1] is A[n] , and the right neighbour of A[n] is A[1].Now your job is to calcula原创 2016-08-27 14:58:52 · 414 阅读 · 0 评论 -
拓扑排序
#include#include#include#includeusing namespace std;int map[500][500],vis[500],topo[500];int n,t; //点数int m; //边数int dfs(int u){ int i; vis[u]=-1; //表示正在访问 for (i=1;i原创 2016-03-08 09:33:59 · 201 阅读 · 0 评论 -
HDU 欧拉回路
Problem Description欧拉回路是指不令笔离开纸面,可画过图中每条边仅一次,且可以回到起点的一条回路。现给定一个图,问是否存在欧拉回路?Input测试输入包含若干测试用例。每个测试用例的第1行给出两个正整数,分别是节点数N ( 1 束。Output每个测试用例的输出占一行,若欧拉回路存在则输出1,否则输出0。Sample Inp原创 2016-06-01 14:43:48 · 376 阅读 · 0 评论 -
哈希表(线性探测再散列)
#include#includetypedef struct elem{ int key; int flag; int count;}elem;typedef struct node{ elem *base; int length;}Table;void Creat(Table &s){ int i,m,n,j; int a[100],b[100],c[原创 2015-11-28 15:11:01 · 1872 阅读 · 1 评论 -
数据结构实验一(1)
1)顺序表的操作① 输入一组整型元素序列,建立线性表的顺序存储结构。② 实现该线性表的遍历。③ 在该顺序表中查找某一元素,查找成功显示查找元素,否则显示查找失败。④ 在该顺序表中删除或插入指定元素。⑤ 建立两个按值递增有序的顺序表,将他们合并成一个按值递增有序的顺序表。#include#includetypedef struct{ int *a; int len原创 2015-11-01 00:14:10 · 841 阅读 · 0 评论 -
数据结构实验二
实验二:栈与队列的应用内容:(1)输入一个十进制数,利用栈操作,将该数转换成n进制数。(2)输入一个表达式,表达式中包括三种括号“()”、“[]”和“{}”,判断该表达式的括号是否匹配。#include#include#define max 100#define add 10typedef struct node{ int *base; int top; in原创 2015-11-01 00:22:10 · 397 阅读 · 0 评论 -
舞伴配对问题
循环队列的应用——舞伴配对问题:在舞会上,男、女各自排成一队。舞会开始时,依次从男队和女队的队头各出一人配成舞伴。如果两队初始人数不等,则较长的那一队中未配对者等待下一轮舞曲。假设初始男、女人数及性别已经固定,舞会的轮数从键盘输入。试模拟解决上述舞伴配对问题。要求:从屏幕输出每一轮舞伴配对名单,如果在该轮有未配对的,能够从屏幕显示下一轮第一个出场的未配对者的姓名。//循环队列的常用函数#incl原创 2015-11-01 00:26:02 · 2115 阅读 · 0 评论 -
数据结构实验一(2)
单链表的操作① 输入一组整型元素序列,使用尾插法建立一个带有头结点的单链表。② 实现该线性表的遍历。③ 在该单链表的第i个元素前插入一个整数。④ 删除该单链表中的第i个元素,其值通过参数将其返回。#include#includetypedef struct{ int *a; int length; int listsize;}sq_list;void ini原创 2015-11-01 00:17:35 · 409 阅读 · 0 评论 -
顺序表的查找
顺序表的查找内容:(1)随机产生n个两位整数,构造一个查找表。(2)输入一个整数,利用顺序查找法在查找表中查找该整数是否存在。若查找成功,返回该整数在表中的位置;查找失败则返回0。(3)对查找表按递增顺序进行排序。(4)输入一个整数,利用折半查找法在有序表中查找该整数是否存在。若查找成功,返回该整数在表中的位置;查找失败则返回0。(5)输入整组数无序,但局部有序的一组整数,原创 2015-11-18 00:23:34 · 1158 阅读 · 0 评论 -
最小生成树(普里姆算法,克鲁斯卡尔算法)
#include#includeusing namespace std;typedef struct node{ int start; int end; int pow;}adjvex;int vexnum,arcnum;adjvex road[20];int node[20];bool cmp(adjvex &a,adjvex &b){ return a.pow<b.p原创 2015-11-22 21:11:23 · 588 阅读 · 0 评论 -
邻接表对图常用的操作
#include#include#define maxsize 20#define Add 10typedef struct Arcnode{ int adjvex; struct Arcnode *nextarc;}Arcnode,*ARC;typedef struct Vnode{ int data; Arcnode *firstarc;}Vnode,Ad原创 2015-11-05 23:27:23 · 354 阅读 · 0 评论 -
二叉排序树(插入、删除、查找)
#include#includetypedef struct elem{ int key;}elem;typedef struct node{ elem data; struct node* lchild,*rchild;}*Bitree,Binode;int Search(Bitree T,int key){ if (!T) { printf("查找失败\n原创 2015-11-29 15:37:03 · 348 阅读 · 0 评论 -
学生信息排序(基于文件)
#include#includetypedef struct student{ char number[20]; int score; int location; int num; char name[10];}student;typedef struct{ student *base; int num;}Message;void Scan(studen原创 2015-12-08 20:05:03 · 538 阅读 · 0 评论 -
HDU 还是畅通工程
Problem Description某省调查乡村交通状况,得到的统计表中列出了任意两村庄间的距离。省政府“畅通工程”的目标是使全省任何两个村庄间都可以实现公路交通(但不一定有直接的公路相连,只要能间接通过公路可达即可),并要求铺设的公路总长度为最小。请计算最小的公路总长度。Input测试输入包含若干测试用例。每个测试用例的第1行给出村庄数目N ( 当N为0时,输入结束,该原创 2016-05-31 17:11:41 · 287 阅读 · 0 评论 -
HDU 1874 畅通工程续
Problem Description某省自从实行了很多年的畅通工程计划后,终于修建了很多路。不过路多了也不好,每次要从一个城镇到另一个城镇时,都有许多种道路方案可以选择,而某些方案要比另一些方案行走的距离要短很多。这让行人很困扰。现在,已知起点和终点,请你计算出要从起点到终点,最短需要行走多少距离。Input本题目包含多组数据,请处理到文件结束。每组数据第一行包含原创 2016-05-07 21:19:36 · 590 阅读 · 0 评论 -
蓝桥杯 显示二叉树
排序二叉树的特征是:某个节点的左子树的所有节点值都不大于本节点值。某个节点的右子树的所有节点值都不小于本节点值。为了能形象地观察二叉树的建立过程,小明写了一段程序来显示出二叉树的结构来。#include #include #define N 1000#define HEIGHT 100#define WIDTH 1000struct BiTree原创 2016-05-27 17:59:16 · 778 阅读 · 0 评论 -
蓝桥杯 操作格子
问题描述有n个格子,从左到右放成一排,编号为1-n。共有m次操作,有3种操作类型:1.修改一个格子的权值,2.求连续一段格子权值和,3.求连续一段格子的最大值。对于每个2、3操作输出你所求出的结果。输入格式第一行2个整数n,m。接下来一行n个整数表示n个格子的初始权值。接下来m行,每行3个整数p,x,y,p表示操作类型,p=1原创 2016-04-13 15:37:59 · 320 阅读 · 0 评论 -
hdu 1556 color the balls
Problem DescriptionN个气球排成一排,从左到右依次编号为1,2,3....N.每次给定2个整数a b(a Input每个测试实例第一行为一个整数N,(N 当N = 0,输入结束。Output每个测试实例输出一行,包括N个整数,第I个数代表第I个气球总共被涂色的次数。Sample Input31 12 23 3转载 2016-04-09 17:49:09 · 239 阅读 · 0 评论 -
hdu 1166 敌兵布阵
Problem DescriptionC国的死对头A国这段时间正在进行军事演习,所以C国间谍头子Derek和他手下Tidy又开始忙乎了。A国在海岸线沿直线布置了N个工兵营地,Derek和Tidy的任务就是要监视这些工兵营地的活动情况。由于采取了某种先进的监测手段,所以每个工兵营地的人数C国都掌握的一清二楚,每个工兵营地的人数都有可能发生变动,可能增加或减少若干人手,但这些都逃不过C国的监视。原创 2016-04-09 17:39:14 · 195 阅读 · 0 评论 -
hdu 1241 Oil Deposits
Problem DescriptionThe GeoSurvComp geologic survey company is responsible for detecting underground oil deposits. GeoSurvComp works with one large rectangular region of land at a time, and creates a原创 2016-04-04 11:53:17 · 254 阅读 · 0 评论 -
hdu 1312 Red and Black (dfs+bfs)
Red and BlackTime Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submission(s): 15731 Accepted Submission(s): 9730Problem DescriptionThere is a rectangula原创 2016-04-03 11:39:05 · 267 阅读 · 0 评论 -
邻接矩阵关于图的常用操作
#include#include#define maxsize 21typedef int adjmatrix[maxsize][maxsize];typedef struct{ int vex[maxsize]; //顶点向量 adjmatrix arcs; //邻接矩阵 int vexnum,arcnum;}Mgraph;typedef struct ele原创 2015-11-05 23:35:27 · 900 阅读 · 0 评论