Codeforces 330D Biridian Forest【思维+Bfs】

本文介绍了一个迷宫逃脱问题,玩家需要找到一条通往出口的路径,同时尽量减少与敌人的战斗次数。通过从终点进行广度优先搜索(BFS),计算每个敌人到达出口的最短步数,并据此确定最少遭遇敌人的策略。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

D. Biridian Forest
time limit per test
2 seconds
memory limit per test
256 megabytes
input
standard input
output
standard output

You're a mikemon breeder currently in the middle of your journey to become a mikemon master. Your current obstacle is go through the infamous Biridian Forest.

The forest

The Biridian Forest is a two-dimensional grid consisting of r rows and c columns. Each cell in Biridian Forest may contain a tree, or may be vacant. A vacant cell may be occupied by zero or more mikemon breeders (there may also be breeders other than you in the forest). Mikemon breeders (including you) cannot enter cells with trees. One of the cells is designated as the exit cell.

The initial grid, including your initial position, the exit cell, and the initial positions of all other breeders, will be given to you. Here's an example of such grid (from the first example):

Moves

Breeders (including you) may move in the forest. In a single move, breeders may perform one of the following actions:

  • Do nothing.
  • Move from the current cell to one of the four adjacent cells (two cells are adjacent if they share a side). Note that breeders cannot enter cells with trees.
  • If you are located on the exit cell, you may leave the forest. Only you can perform this move — all other mikemon breeders will never leave the forest by using this type of movement.

After each time you make a single move, each of the other breeders simultaneously make a single move (the choice of which move to make may be different for each of the breeders).

Mikemon battle

If you and t (t > 0) mikemon breeders are located on the same cell, exactly t mikemon battles will ensue that time (since you will be battling each of those t breeders once). After the battle, all of those t breeders will leave the forest to heal their respective mikemons.

Note that the moment you leave the forest, no more mikemon battles can ensue, even if another mikemon breeder move to the exit cell immediately after that. Also note that a battle only happens between you and another breeders — there will be no battle between two other breeders (there may be multiple breeders coexisting in a single cell).

Your goal

You would like to leave the forest. In order to do so, you have to make a sequence of moves, ending with a move of the final type. Before you make any move, however, you post this sequence on your personal virtual idol Blog. Then, you will follow this sequence of moves faithfully.

Goal of other breeders

Because you post the sequence in your Blog, the other breeders will all know your exact sequence of moves even before you make your first move. All of them will move in such way that will guarantee a mikemon battle with you, if possible. The breeders that couldn't battle you will do nothing.

Your task

Print the minimum number of mikemon battles that you must participate in, assuming that you pick the sequence of moves that minimize this number. Note that you are not required to minimize the number of moves you make.

Input

The first line consists of two integers: r and c (1 ≤ r, c ≤ 1000), denoting the number of rows and the number of columns in Biridian Forest. The next r rows will each depict a row of the map, where each character represents the content of a single cell:

  • 'T': A cell occupied by a tree.
  • 'S': An empty cell, and your starting position. There will be exactly one occurence of this in the map.
  • 'E': An empty cell, and where the exit is located. There will be exactly one occurence of this in the map.
  • A digit (0-9): A cell represented by a digit X means that the cell is empty and is occupied by X breeders (in particular, if X is zero, it means that the cell is not occupied by any breeder).

It is guaranteed that it will be possible for you to go from your starting position to the exit cell through a sequence of moves.

Output

A single line denoted the minimum possible number of mikemon battles that you have to participate in if you pick a strategy that minimize this number.

Examples
Input
5 7
000E0T3
T0TT0T0
010T0T0
2T0T0T0
0T0S000
Output
3
Input
1 4
SE23
Output
2
Note

The following picture illustrates the first example. The blue line denotes a possible sequence of moves that you should post in your blog:

The three breeders on the left side of the map will be able to battle you — the lone breeder can simply stay in his place until you come while the other two breeders can move to where the lone breeder is and stay there until you come. The three breeders on the right does not have a way to battle you, so they will stay in their place.

For the second example, you should post this sequence in your Blog:

Here's what happens. First, you move one cell to the right.

Then, the two breeders directly to the right of the exit will simultaneously move to the left. The other three breeder cannot battle you so they will do nothing.

You end up in the same cell with 2 breeders, so 2 mikemon battles are conducted. After those battles, all of your opponents leave the forest.

Finally, you make another move by leaving the forest.


题目大意:

给你一个N*M的图,起点是S,终点是E.

其中数字0代表空地,数字1~9表示这个位子上一开始的人数。

这些人不想让我们走到终点,我们希望走到终点碰到敌人数量越少越好。

每一回合所有人可以做两件事:①原地不动,②向走位四个格子走一步。

只有我们主人公走到终点才会离开,敌人不会离开。

问假设所有人都足够聪明的话,我们最少遇到的敌人的个数。


思路:

这还是一道煞笔题啊,我们只要让所有敌人都走到终点然后在终点等候主人公即可啊。所以原地不动这种骚操作不是给主人公用的啊,就是给这些敌人在终点等候使用的啊。

所以问题就变成了,求各个敌人和主人公到终点的距离,ans=敌人到终点的距离小于主人公到终点的距离的人数和。


那么我们从终点开始Bfs统计一下即可。


Ac代码:

#include<stdio.h>
#include<string.h>
#include<queue>
using namespace std;
struct node
{
    int x,y,step;
}now,nex;
int n,m,Dis,cnt;
int dist[1005][1005];
char a[1005][1005];
bool vis[1005][1005];
int fx[4]={0,0,1,-1};
int fy[4]={1,-1,0,0};
void Bfs(int x,int y)
{
    int cnt=0;
    memset(dist,-1,sizeof(dist));
    memset(vis,0,sizeof(vis));
    vis[x][y]=1;
    queue<node>s;
    now.x=x;
    now.y=y;
    now.step=0;
    s.push(now);
    while(!s.empty())
    {
        now=s.front();s.pop();
        dist[now.x][now.y]=now.step;
        if(a[now.x][now.y]=='S')Dis=now.step;
        for(int i=0;i<4;i++)
        {
            nex.x=now.x+fx[i];
            nex.y=now.y+fy[i];
            nex.step=now.step+1;
            if(nex.x>=0&&nex.x<n&&nex.y>=0&&nex.y<m&&vis[nex.x][nex.y]==false&&a[nex.x][nex.y]!='T')
            {
                vis[nex.x][nex.y]=1;
                s.push(nex);
            }
        }
    }
    int output=0;
    for(int i=0;i<n;i++)
    {
        for(int j=0;j<m;j++)
        {
            if(dist[i][j]==-1)continue;
            if(dist[i][j]<=Dis&&a[i][j]>='1'&&a[i][j]<='9')
            {
                output+=a[i][j]-'0';
            }
        }
    }
    printf("%d\n",output);
}
int main()
{
    while(~scanf("%d%d",&n,&m))
    {
        for(int i=0;i<n;i++)scanf("%s",a[i]);
        int xx,yy;
        for(int i=0;i<n;i++)
        {
            for(int j=0;j<m;j++)
            {
                if(a[i][j]=='E')
                {
                    xx=i;yy=j;
                }
            }
        }
        Bfs(xx,yy);
    }
}


















标题基于Python的高校岗位招聘和分析平台研究AI更换标题第1章引言介绍高校岗位招聘的现状、问题以及Python在分析平台中的应用。1.1研究背景与意义分析高校岗位招聘的重要性及其面临的挑战。1.2国内外研究现状探讨当前国内外在高校岗位招聘分析方面的研究进展。1.3研究方法与论文结构简述本文的研究方法,并概述论文的整体结构。第2章相关理论与技术总结高校岗位招聘分析所涉及的理论框架与关键技术。2.1数据挖掘与信息处理讨论数据挖掘技术在高校岗位招聘中的应用。2.2Python编程语言及其优势阐述Python在数据处理与分析方面的优势和特点。2.3相关算法与模型介绍用于招聘数据分析的主要算法和模型。第3章平台需求分析与设计详细分析高校岗位招聘和分析平台的需求,并设计相应的功能模块。3.1平台需求分析深入探讨平台需要满足的用户需求和业务需求。3.2平台架构设计提出平台的整体架构设计,包括前后端分离、数据库设计等。3.3功能模块设计详细介绍平台的各个功能模块,如数据采集、数据预处理、数据分析与可视化等。第4章平台实现与测试具体阐述平台的实现过程,并进行详尽的测试以确保平台的稳定性和可靠性。4.1平台实现详细描述平台的实现细节,包括关键代码的实现、模块之间的交互等。4.2平台测试对平台进行全面测试,包括功能测试、性能测试、安全测试等。第5章平台应用与效果评估将平台应用于实际的高校岗位招聘中,并对其效果进行评估和分析。5.1平台应用案例列举平台在高校岗位招聘中的具体应用案例。5.2效果评估指标体系构建用于评估平台效果的指标体系,如招聘效率提升、招聘成本降低等。5.3评估结果与分析根据评估指标体系对平台应用效果进行量化分析,并给出结论。第6章结论与展望总结本文的研究成果,并展望未来的研究方向和改进措施。6.1研究结论概括本文关于高校岗位招聘和分析平台的主要研究结论。6.2展望与改进提出对
当前提供的引用内容并未提及关于Codeforces比赛M1的具体时间安排[^1]。然而,通常情况下,Codeforces的比赛时间会在其官方网站上提前公布,并提供基于不同时区的转换工具以便参赛者了解具体开赛时刻。 对于Codeforces上的赛事而言,如果一场名为M1的比赛被计划举行,则它的原始时间一般按照UTC(协调世界时)设定。为了得知该场比赛在UTC+8时区的确切开始时间,可以遵循以下逻辑: - 前往Codeforces官网并定位至对应比赛页面。 - 查看比赛所标注的标准UTC起始时间。 - 将此标准时间加上8小时来获取对应的北京时间(即UTC+8)。 由于目前缺乏具体的官方公告链接或者确切日期作为依据,无法直接给出Codeforces M1比赛于UTC+8下的实际发生时段。建议定期访问Codeforces平台查看最新动态更新以及确认最终版程表信息。 ```python from datetime import timedelta, datetime def convert_utc_to_bj(utc_time_str): utc_format = "%Y-%m-%dT%H:%M:%SZ" bj_offset = timedelta(hours=8) try: # 解析UTC时间为datetime对象 utc_datetime = datetime.strptime(utc_time_str, utc_format) # 转换为北京时区时间 beijing_time = utc_datetime + bj_offset return beijing_time.strftime("%Y-%m-%d %H:%M:%S") except ValueError as e: return f"错误:{e}" # 示例输入假设某场Codeforces比赛定于特定UTC时间 example_utc_start = "2024-12-05T17:35:00Z" converted_time = convert_utc_to_bj(example_utc_start) print(f"Codeforces比赛在北京时间下将是:{converted_time}") ```
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值