“师创杯”精英赛G---限额逃生2(BFS)---已AC+错误分析

AI权益加码!Claude Code、Cursor等20+工具免费用! 购周边限时加赠Coding Plan Lite,畅享主流AI工具!学习进阶更高效! 阅读详情

Problem G: G-险恶逃生II

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 27   Solved: 5
[ Submit][ Status][ Web Board]

Description

    SOS!!!koha is trapped in the dangerous maze.He need your help again.
    The maze is a 2D grid consisting of n rows and m columns. Each cell in the maze may have a stone or may
be occupied by zero or more monsters. The cell that has a stone Koha(including the monsters) cannot enter. Only one of the cells is designated as the exit cell.
    Kona,including the monsters may move in the maze.In a single move,each of them may perform one of the Following actions:
    1. do nothing
    2. move from the current cell to one of the four adjacent cells.
    3. if Koha is located on the exit cell, he may leave the maze. Only he can perform this move — all Monsters will never leave the maze by using this type of movement.
    After each time Kona makes a single move,each of the monsters simultaneously make a single move ,however the choice of which move to make may be different for each of the monsters.
 
    If koha and x(x>0) monsters are located on the same cell, exactly x monsters will ensue that time(since he will be battling each of those x breeders once).After the battle, all of those x monsters will be killed.
    Now,Koha would like to leave the maze,however the monsters will all know his exact sequence of moves even before he makes his first move.All of them will move in such way that will guarentee a monster battle with Koha,if possible. The monsters that couldn't battle him will do nothing.
 
    All right.Your task is to print the mininum number of monster battles that kona must participates in,note that you are not required to minimize the number of moves kona makes.

Input

For each case,the first line consists of two integes: n and m(1<=n,m<=1000),denoting the number of rows and the number of columns in the maze.the next n rows will echo depict a row of the map,where each character represents the content of a single cell:
'T':A cell occupied by a stone.
'S':An empty cell,and Kona's starting position.
'E':An empty cell,and where the exit is located.
A digit(0-9): A cell represented by a digit x means that the cell is empty and is occupied by x monsters(if x is zero,it means the cell is not occupied by any monsters).
 
It is guaranteed that it will be possible for Kona to leave the maze.

Output

For each case,ouput a single line denoted the mininum possible number of monster battles that koha has to participate in if you pick a strategy that minimize this number.

Sample Input

5 7
000E0T3
T0TT0T0
010T0T0
2T0T0T0
0T0S000
1 4
SE23

Sample Output

3
2

HINT

For the second case,kona and the monsters located in (0,2) will reach

the exit cell simultaneously ,so he must kill them.








AC代码:

#include <iostream>
#include <cstring>
#define size 1000

using namespace std;
char map[1011][1011];
int res[1011][1011];
int x1,x2,y1,y2,n,m;
struct point
{
    int x,y;
} r[size*size+11];
int dis[4][2]= {{1,0},{-1,0},{0,1},{0,-1}};
void dfs()
{
    int i,tail,head,xx,yy,x11,y11;
    memset(res,-1,sizeof(res));
    res[x1][y1]=0;
    r[0].x=x1;
    r[0].y=y1;
    tail=1;
    head=0;
    while(tail != head)
    {
        x11=r[head].x;
        y11=r[head].y;
        for(i=0; i<4; i++)
        {
            xx=x11+dis[i][0];
            yy=y11+dis[i][1];
            if(map[xx][yy]!='T'&&res[xx][yy]==-1)
            {
                r[tail].x=xx;
                r[tail].y=yy;
                res[xx][yy] = 1 + res[x11][y11];
                tail++;
            }
        }
        head++;
    }

}
int main()
{
    int i,j;
    int num,max=0;
    while(cin>>m>>n)
    {
        for(i=0; i<=n+1; i++)
            map[0][i]=map[m+1][i]='T';
        for(i=0; i<=m+1; i++)
            map[i][0]=map[i][n+1]='T';
        for(i=1; i<=m; i++)
            for(j=1; j<=n; j++)
            {
                cin>>map[i][j];
                if(map[i][j]=='E')
                {
                    x1=i;
                    y1=j;
                }
                if(map[i][j]=='S')
                {
                    x2=i;
                    y2=j;
                }
            }
        dfs();
        num=res[x2][y2];
        max=0;
        for(i=1; i<=m; i++)
            for(j=1; j<=n; j++)
                if(map[i][j]>'0'&&map[i][j]<='9')
                    if(res[i][j]<=num&&res[i][j]!=-1)
                    max+=map[i][j]-'0';
        cout<<max<<endl;
    }
    return 0;
}



