好用的函数/算法

· · 个人记录

1,shuffle函数

用于随机化,随机打乱数组下标。示例:

#include<bits/stdc++.h>
using namespace std;
const int N=1e4+10;
int b[N];
int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n=10;
    for(int i=1;i<=n;i++)b[i]=i;
    shuffle(b+1,b+n+1,mt19937(time(0)));
    for(int i=1;i<=n;i++)cout<<b[i]<<" ";
    return 0;
}

2,__int128

__int128 read(){
    __int128 x=0,h=1;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        if(ch=='-')h=-1;
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<3)+(x<<1)+ch-'0';
        ch=getchar();
    }
    return x*h;
}
void write(__int128 x){
    if(!x)return;
    write(x/10);
    putchar(x%10+'0');
}

3,对拍

#include<bits/stdc++.h>
using namespace std;
int main(){
    while(1){
        system("data.exe > in.txt");
        system("baoli.exe < in.txt > out.txt");
        system("std.exe < in.txt > ans.txt");
        if(system("fc out.txt ans.txt"))break;
    }

    return 0;
}