测试点2:
6
- 0 0 1 1 1 0
- 1 1 1 0 1 0
- 1 0 0 0 0 1
- 1 1 0 1 1 1
- 0 1 0 1 0 0
- 0 1 1 1 0 0
by 1901吴昊 @ 2021-10-12 22:07:02
你跟我的思路还挺像的,贴一下我的AC代码吧(滑稽
```cpp
#include<bits/stdc++.h>
using namespace std;
int a[31][31],n;
int pd(int x,int y)
{
int i,j;
for(j=y;j<=n;j++)
if(a[x][j]==1)
return 1;
return 0;
}
int pd2(int x,int y)
{
int i,j;
for(i=x;i<=n;i++)
if(a[i][y]==1)
return 1;
return 0;
}
int pd3(int x,int y)
{
int i,j;
for(i=x;i>=1;i--)
if(a[i][y]==1)
return 1;
return 0;
}
int pd4(int x,int y)
{
int i,j;
for(j=y;j>=1;j--)
if(a[x][j]==1)
return 1;
return 0;
}
int check(int x,int y)
{
if(a[x][y]==2 && (a[x+1][y]==0 || a[x][y+1]==0 || a[x-1][y]==0 || a[x][y-1]==0))
return 1;
return 0;
}
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int i,j;
cin>>n;
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
cin>>a[i][j];
for(i=2;i<=n;i++)
{
int flag=0;
for(j=1;j<=n;j++)
{
int x=0;
if(flag==2 && a[i][j]==1 && a[i][j-1]!=1)
flag=0;
if(flag==0 && a[i][j]==1)
flag=2;
else if(flag==2 && a[i][j]!=1 && i<n && j<n)
if(pd(i,j)==1 && pd2(i,j)==1 && pd3(i,j)==1 && pd4(i,j)==1)
a[i][j]=2;
}
}
for(i=1;i<=n;i++)
for(j=1;j<=n;j++)
if(check(i,j)==1)
a[i][j]=0;
for(i=1;i<=n;i++)
{
for(j=1;j<=n;j++)
cout<<a[i][j]<<" ";
cout<<endl;
}
return 0;
}
```
我已经尽力压行了,但还是这么长~~鬼知道我下载了多少测试点~~,因为这题踩得点太多了。。。
by queen_street @ 2021-10-13 19:57:51
@[1901吴昊](https://www.luogu.com.cn/user/253453)
by queen_street @ 2021-10-13 19:58:37
@[游走的灵魂](/user/284521)
我是认为一旦一个围起来的空间,它一定会有1个开始的1和一个结束的1出现在同一行内~~当然这两可以是同一个~~
```
1 1 1
1 0 1
1 1 1
```
这样才可能是封闭空间,我的代码就基于这个
by 1901吴昊 @ 2021-10-22 22:33:22
az
by queen_street @ 2021-10-24 21:46:44
@[1901吴昊](/user/253453) 如果出现
00000000
01100110
10011001
10010001
11111111
这样的情况呢?
by splendid_followers @ 2022-03-04 12:43:02
测试点4 :
```
输入
20
0 0 0 0 1 1 1 0 0 0 0 1 1 1 0 0 0 0 0 0
0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0
0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0
0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0
0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0
0 0 0 0 1 0 1 0 0 0 0 1 0 1 0 0 0 0 0 0
1 1 1 1 1 0 1 1 1 1 1 1 0 1 0 0 0 0 0 0
1 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 0 0 0 0 1 1 1 1 1 1 1
0 0 0 0 0 0 0 0 1 0 0 0 0 0 0 0 0 0 0 1
0 0 0 0 0 0 0 0 1 0 1 1 1 1 0 0 0 1 1 1
0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 1 0 0
0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 0 0 0 0
0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 0 0 0 0
0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1
0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 0 0 0 0 1
0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 1 1 1 1
0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 0 0 0 0
0 0 0 0 0 0 0 0 1 0 1 0 0 1 0 1 0 0 0 0
0 0 0 0 0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