使用技巧

变量声明

声明变量时一定要赋值!!!!!
未定义的一维数组放在 int main() 里会生成随机数!

类型参数

1
template<typename T>

原来使用 int、float、char 等内置类型的地方,都可以用类型参数来代替。

int len = (int) sizeof(arr) / sizeof(*arr);
计算动态数组长度公式:用数组占用空间除以指针占用空间

get函数

gets()函数在C++14中被完全删除了,编译时会报错:

‘gets’ was not declared in this scope

相关功能可以用fgets()函数代替。

命名空间

1
<algorithm>

算法相关

递归算法

时间复杂程度:O(log2n)
注意:一定要设置结束条件!!!
使用方法:
1.return 函数本身
2.直接调用

杨辉三角

公式一:
a[i][j]=a[i1][j]+a[i1][j1]a[i][j] = a[i - 1][j] + a[i - 1][j - 1]

公式二:
sum=sum(ij+1)/(j1)sum = sum * (i - j + 1)/(j - 1)

信息学奥赛一本通在线题库

http://ybt.ssoier.cn:8088

一些题目

以下排序算法中,不需要进行关键字比较操作的算法是( )。
A. 基数排序
B. 冒泡排序
C. 堆排序
D. 直接插入排序

设 x=true, y=true, z=false,以下逻辑运算表达式值为真的是( )。
A. (y∨z)∧x∧z
B. x∧(z∨y) ∧z
C. (x∧y) ∧z
D. (x∧y)∨(z∨x)

参考资料

真题

https://ti.luogu.com.cn

几种排序算法

https://www.cnblogs.com/rope/p/12119391.html