10分钟以为能切掉的一道水题,直接9WA,哪位巨佬帮忙看一下

P1767 家族

数据类型规范很重要 ```cpp #include<bits/stdc++.h> using namespace std; struct F{ int x; int y; }; queue<F>q; const int N=1003; int a[N][N];//用int存储,原理我也不知道 bool p[N][N]; int num=0;//建议,数据类型统一,最好不要写unsigned int int n; int dir[4][2]={{1,0},{-1,0},{0,1},{0,-1}};//这里写错了,不建议使用short int main(){ p[0][0]=0; string h; cin >> n; getline(cin,h); for(int i=1;i<=n;i++){ getline(cin,h); a[i][0]=h.length()-1;//在洛谷中会多读一个换行符,我也不知道为什么,因为我一般写getchar for(int j=1;j<=a[i][0];j++){ a[i][j]=h[j-1]; int A=a[i][j]; if(A==32||A==42)p[i][j]=1; } }//i竖j横x竖y横 for(int i=1;i<=n;i++){ for(int j=1;j<=a[i][0];j++){ if(p[i][j]==0){ p[i][j]=1; q.push({i,j}); while(!q.empty()){ int xx=q.front().x; int yy=q.front().y; q.pop(); for(int k=0;k<4;k++){//并不是错误,只是建议使用不重复的变量 int tx=xx+dir[k][0]; int ty=yy+dir[k][1]; if(tx>=1&&tx<=n&&ty>=1&&ty<=a[tx][0]&&p[tx][ty]==0){ p[tx][ty]=1; q.push({tx,ty}); } } } num++; } } } cout<<num<<endl;; return 0; } ```
by BigSmall_En @ 2022-09-25 16:51:14


@[BigSmall_En](/user/360491) [评测记录](https://www.luogu.com.cn/record/87561690)
by BigSmall_En @ 2022-09-25 16:52:16


@[BigSmall_En](/user/360491) A掉了,蟹蟹啦
by qwq666666 @ 2022-09-25 17:32:12


|