我一看这道题是 Special Judge,一想肯定有很多解,但是我在各种尝试下只发现了一种。
Part 1
这道题是构造题,但是开始时,我不知怎个构造,所以写出了以下代码。
#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;
}我用的是随机数,结果 分了。
这个很复杂,但因为太乱导致大量错误块抵消,反而缩短了总步数。
然后我又想到了规则图形。
三角形。
#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;
}传递一遍就死不行了。
对角线。
#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;
}和三角形差不多。
国际象棋棋盘。
#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
经过一番折腾,我发现随机和规则图形都走不通。随机太乱,状态会抵消。规则图形容易陷入重复死循环。
所以既然要长,且反复地跑。这种东西还真有!!!
我们先看最普通的。
1 0
0 1翻转后变成。
0 1
1 0如果我们要让它跑一行,就把他多复制几遍。
1 0 0 0 0 0
0 1 1 1 1 1变成。
0 0 0 0 0 1
1 1 1 1 1 0如果想传下去,就得在下一行放个传递的连接器。
0 0 0 0 0 1
1 1 1 1 1 0
0 0 0 0 0 1再变成。
0 0 0 0 0 1
0 1 1 1 1 1
1 0 0 0 0 0再放一行。
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 代码。
#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;
}