算法技巧
提速技巧
- inline
将反复调用的函数添加inline修饰符1
2
3inline int add(int x, int y) {
return x + y;
} - register
将多次使用的值添加register修饰符,作用是将该字段存入cpu而非内存中1
2
3for(register int i = 0; i < n; i++) {
...
} - 数字读取 先读取前面非数字部分,再依次读取数字,(x<<1)+(x<<3)=x*10
1
2
3
4
5
6
7int read(){
int x;
char ch = getchar();
while(!isdigit(ch)) ch = getchar();
while(isdigit(ch)) x = (x<<1)+(x<<3)+ch-'0', ch=getchar();
return x;
}
typedef和#define
1 | typeof long long LL; |
- Title: 算法技巧
- Author: Kelvin
- Created at: 2023-02-27 00:00:00
- Updated at: 2023-05-11 21:41:07
- Link: https://yanwc.com/2023/02/27/2023-03-09-skill/
- License: This work is licensed under CC BY-NC-SA 4.0.