自定义博客皮肤VIP专享

*博客头图:

格式为PNG、JPG,宽度*高度大于1920*100像素,不超过2MB,主视觉建议放在右侧,请参照线上博客头图

请上传大于1920*100像素的图片!

博客底图:

图片格式为PNG、JPG,不超过1MB,可上下左右平铺至整个背景

栏目图:

图片格式为PNG、JPG,图片宽度*高度为300*38像素,不超过0.5MB

主标题颜色:

RGB颜色,例如:#AFAFAF

Hover:

RGB颜色,例如:#AFAFAF

副标题颜色:

RGB颜色,例如:#AFAFAF

自定义博客皮肤

-+

c

初学

  • 博客(51)
  • 收藏
  • 关注

原创 算法和数据结构基本概念

数据是客观事物的符号表示。数据元素是数据的基本单位。数据项是组成数据元素的最小单位。数据对象是性质相同的数据元素的集合,是数据的一个子集。算法是为了解决某类问题而规定的一个有限长的操作序列。算法的五个重要特性:有穷性、确定性、可行性、输入、输出。评价算法优劣的基本标准:正确性、可读性、健壮性、高效性。衡量算法的两个主要指标:时间复杂度、空间复杂度。...

2021-01-23 16:46:22 254

原创 时间复杂度和空间复杂度

文章目录1.时间复杂度1.时间复杂度一条语句的重复执行次数称作语句频度。分析算法时间复杂度的基本方法:找出所有语句中语句频度最大的那条语句作为基本语句,计算基本语句的频度得到问题规模n的某个函数f(n),取其数量级用符号“O”表示。...

2021-01-19 12:18:10 193

原创 c/c++常用函数

求绝对值函数fabs()

2021-01-08 20:55:54 575 2

原创 计算f(x)=a0+a1*x+a2*x^2+...+an*x^n

提公因子,程序从里往外算#include<bits/stdc++.h>using namespace std;int main(){ double x,ans,a[100]; int n; cout<<"输入n\n"; cin>>n; cout<<"输入x\n"; cin>>x; cout<<"输入"<<n+1<<"个系数\n"; for.

2021-01-08 15:18:00 1952

原创 链队列的基础操作

为了操作方便,给链队添加一个头结点,并令头指针始终指向头结点。#include<bits/stdc++.h>using namespace std;typedef struct Node{ int date; struct Node *next;}QNode,*QueueList;typedef struct { QueueList front,rear;}QueueNode;void InitQueue(QueueNode &Q)//链队列的初始化{

2020-12-26 17:56:45 154

原创 链队列的基本操作

#include<bits/stdc++.h>using namespace std;typedef struct Node{ int date; struct Node *next;}QNode,*QueueList;typedef struct { QueueList front,rear;}QueueNode;void InitQueue(QueueNode &Q)//链队列的初始化{ Q. front=Q.rear=new QNode; Q

2020-12-26 17:52:22 331

原创 链栈的基本操作

由于栈只在栈顶操作,因此,通常不设头结点。#include<bits/stdc++.h>using namespace std;typedef struct Node{ int date; struct Node *next;}SNode,*StackList;void InitStack(StackList &top)//链栈的初始化{ top=NULL;}int EmptyStack(StackList top)//判空{ if(top==NULL)

2020-12-26 16:38:22 245 1

原创 数据结构和算法的基本概念

评价算法优劣的基本标准:正确性,可读性,健壮性,高效性。算法的五个重要特性:有穷性,确定性,可行性,输入,输出。

2020-12-26 14:58:19 104

原创 哈夫曼编码译码

#include<bits/stdc++.h>using namespace std;typedef struct{ int weight; char ch; int parent,lchild,rchild;}HNode,*HTree;typedef char **HCode;char code[1000];void Select(HTree H,int n,int &n1,int &n2)//选出最小的两个树{ int min=

2020-12-24 21:20:55 232

原创 拓扑排序

#include<bits/stdc++.h>using namespace std;int v,e,x,y,indegree[100],ans[100],t=1;typedef struct ANode{ int adjvex; struct ANode *next;}ANode;struct VNode{ int date; ANode *first;}V[100];typedef struct Stack{ int date[10

2020-12-24 21:20:34 47

原创 计算表达式

