杂谈:某煞笔挑战图灵机停机问题的珍贵记录
yuyang0974 · · 科技·工程
题目相关
Link
1RB1LC_1RC---_0LD1RE_0LA1LD_0RF0RB_0LC1RE
1RB1LF_1RC1LB_0RD1RD_1LE0RC_0LE1LA_0LB---
1RB0RF_1RC1LB_0RD1RD_1LE0RC_0LE1LA_---1RA
1RB1LC_0RC0RB_1LD0LA_1LE---_1LF0LA_1RB1LE
1RB1RC_1LC1RE_1RA0LD_1LC1LB_0RF1LC_---1RB
1RB0LE_0RC0RA_0LD1RF_1RE---_1LA0LF_0LB0RD
1RB1RA_1LC0LF_0RE1LD_0LB0LC_1RA0LE_---0RA
1RB0RA_0LC1RA_1RE1LD_1LC0LD_---0RB_------
1LB0LB_0LC0RF_0LD0LA_0RE---_1RE0RA_1RF1LA
1LB0LF_0RC0LA_1RA0LD_1LE1RE_1RC1LC_---1RB
提交的代码(15 pts)
#include<bits/stdc++.h>
using namespace std;
#define tp template<typename T>
#define tpp template<typename T, typename ...T1>
#define tpvoid tp void
#define tppvoid tpp void
#define bug(x) {cout << #x":" << x << " ";}
#define _n {putchar('\n');}
#define _b {putchar(' ');}
#define _t(x) {cout << x;}
tpvoid read(T &x) {
x = 0;
char c = getchar(), f = 'a';
while(c < '0' || c > '9') {
if(!(c ^ '-')) f = 'b';
c = getchar();
}
while(c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + (c ^ '0');
c = getchar();
}
if(f ^ 'a') x = -x;
}
tppvoid read(T &x, T1 &...x1) {read(x); read(x1...);}
tpvoid write(T x) {
if(x < 0) {
putchar('-');
x = -x;
}
if(x > 9) write(x / 10);
putchar(x % 10 + '0');
}
const char dir[10] = {'X', 'X', 'X', 'X', 'H', 'X', 'X', 'X', 'X', 'X'};
int main() {
//freopen("P1452_1.in", "r", stdin);
//freopen("mex.in", "r", stdin);
//freopen("mex.out", "w", stdout);
for(int i = 0; i < 10; i ++) {
putchar(dir[i]);
putchar('\n');
}
return 0;
}
测试图灵机的代码
#include<bits/stdc++.h>
using namespace std;
#define tp template<typename T>
#define tpp template<typename T, typename ...T1>
#define tpvoid tp void
#define tppvoid tpp void
#define bug(x) {cout << #x":" << x << " ";}
#define _n {putchar('\n');}
#define _b {putchar(' ');}
#define _t(x) {cout << x;}
tpvoid read(T &x) {
x = 0;
char c = getchar(), f = 'a';
while(c < '0' || c > '9') {
if(!(c ^ '-')) f = 'b';
c = getchar();
}
while(c >= '0' && c <= '9') {
x = (x << 1) + (x << 3) + (c ^ '0');
c = getchar();
}
if(f ^ 'a') x = -x;
}
tppvoid read(T &x, T1 &...x1) {read(x); read(x1...);}
tpvoid write(T x) {
if(x < 0) {
putchar('-');
x = -x;
}
if(x > 9) write(x / 10);
putchar(x % 10 + '0');
}
int n;
// L -> 0, R -> 1
// A -> 0, B -> 1, C -> 2, D -> 3, E -> 4, F -> 5
int opt = 0;
const int table[10][6][2][3] = {
{ // 1
{
1, 1, 1,
1, 0, 2,
},
{
1, 1, 2,
-1, -1, -1,
},
{
0, 0, 3,
1, 1, 4,
},
{
0, 0, 0,
1, 0, 3,
},
{
0, 1, 5,
0, 1, 1,
},
{
0, 0, 2,
1, 1, 4,
},
},
{ // 2
{
1, 1, 1,
1, 0, 5,
},
{
1, 1, 2,
1, 0, 1,
},
{
0, 1, 3,
1, 1, 3,
},
{
1, 0, 4,
0, 1, 2,
},
{
0, 0, 4,
1, 0, 0,
},
{
0, 0, 1,
-1, -1, -1,
},
},
{ // 3
{
1, 1, 1,
0, 1, 5,
},
{
1, 1, 2,
1, 0, 1,
},
{
0, 1, 3,
1, 1, 3,
},
{
1, 0, 4,
0, 1, 2,
},
{
0, 0, 4,
1, 0, 0,
},
{
-1, -1, -1,
1, 1, 0,
},
},
{ // 4
{
1, 1, 1,
1, 0, 2,
},
{
0, 1, 2,
0, 1, 1,
},
{
1, 0, 3,
0, 0, 0,
},
{
1, 0, 4,
-1, -1, -1,
},
{
1, 0, 5,
0, 0, 0,
},
{
1, 1, 1,
1, 0, 4,
},
},
{ // 5
{
1, 1, 1,
1, 1, 2,
},
{
1, 0, 2,
1, 1, 4,
},
{
1, 1, 0,
0, 0, 3,
},
{
1, 0, 2,
1, 0, 1,
},
{
0, 1, 5,
1, 0, 2,
},
{
-1, -1, -1,
1, 1, 1,
},
},
{ // 6
{
1, 1, 1,
0, 0, 4,
},
{
0, 1, 2,
0, 1, 0,
},
{
0, 0, 3,
1, 1, 5,
},
{
1, 1, 4,
-1, -1, -1,
},
{
1, 0, 0,
0, 0, 5,
},
{
0, 0, 1,
0, 1, 3,
},
},
{ // 7
{
1, 1, 1,
1, 1, 0,
},
{
1, 0, 2,
0, 0, 5,
},
{
0, 1, 4,
1, 0, 3,
},
{
0, 0, 1,
0, 0, 2,
},
{
1, 1, 0,
0, 0, 4,
},
{
-1, -1, -1,
0, 1, 0,
},
},
{ // 8
{
1, 1, 1,
0, 1, 0,
},
{
0, 0, 2,
1, 1, 0,
},
{
1, 1, 4,
1, 0, 3,
},
{
1, 0, 2,
0, 0, 3,
},
{
-1, -1, -1,
0, 1, 1,
},
{
-1, -1, -1,
-1, -1, -1,
},
},
{ // 9
{
1, 0, 1,
0, 0, 1,
},
{
0, 0, 2,
0, 1, 5,
},
{
0, 0, 3,
0, 0, 0,
},
{
0, 1, 4,
-1, -1, -1,
},
{
1, 1, 4,
0, 1, 0,
},
{
1, 1, 5,
1, 0, 0,
},
},
{ // 10
{
1, 0, 1,
0, 0, 5,
},
{
0, 1, 2,
0, 0, 0,
},
{
1, 1, 0,
0, 0, 3,
},
{
1, 0, 4,
1, 1, 4,
},
{
1, 1, 2,
1, 0, 2,
},
{
-1, -1, -1,
1, 1, 1,
},
}
};
#define out(q, s) table[opt][q][s][0]
#define dir(q, s) table[opt][q][s][1]
#define nxt(q, s) table[opt][q][s][2]
const int maxn = 5e7 + 5;
char s_fu[maxn], s_zheng[maxn];
int pl_fu, pl_zheng;
#define s(pl) ((pl) >= 0 ? s_zheng[(pl)] : s_fu[-(pl) - 1])
void maintain(int pl) {
if(pl >= 0 && pl > pl_zheng) {
pl_zheng = pl;
s_zheng[pl + 1] = '\0';
}
else if(pl < 0 && -pl - 1 > pl_fu) {
pl_fu = -pl - 1;
s_fu[pl_fu + 1] = '\0';
}
}
typedef long long ll;
ll cnt;
void output(int cur) {
printf("turn %lld\ncur:%c\ns_fu: %s\ns_zheng:%s\n\n", cnt, (char)('A' + cur), s_fu, s_zheng);
}
void Error() {
printf("break!\nturn %lld\npl_fu:%d\npl_zheng:%d", cnt, pl_fu, pl_zheng);
}
int OP = 0;
int l[15], r[15];
void Delete(int x) {
r[l[x]] = r[x];
l[r[x]] = l[x];
}
int main() {
//freopen("P1452_1.in", "r", stdin);
//freopen("mex.in", "r", stdin);
//freopen("mex.out", "w", stdout);
r[10] = 0;
l[10] = -1;
l[0] = 10;
r[0] = 1;
for(int i = 1; i < 9; i ++) {
r[i] = i + 1;
l[i] = i - 1;
}
l[9] = 8;
r[9] = 11;
l[11] = 9;
r[11] = -1;
int res = 10;
ll TIM = 51200000000LL;
ll tim;
Delete(4);
while(res) {
printf("depth:%lld\n", TIM);
int sta = r[10];
while(sta < 10) {
printf("testing %d...", sta + 1);
opt = sta;
int cur = 0, pl = 0;
pl_zheng = -1, pl_fu = -1;
s_zheng[0] = '\0';
s_fu[0] = '\0';
cnt = 0;
//output(0);
cnt ++;
int q, s;
tim = TIM;
while(tim --) {
q = cur;
if(s(pl) == '0') s = 0;
else if(s(pl) == '1') s = 1;
else s = 0;
if(out(q, s) == -1) {
Error();
Delete(sta);
res --;
break;
}
s(pl) = (char)('0' + out(q, s));
maintain(pl);
if(dir(q, s)) pl ++;
else pl --;
cur = nxt(q, s);
//output(cur);
cnt ++;
}
putchar('\n');
sta = r[sta];
}
TIM <<= 1;
putchar('\n');
}
return 0;
}