0% found this document useful (0 votes)
67 views9 pages

新建 文本文档

Uploaded by

mrd200476
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
67 views9 pages

新建 文本文档

Uploaded by

mrd200476
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 9

https://twinkaboo.

com/videos/kinky-blond-femboy-explodes-on-cam-for-you-7deeb021

https://cutedeadguys.net/threads/big-brazil-collection.67709/page-89

https://cutedeadguys.net/threads/naked-autoerotic-hangings.71463/
https://cutedeadguys.net/threads/young-hot-twin-brothers-shot-to-death.21584/
https://cutedeadguys.net/forums/death-images.6/page-201
https://cutedeadguys.net/threads/hanging-collection-part-1.21/page-315
https://cutedeadguys.net/threads/nice-looking-19-yo-jonata-sobrinho-felled-by-
twleve-bullets-in-his-bed.32915/
https://cutedeadguys.net/threads/dead-chinese-dudes.624/
https://cutedeadguys.net/forums/death-images.6/page-101
https://cutedeadguys.net/tags/dick/
https://cutedeadguys.net/threads/beautiful-athlete-hanged-himself-naked-in-texas-
real-case.71136/
nightalks.com
https://cutedeadguys.net/threads/strip-the-bodies-of-rivals.71394/

https://cutedeadguys.net/tags/boy/page-5
https://cutedeadguys.net/threads/drowning-collection-part-1.25/page-8
https://cutedeadguys.net/threads/nice-looking-19-yo-jeferson-passos-
executado.35971/
#include <limits>
https://pixhost.to/gallery/JQllf
https://cutedeadguys.net/tags/nude/page-2
https://cutedeadguys.net/tags/dead-naked/
https://cutedeadguys.net/threads/big-brazil-collection.67709/page-45
#include <vector>
#include <queue>
#include <variant>
#include <stack>
#include <functional> // 用于 std::function
#include <type_traits>
// 0 1 2 4 3 6 5 8 7
using namespace std;
int fact[] = {1,1,2,6,24,120,720,5040,40320};
https://cutedeadguys.net/tags/asian/page-3
https://cutedeadguys.net/threads/new-drowning-collection.32484/page-4
//康托展开
int cantor(int board[]) {
int ans = 0;
int i = 0;
while (i < 9) {
int a = 0;
for (int j = i + 1; j < 9; ++j) {
if (board[i] > board[j]) a++;
}
ans += a * fact[8 - i];
i++;
}
return ans;
}

//逆康托展开
void rev_cantor(int num, int board[]) {
vector<int> vec;

for (int i = 0; i < 9; i++) {


vec.push_back(i);
}
for (int i = 0; i < 9; i++) {
int pos = num / fact[8 - i];
board[i] = vec[pos];
vec.erase(vec.begin() + pos);
num %= fact[8 - i];
}
}

//使用逆序数判断是否有解
bool access(int board1[], int board2[]) {
int n1 = 0, n2 = 0;

// 处理 board1
for (int i = 0; i < 9; i++) {
for (int j = i + 1; j < 9; j++) {
if (board1[i] != 0 && board1[j] != 0 && board1[i] > board1[j]) {
n1++;
}
}
}
// 处理 board2
for (int i = 0; i < 9; i++) {
for (int j = i + 1; j < 9; j++) {
if (board2[i] != 0 && board2[j] != 0 && board2[i] > board2[j]) {
n2++;
}
}
}
// 判断两个逆序数是否同为奇数或偶数
return (n1 % 2) == (n2 % 2);
}

//搜索树结点
struct Node {
Node(int n = 0, Node* p1 = NULL, Node* p2 = NULL, int g = 0) :
num(n), self(p1), parent(p2), G(g), H(0) {
if (g > 0) {
//计算启发函数值
int goal_pos[9][2] = { {1, 1}, {0, 0}, {0, 1}, {0, 2}, {1, 2}, {2, 2},
{2, 1}, {2, 0}, {1, 0} };
int board[9];
rev_cantor(num, board);
for (int i = 0; i < 9; i++) {
int x = i / 3, y = i % 3;
H += abs(x - goal_pos[board[i]][0]) + abs(y - goal_pos[board[i]]
[1]);
}
}
}
bool operator<(const Node& node) const {
return (this->G + this->H) > (node.G + node.H);
}
int num; //康托展开值
int G; //初始结点到当前结点的代价(当前结点深度)
int H; //当前结点到目标结点的代价(曼哈顿距离)
Node* self;
Node* parent;
static int goal[9];
};

int Node::goal[9] = { 1, 2, 3, 8, 0, 4, 7, 6, 5 };