#include<bits/stdc++.h>using namespace std;#define MAXSIZE 100typedef struct{ int opnd[MAXSIZE]; int top;}Stack1;typedef struct{ char opter[MAXSIZE]; int top;}Stack2;char cmp[7][8]= {">><<<>>",

2020-12-24 21:20:17 130

原创 散列表

#include<bits/stdc++.h>using namespace std;const int M=20,mod=13;int x;typedef struct FLNode{ int date; struct FLNode *next;}Node,*NodeList;NodeList L[M];void Init(){ for(int i=0;i<mod;i++) { L[i]=new Node;

2020-12-24 21:19:59 67

原创 joseph环

#include<bits/stdc++.h>using namespace std;typedef struct Node{ int date; int password; struct Node *next;}Node,*LinkList;int InitList(LinkList &L){ L=new Node; if(L==NULL) return 0; L->next=L; return

2020-12-24 15:12:08 160

原创

类是用户自定义的一种数据类型,特殊之处在于和一般的数据类型相比,它不仅包含相关的数据,还包含能对这些数据进行处理的函数。类中包含的数据和函数统称为成员,数据称为成员数据,函数称为成员函数。class 类名{ private: 私有成员数据和成员函数;//私有成员只能被本类的成员函数访问 protected: 保护成员数据和成员函数; public: 公有成员数据和成员函数;};#include<bits/stdc++.h>using namespace std;c

2020-12-06 09:56:22 143

原创 数据类型转换

数据类型转换,仅在本次操作中对操作数进行临时性的转换,并不改变数据类型说明中所规定的。#include <bits/stdc++.h>using namespace std;int main(){ double x=5.6; int y; y=(int)x; cout<<"x="<<x<<" "<<"y="<<y; return 0;}//输出 x=5.6 y=5...

2020-11-13 10:54:38 52

原创 宏定义

编译预处理进行宏替换时,不作任何计算,也不做语法检查,仅对宏名做简单的替换。1.无参数宏#include <bits/stdc++.h>using namespace std;#define A 3+3#define B A*Aint main(){ cout<<B<<"\n"; return 0;}/*输出15,而不是36,因为编译预处理进行宏替换后为cout<<3+3*3+3<<'\n';*/2.带参数的宏#d

2020-11-13 10:47:03 61

原创 全局变量和局部变量

全局变量的作用域是从声明该变量的位置开始直到程序结束。在一个函数内部,如果一个局部变量和一个全局变量重名,则在局部变量的作用域内,全局变量不起作用。

2020-11-13 10:20:24 38

原创 链栈的基本算法

1.链栈的初始化void StackInit()

2020-11-13 10:11:54 380

原创 函数

文章目录1.具有缺省参数值的函数2.内联函数3.函数的重载1.具有缺省参数值的函数调用函数时若给出了相应实参的值,则函数使用实参值,若没有给出相应的实参,则使用缺省值。因为实参与形参的结合是从左到右进行的,因此指定默认值的参数必须从右向左指定。例如int max(int a,int b=7,int c=6);2.内联函数编译器将函数体的代码插入到函数调用处。定义函数时在函数的类型前加上修饰词inline,即可指明将函数定义为内联函数。当函数体内含有循环,switch语句和复杂嵌套if语句时,

2020-11-12 20:14:09 70

原创 链表

typedef struct LNode{ int date; struct LNode *next;}LNode,*LinkList;int GreateList(LinkList &L,int n)//尾插法创建含n个元素的链表{ int i; LinkList p,r; L=new LNode; if(L==NULL) { cout<<"error"; return 0; }

2020-10-12 18:45:54 93

原创 条件编译

#ifdef 标识符程序段1;#else程序段2;#endif功能:如果标识符已被定义,则编译程序段1,否则编译程序段2.例子#include <bits/stdc++.h>using namespace std;#define A //此时#ifdef A 为真int main(){ #ifdef A cout<<1; #else...

2020-06-02 15:14:27 153

原创 #define宏定义

#define 宏名(参数表) 字符串例子1#include <bits/stdc++.h>using namespace std;#define PI 3.14 //注意没有分号int main(){ cout<<PI; return 0;}输出:3.14例子2#include <bits/stdc++.h>usi...

2020-06-02 15:12:35 151

原创 Function Run Fun-dp

DescriptionWe all love recursion! Don’t we?Consider a three-parameter recursive function w(a, b, c):if a <= 0 or b <= 0 or c <= 0, then w(a, b, c) returns: 1if a > 20 or b > 20 or c > 20, then w(a, b, c) returns: w(20, 20, 20)if a &l

2020-06-02 14:55:15 118

原创 容易忽视的错误

1.定义字符串,注意是char[],不是int[],

2020-06-02 14:38:13 120

原创 来来的正方形-dp

Description有一个n*m的01矩阵,想找出一个只包含1的最大正方形,输出这个正方形的边长。Input多组数据,第一行为两个整数n,m(1<=n,m<=100),接下来n行,每行m个数字,只有0或1.Output一个整数,最大正方形的边长每个输出占一行。Sample Input3 31 1 11 1 01 1 0Sample Output2/*dp值取决于min(上,左,左上)+1;是0的话则dp值为0*/#include <bits/stdc+

2020-05-30 09:24:37 129

原创 最长上升子序列-dp

Description一个数的序列bi,当b1 < b2 < … < bS的时候,我们称这个序列是上升的。对于给定的一个序列(a1, a2, …, aN),我们可以得到一些上升的子序列(ai1, ai2, …, aiK),这里1 <= i1 < i2 < … < iK <= N。比如,对于序列(1, 7, 3, 5, 9, 4, 8),有它的一些上升子序列,如(1, 7), (3, 4, 8)等等。这些子序列中最长的长度是4,比如子序列(1, 3, 5, 8

2020-05-30 07:12:56 171

原创 max sum-dp

DescriptionGiven a sequence a[1],a[2],a[3]…a[n], your job is to calculate the max sum of a sub-sequence. For example, given (6,-1,5,4,-7), the max sum in this sequence is 6 + (-1) + 5 + 4 = 14.InputThe first line of the input contains an integer T(1<

2020-05-30 06:45:06 100

原创 命运-dp

Description穿过幽谷意味着离大魔王lemon已经无限接近了! 可谁能想到,yifenfei在斩杀了一些虾兵蟹将后,却再次面临命运大迷宫的考验,这是魔王lemon设下的又一个机关。要知道,不论何人,若在迷宫中被困1小时以上,则必死无疑!可怜的yifenfei为了去救MM,义无返顾地跳进了迷宫。让我们一起帮帮执着的他吧! 命运大迷宫可以看成是一个两维的方格阵列,如下图所示:yifenfei一开始在左上角,目的当然是到达右下角的大魔王所在地。迷宫的每一个格子都受到幸运女神眷恋或者痛苦魔王的诅咒,所

2020-05-30 05:34:30 171 1

原创 Recaman Sequence-dp

DescriptionThe Recaman’s sequence is defined by a0 = 0 ;for m > 0, am = am−1 − m if the rsulting am is positive and not already in the sequence, otherwise am = am−1 + m.The first few numbers in the Recaman’s Sequence is 0, 1, 3, 6, 2, 7, 13, 20, 12,

2020-05-30 03:37:51 236 1

原创 数字三角形-dp

Description73 88 1 02 7 4 44 5 2 6 5给出了一个数字三角形。从三角形的顶部到底部有很多条不同的路径。对于每条路径,把路径上面的数加起来可以得到一个和,你的任务就是找到最大的和。注意:路径上的每一步只能从一个数走到下一层上和它最近的左边的那个数或者右边的那个数。Input输入数据有多组,每组输入的是一行是一个整数N (1 < N <= 100),给出三角形的行数。下面的N行给出数字三角形。数字三角形上的数的范围都在0和100之间。Output

2020-05-29 18:50:07 124

原创 穿过街道-dp

Description一个城市的街道布局如下:从最左下方走到最右上方,每次只能往上或往右走,一共有多少种走法?Input输入很多行行数,每行1个数字代表n的值,当n=0时结束(2<=n<=15)Output输出对应每行n值的走法.Sample Input121050Sample Output26184756252#include <bits/stdc++.h>using namespace std;int main(){ int a[

2020-05-29 18:11:21 334

原创 Moving Tables-贪心

DescriptionThe famous ACM (Advanced Computer Maker) Company has rented a floor of a building whose shape is in the following figure.The floor has 200 rooms each on the north side and south side along the corridor. Recently the Company made a plan to ref

2020-05-28 23:02:53 221

原创 Wooden Sticks-贪心

DescriptionThere is a pile of n wooden sticks. The length and weight of each stick are known in advance. The sticks are to be processed by a woodworking machine in one by one fashion. It needs some time, called setup time, for the machine to prepare proce

2020-05-28 21:27:57 173

原创 区间覆盖-贪心

Description用i来表示x轴上坐标为[i-1,i]的区间(长度为1),并给出M(1=<M=<200)个不同的整数,表示M个这样的区间。现在让你画几条线段覆盖住所有的区间,条件是:每条线段可以任意长,但是要求所画线段之和最小,并且线段的数目不超过N(1=<N=<50)。Input第一行为M和N;第二行为这M个数;Output输出所画线段之和最小的值Sample Input5 31 3 4 8 11Sample Output6/**/#include

2020-05-28 20:33:21 198

原创 看节目-贪心

Description确实如此,世界杯来了,球迷的节日也来了,估计很多ACMer也会抛开电脑,奔向电视了。作为球迷,一定想看尽量多的完整的比赛,当然,作为新时代的好青年,你一定还会看一些其它的节目,比如新闻联播(永远不要忘记关心国家大事)、非常6+7、超级女生,以及王小丫的《开心辞典》等等,假设你已经知道了所有你喜欢看的电视节目的转播时间表,你会合理安排吗?(目标是能看尽量多的完整节目)Input输入数据包含多个测试实例,每个测试实例的第一行只有一个整数n(n<=100),表示你喜欢看的节目的

2020-05-28 18:55:41 303

原创 老鼠的旅行-贪心

Description一只老鼠有M磅猫食,然后在N个房间里面用猫食换JavaBean,房间i中能用F[i]磅的猫食换J[i]磅的JavaBean,而且老鼠可以在一个房间里根据一定比例a%来换取JavaBean.现在他是这任务分配给你:告诉他,他的JavaBeans的获取能最多。InputThe input consists of multiple test cases. Each test case begins with a line containing two non-negative int

2020-05-28 17:53:24 217

原创 斐波那契数列-高精度

Description兴安黑熊在学习数学时,特别喜欢斐波那契数列,它的表示如下: f(0)=1,f(1)=1, f(n)=f(n-1)+f(n-2);现在他想知道该数列的每个确切的值是多少,学过高精度的你能帮助他吗?Input输入数据有多组,每组一个数n. (1<=n <=200).Output输出f(n)的值。Sample Input35Sample Output38#include <bits/stdc++.h>using namespace std;

2020-05-27 11:03:44 1180 1

原创 计算N!-高精度

DescriptionGiven an integer N(0 ≤ N ≤ 10000), your task is to calculate N!InputOne N in one line, process to the end of file.OutputFor each N, output N! in one line.Sample Input0130Sample Output11265252859812191058636308480000000/*N!=(N-1)!N

2020-05-27 02:14:06 343

原创 指针

#include <bits/stdc++.h>using namespace std;void swap(int *p,int *q){ int t; t=*q; *q=*p; *p=t; /*错误做法:这样写不起作用,两个数是没有被交换的。 int *t; t=q; q=p; p=t; */}int main(){ int a,b; cin>>a>>b; swap(&amp

2020-05-27 00:33:26 178

原创 白与黑搜索-递归

Description有一间长方形的房子,地上铺了白色、黑色两种颜色的正方形瓷砖。你站在其中一块黑色的瓷砖上,只能向相邻的黑色瓷砖移动。请写一个程序,计算你总共能够到达多少块黑色的瓷砖。Input包括多个数据集合。每个数据集合的第一行是两个整数W 和H,分别表示x 方向和y 方向瓷砖的数量。W 和H 都不超过20。在接下来的H 行中,每行包括W 个字符。每个字符表示一块瓷砖的颜色,规则如下:1)‘.’:黑色的瓷砖;2)‘#’:白色的瓷砖;3)‘@’:黑色的瓷砖,并且你站在这块瓷砖上。该字符在每

2020-05-25 23:34:44 175

空空如也

空空如也

TA创建的收藏夹 TA关注的收藏夹

TA关注的人

提示
确定要删除当前文章?
取消 删除