跳到正文

个人记录

好用的函数/算法

Fire_flys约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年8月10日
收录
2025年12月12日
更新
2026年9月10日
篇幅
约 2 分钟

版本

  1. v2当前
  2. v1

1,shuffle函数

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

C++
#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

C++
__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,对拍

C++
#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;
}
原文