AcWing 842. 排列数字(DFS)
# 排列数字 - 深度优先遍历 DFS
#include <iostream>
using namespace std;
const int N = 1e6 + 10;
int n;
int path[N];
bool st[N];
void dfs(int u){
if(u == n){
for(int i = 0; i < n; i++) printf("%d ", path[i]);
puts("");
return;
}
/
more...AcWing 843. n-皇后问题
# N 皇后问题 - DFS
#include <iostream>
using namespace std;
const int N = 20;
int n;
char g[N][N];
bool col[N], dg[N], udg[N];
void dfs(int u){
if(u == n){
for(int i = 0; i < n; i++) puts(g[i]);
puts("");
return;
}
for(int i = 0; i
more...AcWing 844. 走迷宫(BFS)
# 走迷宫 - BFS
#include <iostream>
#include <algorithm>
#include <cstring>
using namespace std;
typedef pair<int, int> PII;
const int N = 110;
int n, m;
int g[N][N];
int d[N][N];
PII q[N * N];
int bfs(){
int hh = 0, tt = 0;
q[0] = {0, 0}
more...随机函数randomshuffle和排序函数sort
#include <iostream>
#include <algorithm>
#include <vector>
#include <ctime>//一般是可以把时间传进去当成一个随机种子
using namespace std;
// bool cmp(int a, int b){ //a是否应该排在b的前面
// return a < b; //如果a < b的话 a就应该排在b的前面
/
more...常用库函数排列sort使用结构体定义
#include <iostream>
#include <algorithm>
#include <vector>
#include <ctime>
using namespace std;
struct Rec{
int x, y;
bool operator< (const Rec &t) const{//这个operator背过就可以了 语法来的//operator<就是重载<如果operator>就是重载大于号
more...





