跳到正文

休闲·娱乐

样例没过,废了?NoNoNo...

wjh123bcc约 2 分钟
原文
文章信息与版本

文章信息

发布
2025年2月23日
收录
2025年12月12日
更新
2026年8月17日
篇幅
约 2 分钟

版本

  1. v1当前

我今天上午在做usaco的题

当我写完bfs后发现样例没过,便进入了令人痛苦的调试环节,(有大佬看出问题吱一声),一调调到了下课,我就打算交一下(我用的学校机房电脑),结果得了73分,不信的交下试试,代码如下:

C++
#include <bits/stdc++.h>
using namespace std;
const int N=105;
int n,m,xx,yy;
int dis[N][N];
char a[N][N];
int dx[8]={1,0,0,-1,1,1,-1,-1};
int dy[8]={0,1,-1,0,1,-1,1,-1};
struct node
{
	int x,y;
};
int main()
{
	queue<node> q;
    cin>>n>>m>>xx>>yy;
    memset(dis,-1,sizeof(dis));
	for(int i=n;i>=1;i--)
	{
		for(int j=m;j>=1;j--)
		{
			cin>>a[i][j];
		    if(i==xx&&j==yy)
		    {
		    	dis[xx][yy]=0;
				a[i][j]='#';
				q.push({xx,yy});
			}
		}
	}
	int i=0;
	while(q.empty()==false)
	{
		node u=q.front();
		q.pop();
		int x=u.x,y=u.y;
	    for(int i=0;i<8;i++)
	    {
	    	int nx=x+dx[i],ny=y+dy[i];
	    	if(nx>=1&&nx<=n&&ny>=1&&ny<=m&&a[nx][ny]!='*'&&a[nx][ny]!='#')
	    	{
	    		a[nx][ny]='#';
	    		dis[nx][ny]=dis[x][y]+1;
				q.push({nx,ny});
			}
		}
	}
	int maxx=-1;
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
		    maxx=max(maxx,dis[i][j]);
		}
	}
	cout<<maxx;
	return 0;
}
原文