//输入
void input(int board[]) {
int flag[9];
bool valid;

do {
valid = true; // 重置有效性检查
cout << "input:" << endl;
for (int i = 0; i < 9; ++i)
flag[i] = 0;
for (int i = 0; i < 9; ++i) {
cin >> board[i];
if (board[i] >= 0 && board[i] < 9) {
++flag[board[i]];
if (flag[board[i]] > 1) {
cout << "Error input! Duplicate values are not allowed." <<
endl;
valid = false; // 标记为无效输入
break; // 提前退出当前输入循环
}
} else {
cout << "Error input! Please enter values between 0 and 8." <<
endl;
valid = false; // 标记为无效输入
break;
}
}
// 清除输入流中的多余字符,避免影响下一次输入
if (!valid) {
cin.clear(); // 重置输入流状态
cin.ignore(numeric_limits<streamsize>::max(), '\n');
}
} while (!valid); // 如果输入无效,重新进行输入
}

//输出
void output(Node node) {
vector<Node> ans;
// 收集从目标状态到初始状态的路径
while (node.parent) {
ans.push_back(node);
node = *(node.parent);
}
cout << ans.size() << " step(s):" << endl;
// 逆序输出路径
for (int i = ans.size() - 1; i >= 0; i--) {
cout << "------" << endl;
int board[9];
rev_cantor(ans[i].num, board);

// 输出当前状态的棋盘
for (int j = 0; j < 3; j++) {
for (int k = 0; k < 3; k++) {
cout << board[3 * j + k] << ' ';
}
cout << endl;
}
}
}

bool visited[362880] = { false };

//BFS 移动函数
void mov_Check(int board[], int pos, int move, queue<Node>& Q, Node* parent) {
swap(board[pos], board[pos + move]);
int num = cantor(board);
if (!visited[num]) {
Node* node_ptr = new Node(num, NULL, parent);
node_ptr->self = node_ptr;
Q.push(*node_ptr);
visited[num] = true;
}
swap(board[pos], board[pos + move]);
}

//DFS 移动函数
bool moveAndCheckDFS(int board[], int pos, int move, stack<Node>& S, Node* parent,
int& depth) {
swap(board[pos], board[pos + move]);
int num = cantor(board);
if (!visited[num]) {
Node* node_ptr = new Node(num, NULL, parent);
node_ptr->self = node_ptr;
S.push(*node_ptr);
visited[num] = true;
--depth;
swap(board[pos], board[pos + move]);
return true; // 表示移动并添加了新节点
}
swap(board[pos], board[pos + move]);
return false; // 表示没有移动或添加新节点
}

//A*移动函数
void moveAndCheckAStar(int board[], int pos, int move, priority_queue<Node>& Q,
Node* parent, int G) {
swap(board[pos], board[pos + move]);
int num = cantor(board);
if (!visited[num]) {
Node* node_ptr = new Node(num, NULL, parent, G + 1);
node_ptr->self = node_ptr;
Q.push(*node_ptr);
visited[num] = true;
}
swap(board[pos], board[pos + move]);
}
//终止查找函数重载
void finalizeSearch(Node& node, const string& searchMethod, clock_t start,
queue<Node>& dataStructure) {
clock_t end = clock();
cout << searchMethod << ": " << "time = " << end - start << "ms, ";
output(node);

while (!dataStructure.empty()) {
delete dataStructure.front().self;
dataStructure.pop();
}
}

void finalizeSearch(Node& node, const string& searchMethod, clock_t start,


stack<Node>& dataStructure) {
clock_t end = clock();
cout << searchMethod << ": " << "time = " << end - start << "ms, ";
output(node);

while (!dataStructure.empty()) {
delete dataStructure.top().self;
dataStructure.pop();
}
}

void finalizeSearch(Node& node, const string& searchMethod, clock_t start,


priority_queue<Node>& dataStructure) {
clock_t end = clock();
cout << searchMethod << ": " << "time = " << end - start << "ms, ";
output(node);

while (!dataStructure.empty()) {
delete dataStructure.top().self;
dataStructure.pop();
}
}

//初始化函数
template<typename T>
pair<T, Node*> initializeSearch(int Board[], int& ans, clock_t& start) {
int board[9];
for (int i = 0; i < 9; i++) // 后置++
board[i] = Board[i];

start = clock(); // 记录开始时间

ans = cantor(Node::goal); // 计算目标状态的康托展开值


for (int i = 0; i < 362880; i++)
visited[i] = false; // 初始化 visited 数组为 false

T dataStructure; // 初始化模板类型的搜索数据结构
Node* node_ptr = new Node(cantor(board), NULL, NULL); // 创建初始节点
node_ptr->self = node_ptr; // 设置 self 指针指向自己
dataStructure.push(*node_ptr); // 将初始节点推入数据结构
visited[dataStructure.front().num] = true; // 标记初始节点已访问
return { dataStructure, node_ptr }; // 返回数据结构和节点指针
}

