- main()相当于int main()
- int main(void)表示不接受参数,int main()表示授受任何数量的参数,void main()表示接受任何参数且无返回值
更进一步讲,最普遍的main函数的写法应该是
int main(int argc, char **argv) {
}
int main(int argc, char *argv[]) {
}
https://www.zhihu.com/question/24336567/answer/27458151
2.
https://www.cnblogs.com/phemiku/p/11409055.html
https://www.cnblogs.com/wangyifan124/p/10319878.html
3.
程序的空间可以大致分成三类:静态空间、调用栈空间、动态空间
全局变量、代码和声明为静态的变量在静态空间。静态空间在程序运行前可以用size查看占用大小。
局部变量、函数调用相关的变量(参数、返回值、当前层函数的代码执行位置)存在调用栈中。调用栈大小一般操作系统有限制,win限制在exe中(编译时可改),Linux限制在当前的shell中(运行前可改)。Linux下的评测系统一般会把调用栈开大到内存限制。
new出来或是手工alloc出来的空间在动态空间中,动态空间又叫堆空间(但和堆这种数据结构关系没那么大)。堆空间的东西只要不delete或其他方式释放,并不会像局部变量那样函数跑完就回收。操作系统和评测系统一般对堆空间不会单独限制。操作系统会有优秀的数据结构维护堆空间,让我们用起来很平滑,但如果我们故意卡操作系统的算法,仍然可能让new跑得比预期慢。
4.splay
https://blog.csdn.net/qq_30974369/article/details/77587168
5.n&1判断奇偶;
当n为奇数时,返回1;当n为偶数时,返回0
6.abs函数:求整数的绝对值
头文件:stdlib.h
函数原型:int abs(int i);
fabs函数
原型:extern float fabs(float x);
用法:#include <math.h>
说明:计算|x|, 当x不为负时返回x,否则返回-x
7.enum T { A, B, C }相当于
typedef int T;
const T A = 0;
const T B = 1;
const T C = 2;
8.哈希函数与哈希表
这个举了例子:
10.输出优化
void print(int x){ if(x<0) { putchar('-'); x=-x; } if(x>9) print(x/10); putchar(x%10+'0'); }
11.秦九韶算法
12.template<typename TYPE>
是定义模版的意思,比如:
template<typename TYPE>
TYPE add(TYPE a, TYPE b){
return a + b;
}
这就是个函数模版
int n = add(3, 4);
double d = add(3.4, 5.6);
从例子可以看出add可以使得传入的两个参数不受限制,int也行,double也行,但传入的两个参数必须是相同类型的
template<typename TYPE>
void fun(TYPE t) {
printf("%d
", sizeof(TYPE));
}
int main() {
int n = 0;
double d = 0;
fun(n);
fun(d);
return 0;
}
打印: 4 8 int 是4个字节的,double是8个字节的,因为传入参数类型不同而有所不同
13.gcd-函数
int gcd(int a,int b){
if(a==0) return b;
if(b==0) return a;
return gcd(b,a%b);
}
是求最大公约数的 有了这个函数之后,求最大公约数就好很多了
不过可以这样写:
int gcd(int a,int b){
//if(a==0) return b;
if(b==0) return a;
return gcd(b,a%b);
}
a==0 这行可以不要
这样写也一样:
int gcd(int a,int b) {
return b==0?a:gcd(b,a%b);
}
14.欧拉回路
15.树状数组详解
16.动态规划详细总结及例题
17.define
18.费用流