window.cnblogsConfig = { homeTopImg: [ "https://cdn.luogu.com.cn/upload/image_hosting/clcd8ydf.png", "https://cdn.luogu.com.cn/upload/image_hosting/clcd8ydf.png" ], }

卡常技巧

超级快读快些

- 火车头

link1

link2

据CF896E的数据来测试,几乎一样的速度。

- Fast IO !!!

具体见:

https://www.luogu.com.cn/blog/gsczl71/syxqwq-que-xing-yuan-kuai-du-kuai-xie

https://www.luogu.com.cn/blog/gsczl71/kuai-du-kuai-xie-my-que-xing-yuan

- 前置++ 与 --

- 连续访问空间

例如;

for(int i  = 1;i <= n;i++)for(int j = 1;j <= n;j++)a[i][j];

for(int i  = 1;i <= n;i++)for(int j = 1;j <= n;j++)a[j][i];

快2~3倍。

- register 放在变量名前

- inline 放在函数名前

- short 换 int

- long long 换 int

注意:long long 从头慢到脚趾尖

- 位运算

将 % 2 换成 &1

÷2 换成 >> 1

×2 换成 << 1

17 % 2 可写成 17 & 1,45 % 4 可写成 45 & 3, 986 % 16 可写成 986 & 15。

- if换成三目

- 声明常数

- ;换成,

玄学

- bool 换成 int

玄学+1

- 循环展开

for(int i=1;i<=n;++i)
    a=1,b=1;

改成

for(int i=1;i<=n;++i)a=1;
for(int i=1;i<=n;++i)b=1;

- 换掉x=-x

改成:

i = ~i + 1; // NOT 写法
i = (i ^ -1) + 1; // XOR 写法

- x++改成x=-~x;

- x=1<<y; 求2^y

维度大的放前面

如:

int dp[100000][10][2];

手写algorithm里的函数,手写%

我的缺省源

参考文献:

https://blog.csdn.net/sight_720/article/details/122919247?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522170036496616800197074121%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=170036496616800197074121&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_click~default-2-122919247-null-null.142v96control&utm_term=%E5%8D%A1%E5%B8%B8&spm=1018.2226.3001.4187

https://blog.csdn.net/weixin_49652016/article/details/107967580?ops_request_misc=%257B%2522request%255Fid%2522%253A%2522170036496616800197074121%2522%252C%2522scm%2522%253A%252220140713.130102334..%2522%257D&request_id=170036496616800197074121&biz_id=0&utm_medium=distribute.pc_search_result.none-task-blog-2alltop_positive~default-1-107967580-null-null.142v96control&utm_term=%E5%8D%A1%E5%B8%B8&spm=1018.2226.3001.4187

https://blog.csdn.net/m0_60950850/article/details/122827327?ops_request_misc=&request_id=&biz_id=102&utm_term=%E5%8D%A1%E5%B8%B8&utm_medium=distribute.pc_search_result.none-task-blog-2allsobaiduweb~default-1-122827327.142v96control&spm=1018.2226.3001.4187

posted @ 2023-11-24 19:36  gsczl71  阅读(42)  评论(0编辑  收藏  举报