目錄
- 前言
- exe檔案鏈接
- 使用說明
- 代碼
- 后記
- 其他碎碎念
前言
今天和室友一起玩開心拼一拼的時候,一不小心我倆一起卡關了,于是本蒟蒻一怒之下跑去寫了個攻略形的外掛(顯示出過關的詳細步驟),如果有卡關的可以下載exe檔案取用該攻略
exe檔案鏈接
鏈接:https://pan.baidu.com/s/1l09rLR57OFe9SW1FCrovCg
提取碼:0jh5
使用說明
使用的圖片如下:

輸入的內容如下:
9
藍 淺藍 草綠 淺藍
藍 紅 草綠 紫
灰 紫 藍 藍
紅 粉 橙 綠
灰 綠 粉 紅
橙 綠 綠 草綠
草綠 灰 紫 紅
紫 灰 粉 橙
橙 淺藍 淺藍 粉
2
說明:需要按照提示輸入當前關卡的有顏色的試管數量、每個試管的顏色、空試管的數量
注意:我玩的版本將試管分為了四塊,不知道會不會有其余版本的,該攻略僅適用于分為四塊顏色的試管
代碼
#define _CRT_SECURE_NO_WARNINGS
#include<iostream>
#include<stack>
#include<algorithm>
#include<map>
#include<vector>
#include<queue>
using namespace std;
const int maxn = 1000;
stack<int>st[maxn];
stack<int>tmp;
int num[maxn];
int book[maxn];
map<string, int>mp;
int n, m, tot, cnt,wc;
vector<int>path;
int win() {
int res = 0;
int flag = 0;
memset(book, 0, sizeof(book));
for (int i = 1; i <= tot; i++) {
flag = 0;
if (st[i].size() < 4) {
continue;//不滿,肯定不符合
}
while (!st[i].empty()) {
int fr = st[i].top();
tmp.push(fr);
st[i].pop();
if (!st[i].empty() && fr != st[i].top()) {
flag = 1;//不滿足
}
}
while (!tmp.empty()) {
st[i].push(tmp.top());
tmp.pop();
}
if (!flag)book[i] = 1, res++;
}
return res;
}
void dfs(int last, int to) {
int ans = win();
if (ans == n) {
for (int i = 0; i + 1 < path.size(); i += 2) {
printf("將第%d個試管倒入%d\n", path[i], path[i + 1]);
}
printf("已完成\n");
wc = 1;
return;//已完成
}
if (wc)return;
for (int i = 1; i <= tot; i++) {
if (!st[i].size())continue;//是空的
if (book[i])continue;//當前已完成
int si = st[i].size();
int fr = st[i].top();
st[i].pop();
int ne = 1;
while (!st[i].empty() && st[i].top() == fr) {//算出可以移動的數量
ne++;
st[i].pop();
}
int same = 0;
if (ne == si) {//一個試管,同色,標記一下
same = 1;
}
for (int j = 1; j <= tot; j++) {
if (last == j && to == i) {//和上一次操作是反操作
continue;
}
if (i == j)continue;//是同一個
if (num[j] == 4)continue;//滿了
if (same && num[j] == 0)continue;//沒必要把同色試管倒進空試管
int to;
if (!st[j].empty()) {//非空,判斷是否能倒
to = st[j].top();
}
else {//空的,可以倒
to = fr;
}
if (fr == to) {//同色,可以倒
int nu = 4 - num[j];
if (nu < ne)continue;//要去的不夠當前要倒的,沒必要倒
for (int k = 1; k <= ne; k++) {
st[j].push(fr);
}
num[j] += ne;
num[i] -= ne;
path.push_back(i);
path.push_back(j);
dfs(i, j);
path.pop_back();//回溯
path.pop_back();
num[j] -= ne;
num[i] += ne;
for (int k = 1; k <= ne; k++) {
st[j].pop();
}
}
else {
continue;//繼續下一個
}
}
for (int k = 1; k <= ne; k++) {//回溯
st[i].push(fr);
}
}
}
void init() {
memset(num, 0, sizeof(num));
path.clear();
for (int i = 1; i < maxn; i++) {
while (!st[i].empty())st[i].pop();
}
mp.clear();
wc = 0;
}
int main() {
cnt = 0;
string col;
while (1) {
init();
printf("請輸入有顏色的試管數量:");
scanf("%d", &n);
for (int i = 1; i <= n; i++) {
num[i] = 4;
printf("請從下往上輸入第%d個試管的四個顏色:", i);
for (int j = 1; j <= 4; j++) {
cin >> col;
if (mp.find(col) == mp.end()) {
mp[col] = ++cnt;
}
st[i].push(mp[col]);
}
}
printf("請輸入空試管數量:");
scanf("%d", &m);
tot = n + m;
dfs(-1, -1);
}
return 0;
}
后記
目前我測驗的關卡沒有出現BUG,不知道會不會有其余的關卡出現BUG,如果有還請各位大佬評論區指出QAQ
——蒟蒻的第十篇博客
(翻了翻之前的博客,發現最后一篇是半年前我剛好在學爆搜的時候??)
其他碎碎念
暴力出奇跡,爆搜出攻略!
中秋快樂(▽)
2021-9-20 23:49
轉載請註明出處,本文鏈接:https://www.uj5u.com/qita/302041.html
標籤:其他
上一篇:Python_繪制影像
