额~编译错误~

来源:百度知道 编辑:UC知道 时间:2024/05/29 15:40:36
程序为:
#include<stdio.h>

int min(int b,int d)
{
if(b>d) return d;
else return b;
}

void yunsuan(char **a,int **c,int m,int n,int i,int j)
{
if(i-1>=0&&a[i-1][j]!='*')
{
if(c[i-1][j]==0)
c[i-1][j]=1;
else c[i-1][j]=min(c[i][j]+1,c[i-1][j]);
yunsuan(a,c,m,n,i-1,j);
}
if(i+1<=m&&a[i+1][j]!='*')
{
if(c[i+1][j]==0)
c[i+1][j]=1;
else c[i+1][j]=min(c[i][j]+1,c[i+1][j]);
yunsuan(a,c,m,n,i+1,j);
}
if(j-1>=0&&a[i][j-1]!='*')
{
if(c[i][j-1]==0)
c[i][j-1]=1;

强制类型转换,将调用语句改写为:
yunsuan((char**)a,(int**)c,m[i],n[i],p1,p2);

根据你的题目要求我也写了一个宽搜的,你看看能不能AC:
#include <cstdio>
#include <string>
#include <queue>
using namespace std;

const int MAXN = 101;
const int NIL = -1;

int forward[][2] = { { 0, 1}, { 0, -1}, { 1, 0}, { -1, 0}};

bool map[MAXN][MAXN], visited[MAXN][MAXN];
char input[MAXN];
int start_x, start_y, end_x, end_y, row, col, p_time;

int bfs(){
int i, j, k, x, y, p, q, step = 0;
queue<int> fifo;
for(i = 0; i < row; i++){
for(j = 0; j < col; j++) visited[i][j] = false;
}
fifo.push(start_x);
fifo.push(start_y);
fifo.push(NIL);
fifo.push(NIL);
visited[start_x][start_y] = true;
while(!fifo.empty()){
x = fifo.front();
fifo.pop();
y = fifo.front();
fifo.pop();
if(x == NIL && y == NIL){
step++;
if(!fifo.em