跳到正文

题解

题解:P11925 [PA 2025] 显像管 / Migawka

xh_1020约 5 分钟
原文
文章信息与版本

文章信息

发布
2026年9月17日
收录
2026年9月21日
更新
2026年10月25日
篇幅
约 5 分钟
获赞
1
题目
P11925

版本

  1. v1当前

我一看这道题是 Special Judge,一想肯定有很多解,但是我在各种尝试下只发现了一种。

Part 1

这道题是构造题,但是开始时,我不知怎个构造,所以写出了以下代码。

C++
#include <bits/stdc++.h>
using namespace std;
int main () {
    srand((time(0)));
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            cout << rand()%2;
        }
        cout << "\n";
    }
    return 0;
}

我用的是随机数,结果 00 分了。

这个很复杂,但因为太乱导致大量错误块抵消,反而缩短了总步数。

然后我又想到了规则图形。

三角形。

C++
#include <bits/stdc++.h>
using namespace std;
int main () {
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            cout << (i+j<100)?1:0;
        }
        cout << "\n";
    }
    return 0;
}

传递一遍就死不行了。

对角线。

C++
#include <bits/stdc++.h>
using namespace std;
int main () {
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            if(i==j) cout << 1;
            else cout << 0;
        }
        cout << "\n";
    }
    return 0;
}

和三角形差不多。

国际象棋棋盘。

C++
#include <bits/stdc++.h>
using namespace std;
int main () {
    for(int i=1;i<=100;i++){
        for(int j=1;j<=100;j++){
            if(i%2==0){
                if(j%2==0) cout << 1;
                else cout << 0;
            }else{
                if(j%2==0) cout << 0;
                else cout << 1;
            }
        }
        cout << "\n";
    }
    return 0;
}

只有两种,一定不行的。

Part 2

经过一番折腾,我发现随机和规则图形都走不通。随机太乱,状态会抵消。规则图形容易陷入重复死循环。

所以既然要长,且反复地跑。这种东西还真有!!!

我们先看最普通的。

C++
1 0
0 1

翻转后变成。

C++
0 1
1 0

如果我们要让它跑一行,就把他多复制几遍。

C++
1 0 0 0 0 0
0 1 1 1 1 1

变成。

C++
0 0 0 0 0 1
1 1 1 1 1 0

如果想传下去,就得在下一行放个传递的连接器。

C++
0 0 0 0 0 1
1 1 1 1 1 0
0 0 0 0 0 1

再变成。

C++
0 0 0 0 0 1
0 1 1 1 1 1
1 0 0 0 0 0

再放一行。

C++
0 0 0 0 0 1
0 1 1 1 1 1
1 0 0 0 0 0
0 1 1 1 1 1

然后你会发现这是按照 S 形走的,走完一遍又有一遍,错误块的数量非常多。

所以得到以下 AC 代码。

C++
#include <bits/stdc++.h>
using namespace std;
int main () {
    for(int i=1;i<=100;i++){
        if(i==1){
            cout << 1;
            for(int j=1;j<=99;j++) cout << 0;
        }else if(i%2==0){
            cout << 0;
            for(int j=1;j<=99;j++) cout << 1;
        }else{
            for(int j=1;j<=99;j++) cout << 0;
            cout << 1;
        }
        cout << "\n";
    }
    return 0;
}
原文