针对4楼前博文代码未AC原因分析:

   第一次错误提示 :

                                正确输出:0,我的输出:36


                                 分析,从错误原因来看,应当是没有考虑到特殊情况造成的,仔细考虑后发现,由于在广度搜索中用 -1打表,所以在怪兽找不到出口时,当前的表格数据为-1.然而却符合了if(map[i][j]>'0'&&map[i][j]<='9'&& res[i][j]<=num)的判断,于是在判断中多加了个&&res[i][j]!=-1.   特殊情况解决,进行特殊情况测试数据正确,于是将代码提交。但是!!!!更加腚疼的问题又来了~~~ ---runtime error!!!,估计是访问越界数组开小了,在周童辉大神的帮助分析下 发现 果真 点坐标开小了,于是果断把r[1011]开到了 r[1011*1011],成功AC~~~



2017哈理工低年级组院赛初赛 D-逃脱 【一个贼墨迹的bfs 时间限制:C/C++ 1秒,其他语言2秒 空间限制:C/C++ 32768K,其他语言65536K 64bit IO Format: %lld 题目描述  这是mengxiang000和Tabris来到幼儿园的第四天,幼儿园老在值班的时候突然发现幼儿园某处发生火灾,而且火势蔓延极快,老在第一时间就发出了警报,位于幼儿园某处的mengxiang000和Tabris听到了火 阅读详情

相关推荐

HDU-OJ---N皇后问题(DFS)

Problem D Time Limit : 2000/1000ms (Java/Other)   Memory Limit : 32768/32768K (Java/Other) Total Submission(s) : 7   Accepted Submission(s) : 4 Font: Times New Roman | Verdana | Georgia Font Siz

不会吃鱼的喵 1398

探秘Codeforces EduHacking:一款代码竞赛辅助工具

探秘Codeforces EduHacking:一款代码竞赛辅助工具 CodeforcesEduHacking???? Codeforces Edu & Div. 3 Open hacking项目地址:https://gitcode.com/gh_mirrors/co/CodeforcesEduHacking 项目简介 是一个面向编程学习者和爱好者的开源项目,由开发者im0qianqian建。它的主...

gitblog_00077的博客 675

YTU---2887-机器人Bill

2887: D--机器人Bill Time Limit: 1 Sec  Memory Limit: 128 MB Submit: 88  Solved: 11 [Submit][Status][Web Board] Description 最近,Dr. Jiang 新设计一个机器人Bill。Bill很聪明,会做许多事情。唯独对质数的理解与人类不一样,它是从右往左读数。比如,它看到

不会吃鱼的喵 665

Linux下管理腾龙镜头:开源CLI工具实现固件更新与参数调校

USB设备通信与硬件控制是嵌入式开发与设备管理中的常见需求,而命令行工具为自动化操作提供了高效路径。通过libusb库,主机可以直接与USB外设交互,无需额外的图形界面或中间层。这种设计不仅降低了资源占用,还让脚本化批量处理成为可能。在摄影器材领域,许多专业镜头的参数配置和固件更新长期依赖Windows或macOS专用软件,Linux用户往往面临设备无法管理的困境。本文将介绍一款开源CLI工具,它利用Python和libusb在Linux环境下实现腾龙镜头的连接、参数读取、自定义设置修改及固件更新,帮助摄影

weixin_30411819的博客 390

UVA - 11624 - Fire!(BFS逃生问题)

题目链接 题意: 在迷宫内,J表示人,F表示火,火可能不止一处,但是人只有一个,火会向上下左右蔓延, 蔓延速度和人移动速度一至(每次一格,但是可以同时向四个方向)问是否可以成功逃出迷宫, 不能输出IMPOSSIBLE,能的画话输出最短路径。 题解: 每步先让火走–然后人走其他的路–就可以保证人不会被火烧了 先将火入队列最后将人入队列,走的时候判断下是人还是火,如果是人的话看看是否无路可走 注...

