P6909 运行不出来求助
  • 板块灌水区
  • 楼主vvautedSN第一魔怔人
  • 当前回复2
  • 已保存回复2
  • 发布时间2021/5/16 22:36
  • 上次更新2023/11/4 23:09:32
查看原帖
P6909 运行不出来求助
486187
vvautedSN第一魔怔人楼主2021/5/16 22:36
#include <iostream>
#include <stdio.h>
#include <queue>
#include <algorithm>
using namespace std;
long long min(long long a,long long b) {return a>b?b:a;}
int r,c;
char a[55][55];
bool mk[55][55];
const int hx[]={0,-1,0,0,1};
const int hy[]={0,0,1,-1,0};
string s;
struct node{ 
	int cnt,h_f,x,y;
};
queue <node> q;
long long int minx=10000000000000; 
inline void bfs()
{
	node fs;fs.x=1;fs.y=1;fs.h_f=0;fs.cnt=0;
	if(a[fs.x][fs.y]==s[0]) fs.cnt++;fs.h_f++;
	q.push(fs);
	while(!q.empty())
	{
		node now=q.front();
		q.pop();
		mk[now.x][now.y]=1;
		for(int i=1;i<5;i++)
		{
			bool ouj=0; 
			node next=now;next.cnt++;
			while(a[now.x][now.y]==a[next.x][next.y])
			{
				if(next.x>c&&next.y>r){ouj=1;break;}
				next.x+=hx[i];
				next.y+=hy[i]; 
			}
			if(ouj) continue;
			if(!mk[next.x][next.y])
			{
				if(a[next.x][next.y]==s[next.h_f])
				{
					if(next.h_f+1==s.length())
					{
						minx=min(minx,next.cnt+1);
						continue;
					}  
					else
					{
						next.cnt++;
						next.h_f++;
					}
				}
				q.push(next);
			}
		}
	}
}
int main()
{
	//输入部分 
	scanf("%d%d",&r,&c);
	for(int i=1;i<=r;i++)
		for(int k=1;k<=c;k++)
		{
			char p;
			p=getchar();
			if(p=='\n') p=getchar();
			a[i][k]=p;
		}
	getchar();
	getline(cin,s);
	//
	bfs();
	printf("%lld",minx);
}

一运行就出错,应该是语法问题,求神犇帮我找一下,我眼角膜捐掉了

2021/5/16 22:36
加载中...