跳到正文

个人记录

备忘录

XHL2010约 4 分钟
原文
文章信息与版本

文章信息

发布
2023年9月15日
收录
2026年9月10日
更新
2026年9月10日
篇幅
约 4 分钟
获赞
1

版本

  1. v1当前

math库函数

C++
int abs(inti) //返回整型参数i的绝对值 
double fabs(double x) //返回双精度参数x的绝对值 
long labs(long n) //返回长整型参数n的绝对值 
double exp(double x) //返回指数函数e^x的值 
double pow(double x,double y) //返回x^y的值 
double pow10(int p) //返回10^p的值 
double log(double x) //返回logex的值 
double log10(double x) //返回log10x的值 
double sqrt(double x) //返回√x的值 
int ceil(double x) //返回不小于x的最小整数 
int floor(double x) //返回不大于x的最大整数

常见容器

queue

队列内部机制是链表,所以不可随机访问元素

vector 向量(动态数组)

内部机制是动态数组,所以可随机访问元素

stack 栈

内部机制是链表,所以不可随机访问元素

list

双向链表,不可随机访问元素


这些容器一般有的成员函数是:

push(x)、push_back(x)

为插入 x 到尾部的意思。

insert()

往内部插入 一个元素。

erase(x)

往内部删除元素 x 或者地址为 x。

pop()

为栈、队列中删除尾部元素使用。

top()

为栈中访问栈顶元素用的 front() 为队列访问队首使用的

排序算法

| 排序法 | 最差时间分析 | 平均时间复杂度 | 稳定度 | | :----------: | :----------: | :----------: | :----------: | :----------: |冒泡排序|Θ(n2)Θ(n^2)|Θ(n2)Θ(n^2)|稳定| |快速排序|Θ(n2)Θ(n^2)|Θ(nlog2n)Θ(nlog_2 n)|不稳定| |选择排序|Θ(n2)Θ(n^2)|Θ(n2)Θ(n^2)|稳定| |二叉树排序|Θ(n2)Θ(n^2)|Θ(nlog2n)Θ(nlog_2 n)|不稳定| |插入排序|Θ(n2)Θ(n^2)|Θ(n2)Θ(n^2)|稳定| |堆排序|Θ(nlog2n)Θ(nlog_2 n)|Θ(nlog2n)Θ(nlog_2 n)|不稳定| |希尔排序|Θ|Θ|不稳定|


判断回文数代码:

C++
bool h(int x){
	int a[10],num=0;
	while(x>0){
		a[num]=x%10;
		x/=10;
		num++;
	}
	for(int i=0;i<num;i++){
		if(a[i]!=a[num-i-1]) return false;
	}
	return true;
}

高精加:

C++
#include<bits/stdc++.h>
using namespace std;
char str[20005];
struct node{
	int len,s[20005];
	node(){len=0;memset(s,0,sizeof(s));}
};
node operator + (const node &a,const node &b){
	node c;
	c.len=max(a.len,b.len);
	for(int i=1;i<=c.len;i++){
		c.s[i]+=a.s[i]+b.s[i];
		c.s[i+1]+=c.s[i]/10;
		c.s[i]%=10;
	}
	if(c.s[c.len+1]) c.len++;
	return c;
}
node read(){
	scanf("%s",str);
	int len=strlen(str);
	node a;
	a.len=len;
	for(int i=0;i<len;i++) a.s[len-i]=str[i]-'0';
	return a;
}
void print(node a){
	for(int i=a.len;i>=1;i--) printf("%d",a.s[i]);
}
int main(){
	node a,b,c;
	a=read();
	b=read();
	c=a+b;
	print(c);
	return 0;
}
原文