Anoyer的博客 340

山东ACM省赛酱油记

ACM省赛酱油记     比赛结束许久了,但一直没能静下心写点感想。直到昨天,集训队的所有队员集聚一堂,包括已经考上研的集训队第一批学长学姐,一起谈了谈多年的ACM经历、感受与收获,感触良多,又在今天看到了学长的总结,觉得我也应该打开word大干一番了。

不会吃鱼的喵 1686

山东省ACM竞赛(2015)---H - Square Number

Square Number Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 In mathematics, a square number is an integer that is the square of an integer. In other words, it is the product of

不会吃鱼的喵 1550

四川省ACM竞赛(2013)---G-Good Numbers(规律/可DP)

G - Good Numbers Time Limit:1000MS    Memory Limit:32768KB    64bit IO Format:%I64d & %I64u SubmitStatusPracticeHDU 4722 Description If we sum up every digit of a number and the result c

不会吃鱼的喵 1422

HDU---1480-钥匙计数之二

钥匙计数之二 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 1019    Accepted Submission(s): 579 Problem Description 一把钥匙有N个槽,2<N<26槽深为1,2,3,

不会吃鱼的喵 1089

四川省ACM竞赛(2013)---K - Kia's Calculation

K - Kia's Calculation Time Limit:1000MS    Memory Limit:32768KB    64bit IO Format:%I64d & %I64u SubmitStatus Description Doctor Ghee is teaching Kia how to calculate the sum of two integers

不会吃鱼的喵 883

山东省ACM竞赛(2015)---B - Lowest Unique Price

Lowest Unique Price Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Recently my buddies and I came across an idea! We want to build a website to sell things in a new way. For ea

不会吃鱼的喵 767

四川省ACM竞赛(2013)---E - Naive and Silly Muggles

E - Naive and Silly Muggles Time Limit:1000MS    Memory Limit:32768KB    64bit IO Format:%I64d & %I64u SubmitStatus Description Three wizards are doing a experiment. To avoid from bothering,

不会吃鱼的喵 752

HDU---5437-Alisha’s Party(优先队列)(2015 Changchun)

Alisha’s Party Problem Description Princess Alisha invites her friends to come to her birthday party. Each of her friends will bring a gift of some value v, and all of them will come

不会吃鱼的喵 693

福州大学第十二届程序设计竞赛 B.完美的数字(2191)

Problem 2191 完美的数字 Accept: 46 Submit: 139 Time Limit: 1000 mSec Memory Limit : 32768 KB Problem Description Bob是个很喜欢数字的孩子,现在他正在研究一个与数字相关的题目,我们知道一个数字的完美度是 把这个数字分解成三个整数相乘A*A*B(0 S,S表示的是从a

不会吃鱼的喵 682

POJ-2142-The Balance(扩展欧几里得)

A B C D E F G H B - The Balance Crawling in process... Crawling failed Time Limit:5000MS     Memory Limit:65536KB     64bit IO Format:%I64d & %I64u Submit Status Description

不会吃鱼的喵 673

山东省ACM竞赛(2010)---Balloons(BFS

Balloons Time Limit: 1000ms   Memory limit: 65536K  有疑问?点这里^_^ 题目描述 Both Saya and Kudo like balloons. One day, they heard that in the central park, there will be thousands of

不会吃鱼的喵 673

浙江省ACM竞赛(2013)---B - Break Standard Weight(DFS)

B - Break Standard Weight Time Limit:2000MS     Memory Limit:65536KB     64bit IO Format:%lld & %llu Submit Status Practice ZOJ 3706 Description The balance was the first mass measurin

不会吃鱼的喵 641

C语言怎么样?难学吗?

其实C语言并没有想象中的那么难,很多人刚开始接触时觉得很难是因为之前没有接触过类似这样的课程,其实它就是一门语言而已,只不过是给机器使用的,所以刚开始一般人的思维转不过来

qq2227918581的博客 198
上一篇: 2015-第6周项目4-成员函数、友元函数和一般函数有区别
下一篇: 2015-第6周项目5-友元类
EIKY
博客等级 码龄12年 46粉丝 397原创
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值