网页资讯视频图片知道文库贴吧地图采购
进入贴吧全吧搜索

 
 
 
日一二三四五六
       
       
       
       
       
       

签到排名:今日本吧第个签到,

本吧因你更精彩,明天继续来努力!

本吧签到人数:0

一键签到
成为超级会员,使用一键签到
一键签到
本月漏签0次!
0
成为超级会员,赠送8张补签卡
如何使用?
点击日历上漏签日期,即可进行补签。
连续签到:天  累计签到:天
0
超级会员单次开通12个月以上,赠送连续签到卡3张
使用连续签到卡
07月17日漏签0天
c++吧 关注:624,476贴子:2,112,315
  • 看贴

  • 图片

  • 吧主推荐

  • 游戏

  • 0回复贴,共1页
<<返回c++吧
>0< 加载中...

C++进入函数错误,求大犇帮忙

  • 只看楼主
  • 收藏

  • 回复
  • 神楽坂真羽
  • <
    11
该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
#include<queue>
#include<climits>
#include<fstream>
using namespace std;
ifstream cin( "ni.in" );ofstream cout( "ni.out" );
const int MAP_MAX = 1000 + 10;
struct siteType
{
int x;
int y;
};
int h = 0;
int w = 0;
int ans = INT_MAX;
siteType ni = {0};
siteType start = {0};
siteType f[4] = {0};
int map[MAP_MAX][MAP_MAX] = {0};
queue< siteType > olive;
void init();
void work();
void bfs(siteType & site);
void outit();
int main()
{
init();
work();
outit();
return 0;
}
void init()
{
siteType temp = {0};
f[0].x = 1;
f[1].y = 1;
f[2].x = -1;
f[3].y = -1;
cin >> w >> h;
for (temp.x = 0; temp.x != h; ++temp.x)
for (temp.y = 0; temp.y != w; ++temp.y)
{
cin >> map[temp.x][temp.y];
if (map[temp.x][temp.y] == 2)
start = temp;
if (map[temp.x][temp.y] == 3)
ni = temp;
if (map[temp.x][temp.y] == 4)
olive.push(temp); }
}
void work()
{
while (!olive.empty())
{
siteType site = olive.front();
//这个位置BUG,进入函数bfs出错
bfs(site);
olive.pop();
}
}
void bfs(siteType & site)
{
int step[MAP_MAX][MAP_MAX] = {0};
queue< siteType > team;
team.push(site);
while (!team.empty())
{
siteType now = team.front();
team.pop();
for (int i = 0; i != 4; ++i)
{
siteType temp = now;
cout << endl;
temp.x += f[i].x;
temp.y += f[i].y;
if ((temp.x < 0) || (temp.y < 0) || (temp.x >= h) || (temp.y >= w))
continue;
if (map[temp.x][temp.y] == 1)
continue;
if (step[temp.x][temp.y])
continue;
step[temp.x][temp.y] = step[now.x][now.y] + 1;
team.push(temp);
}
}
if ((step[start.x][start.y] + step[ni.x][ni.y]) < ans)
ans = step[start.x][start.y] + step[ni.x][ni.y];
cout << ans << endl;
}
void outit()
{
cout << ans << endl;
}
/*编辑器是DEV-C++5.4.1,进入bfs函数的位置出错,求大犇帮忙看看原因。。。*/


登录百度账号

扫二维码下载贴吧客户端

下载贴吧APP
看高清直播、视频!
  • 贴吧页面意见反馈
  • 违规贴吧举报反馈通道
  • 贴吧违规信息处理公示
  • 0回复贴,共1页
<<返回c++吧
分享到:
©2025 Baidu贴吧协议|隐私政策|吧主制度|意见反馈|网络谣言警示