用户输出
4
1222
1424
3242
4344
系统信息
Exited with return code 0
编号 | 题目 | 状态 | 分数 | 总时间 | 内存 | 代码 / 答案文件 | 提交者 | 提交时间 |
---|---|---|---|---|---|---|---|---|
#20456 | #1045. mm逗黑白猫 | Accepted | 100 | 85 ms | 2296 K | C++ 11 / 2.4 K | q3540555 | 2019-07-22 15:24:26 |
#include <map>
#include <set>
#include <ctime>
#include <cmath>
#include <queue>
#include <stack>
#include <vector>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define spause() system("pause")
using namespace std;
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> prdd;
typedef map<int, int> mpdd;
const int dinf = 0x7fffffff;
const llong llinf = 0x7fffffffffffffff;
const int way[24] = { 49152, 34816, 24576, 17408, 12288, 8704, 4352, 3072, 2176, 1536, 1088, 768,
544, 272, 192, 136, 96, 68, 48, 34, 17, 12, 6, 3 };
const int wayop[24] = { 1112, 1121, 1213, 1222, 1314, 1323, 1424, 2122, 2131, 2223, 2232, 2324,
2333, 2434, 3132, 3141, 3233, 3242, 3334, 3343, 3444, 4142, 4243, 4344 };
const int ways[24][2] = { { 15, 14 }, { 15, 11 }, { 14, 13 }, { 14, 10 }, { 13, 12 }, { 13, 9 },
{ 12, 8 }, { 11, 10 }, { 11, 7 }, { 10, 9 }, { 10, 6 }, { 9, 8 },
{ 9, 5 }, { 8, 4 }, { 7, 6 }, { 7, 3 }, { 6, 5 }, { 6, 2 },
{ 5, 4 }, { 5, 1 }, { 4, 0 }, { 3, 2 }, { 2, 1 }, { 1, 0 } };
struct wy {
int st = -1;
string w;
};
int from, to, tsp;
wy sve[65540];
vector<int> bfs, tmp;
int bin2dec(int bn) {
const int pws[4] = { 1, 10, 100, 1000 };
int ans = 0;
for (int i = 3; i >= 0; i--)
if (bn >= pws[i]) {
bn -= pws[i];
ans += 1 << i;
}
return ans;
}
int main() {
for (int i = 0; i < 4; i++) {
int orgs;
scanf("%d", &orgs);
from += bin2dec(orgs) << (12 - 4 * i);
}
for (int i = 0; i < 4; i++) {
int orgs;
scanf("%d", &orgs);
to += bin2dec(orgs) << (12 - 4 * i);
}
// llong starttime = clock();
bfs.push_back(from);
sve[from].st = 0;
while (!bfs.empty()) {
for (int i = 0; i < bfs.size(); i++) {
int ts = bfs.at(i);
for (int j = 0; j < 24; j++)
if ((ts >> ways[j][0] & 1) != (ts >> ways[j][1] & 1)) {
int np = bfs.at(i) ^ way[j];
if (sve[np].st == -1) {
sve[np].st = sve[ts].st + 1;
sve[np].w = sve[ts].w + char(j);
tmp.push_back(np);
} else if (sve[np].st == sve[ts].st + 1)
sve[np].w = min(sve[np].w, sve[ts].w + char(j));
}
}
if (sve[to].st != -1) {
printf("%d\n", sve[to].st);
for (int i = 0; i < sve[to].w.length(); i++) printf("%d\n", wayop[sve[to].w.at(i)]);
break;
}
swap(bfs, tmp);
tmp.clear();
}
// cout << "Debug info: " << clock() - starttime << "ms passed\n";
spause();
return 0;
}
用户输出
4
1222
1424
3242
4344
系统信息
Exited with return code 0
用户输出
3
1323
3242
2232
系统信息
Exited with return code 0
用户输出
6
1112
1314
1323
2333
3132
4142
系统信息
Exited with return code 0
用户输出
9
1213
1112
1314
1213
2232
2223
2434
3343
3444
系统信息
Exited with return code 0
用户输出
11
1112
1323
2131
1121
2232
2333
2324
3141
3132
3343
2333
系统信息
Exited with return code 0
用户输出
7
2131
2122
2333
1323
1314
3141
3132
系统信息
Exited with return code 0
用户输出
15
1213
1112
1314
2333
2223
2122
2434
1424
3141
3242
2232
3343
2333
3444
2434
系统信息
Exited with return code 0
用户输出
14
1424
1314
1213
1112
2232
1222
2333
2223
2434
3141
3242
3343
2333
3444
系统信息
Exited with return code 0
用户输出
10
1121
2223
2122
2333
2434
3141
3242
3343
4344
4243
系统信息
Exited with return code 0