//广度优先搜索
void BFS(int Board[]) {
int board[9];
for (int i = 0; i < 9; i++)
board[i] = Board[i];

clock_t start, end;


start = clock();

int ans = cantor(Node::goal);


for (int i = 0; i < 362880; i++)
visited[i] = false;

vector<Node> tree;
queue<Node> Q;
Node* node_ptr = new Node(cantor(board), NULL, NULL);
node_ptr->self = node_ptr;
Q.push(*node_ptr);
visited[Q.front().num] = true;

while (!Q.empty()) {
Node node = Q.front();
Q.pop();
tree.push_back(node);

if (node.num == ans) {
finalizeSearch(node, "BFS", start, Q);
break;
}

rev_cantor(node.num, board);
int pos = 0;
for (/**/; board[pos] != 0; pos++);
int row = pos / 3;
int col = pos % 3;

if (col > 0) mov_Check(board, pos, -1, Q, node.self); // 左移


if (row > 0) mov_Check(board, pos, -3, Q, node.self); // 上移
if (col < 2) mov_Check(board, pos, +1, Q, node.self); // 右移
if (row < 2) mov_Check(board, pos, +3, Q, node.self); // 下移
}
}

//有界深度优先搜索
void DFS(int Board[], int d) {
int board[9];
for (int i = 0; i < 9; i++)
board[i] = Board[i];

clock_t start, end;


start = clock();
int depth = d;
int ans = cantor(Node::goal);
for (int i = 0; i < 362880; i++)
visited[i] = false;

vector<Node> tree;
stack<Node> S;
Node* node_ptr = new Node(cantor(board), NULL, NULL);
node_ptr->self = node_ptr;
S.push(*node_ptr);
visited[S.top().num] = true;

while (!S.empty()) {
if (depth < 0) {
depth++;
tree.push_back(S.top());
S.pop();
continue;
}

Node node = S.top();

if (node.num == ans) {
finalizeSearch(node, "DFS", start, S);
break;
}

rev_cantor(node.num, board);
int pos = 0;
for (/**/; board[pos] != 0; pos++);
int row = pos / 3;
int col = pos % 3;

// 使用 moveAndCheckDFS 函数处理四个方向的移动
if (col > 0 && moveAndCheckDFS(board, pos, -1, S, node.self, depth))
continue; // 左移
if (row > 0 && moveAndCheckDFS(board, pos, -3, S, node.self, depth))
continue; // 上移
if (col < 2 && moveAndCheckDFS(board, pos, +1, S, node.self, depth))
continue; // 右移
if (row < 2 && moveAndCheckDFS(board, pos, +3, S, node.self, depth))
continue; // 下移

depth++;
tree.push_back(S.top());
S.pop();
}

if (depth == d + 1) {
for (int i = tree.size() - 1; i >= 0; i--)
delete tree[i].self;
cout << "No solution at current depth!" << endl;
}
}

//A*算法
void Astar(int Board[]) {
int board[9];
for (int i = 0; i < 9; i++)
board[i] = Board[i];

clock_t start, end;


start = clock();

int ans = cantor(Node::goal);


for (int i = 0; i < 362880; i++)
visited[i] = false;

vector<Node> tree;
priority_queue<Node> Q;
Node* node_ptr = new Node(cantor(board), NULL, NULL, 0);
node_ptr->self = node_ptr;
Q.push(*node_ptr);
visited[Q.top().num] = true;

while (!Q.empty()) {
Node node = Q.top();
Q.pop();
tree.push_back(node);

if (node.num == ans) {
finalizeSearch(node, "A*", start, Q);
break;
}

rev_cantor(node.num, board);
int pos = 0;
for (/**/; board[pos] != 0; pos++);
int row = pos / 3;
int col = pos % 3;

// 使用 moveAndCheckAStar 函数处理四个方向的移动
if (col > 0) moveAndCheckAStar(board, pos, -1, Q, node.self, node.G); // 左移
if (row > 0) moveAndCheckAStar(board, pos, -3, Q, node.self, node.G); // 上移
if (col < 2) moveAndCheckAStar(board, pos, +1, Q, node.self, node.G); // 右移
if (row < 2) moveAndCheckAStar(board, pos, +3, Q, node.self, node.G); // 下移
}
}
int main() {
//int board[] = { 2 8 3 1 0 4 7 6 5 }; //test
//int board[] = { 2 1 6 4 0 8 7 5 3 }; //test
int board[9];
char ch = 'y'; // 初始化一个默认值,进入循环

while (ch != 'q') { // 如果用户输入 'q',退出循环


input(board); // 获取初始状态输入

if (access(board, Node::goal)) { // 判断是否可达


cout << "Starting BFS..." << endl;
BFS(board); // 宽度优先搜索
cout << endl;

int depth = 10; // 默认深度


cout << "Enter depth for DFS (default 10): ";
cin >> depth;
cout << "Starting DFS with depth " << depth << "..." << endl;
DFS(board, depth); // 深度优先搜索
cout << endl;

cout << "Starting A*..." << endl;


Astar(board); // 启发式搜索
cout << endl;
} else {
cout << "No solution exists for the given board!" << endl;
}

// 提示用户是否继续或退出
cout << "Press 'q' to exit, or any other key to continue:" << endl;
cin.ignore(numeric_limits<streamsize>::max(), '\n'); // 清空缓冲区
cin >> ch; // 读取用户输入
}
return 0;
}
286 SDN
322

You might also like