技巧
考试技巧
随机数
生产 \(50\) 个 \(1-50\) 的随机数:
#include<bits/stdc++.h>
using namespace std;
signed main ()
{
ios::sync_with_stdio(false);
cin.tie(0) , cout.tie(0);
mt19937 rnd(random_device{}());
uniform_int_distribution<>rd(1,50);
for ( int i = 1 ; i <= 50 ; i ++ ) cout << rd(rnd) << endl;
return 0;
}
如果不想用 \(uniform\) 也可以用下面这种写法:
#include<bits/stdc++.h>
using namespace std;
signed main ()
{
ios::sync_with_stdio(false);
cin.tie(0) , cout.tie(0);
mt19937 rnd(random_device{}());
for ( int i = 1 ; i <= 50 ; i ++ ) cout << rnd() % 50 + 1 << endl;
return 0;
}
linux命令
cd [dirname]
进入某个文件夹
ls -l
列举所有文件夹信息
mkdir [dirname]
在当前目录下建立某个文件夹
touch a.cpp
在当前目录下新建 \(a.cpp\) 文件
编译选项
g++ a.cpp -o a
将 \(a.cpp\) 中的内容输入到 \(a\) 可执行文件中
./a
运行 \(a\) 文件
-O2/O3
开启优化
-Wall -Wextra
全部/额外警告
-std=c++14
使用 c++\(14\) 标准
-fsanitize=address,undefined
绝佳的查 \(RE\) 和 \(UB\) 的方法
-ftrapv
检查是否爆 \(int\) 或者 \(long\ long\)
输出空间和时间
#include<bits/stdc++.h>
using namespace std;
const int N = 1e7 + 5;
bool ms;
int a[N];
bool mt;
signed main ()
{
ios::sync_with_stdio(false);
cin.tie(0) , cout.tie(0);
for ( int i = 1 ; i <= 1e7 ; i ++ ) a[i] = 1;
cerr << (double)( &ms - &mt ) / 1048576.0 << "MB" << endl;
cerr << 1e3*clock()/CLOCKS_PER_SEC << "ms" << endl;
return 0;
}