Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

Re:洛谷上测WA了两个数据点,大佬帮忙看下

Posted by 2537732688 at 2021-01-15 14:08:32 on Problem 2386
In Reply To:洛谷上测WA了两个数据点,大佬帮忙看下 Posted by:Socialxingjj at 2019-02-26 23:47:56
> #include<bits/stdc++.h>
> using namespace std;
> int dx[9]={0,-1,-1,0,1,1,1,0,-1};
> int dy[9]={0,0,-1,-1,-1,0,1,1,1};
> struct zuobiao
> {
> 	int xx,yy;
> }q[1002];
> int h,t,a,b;
> int g[1003][1003],vis[1003][1003];
> int n,m;
> 
> void BFS(int x,int y)
> {
> 	q[1].xx=x;
> 	q[1].yy=y;
> 	h=0;
> 	t=1;
> 	while(h<t)
> 	{
> 		h++;
> 		x=q[h].xx;
> 		y=q[h].yy;
> 		g[x][y]=0;
> 		for(int i=1;i<=8;i++)
> 		{
> 			a=x+dx[i];
> 			b=y+dy[i];
> 			if(g[a][b]==1&&vis[a][b]==0)
> 			{
> 				t++;
> 				q[t].xx=a;
> 				q[t].yy=b;
> 				vis[a][b]=1;
> 			}
> 		}
> 	} 
> }
> 
> int main()
> {
> 	memset(vis,0,sizeof(vis));
> 	memset(q,0,sizeof(q));
> 	memset(g,0,sizeof(g));
> 	char s[1003];
> //	while()!=EOF)
> //	{
> 	scanf("%d%d",&n,&m);
> 		for(int i=1;i<=n;i++)
> 		{
> 			scanf("%s",&s);
> 			for(int j=0;j<=m-1;j++)
> 			{
> 				if(s[j]=='W') g[i][j+1]=1;
> 			}
> 		}
> 		int ans=0;
> 		for(int i=1;i<=n;i++)
> 			for(int j=1;j<=m;j++)
> 				if(g[i][j]==1)
> 				{
> 					BFS(i,j);
> 					ans++;
> 					memset(q,0,sizeof(q));
> 				}
> 		printf("%d",ans);
> //	}
> 	
> 	return 0;
> }

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator