Fire Game -仅仅两个起点而已

fzu 2150 Fire Game 【技巧BFS】 题目: fzu 2141 Sub-Bipartite Graph (贪心) 阅读详情

Fire Game

 FZU - 2150 

#include<stdio.h>
#include<cstring>
#include<queue>
using namespace std;
#define maxn 222
#define inf 0x3f3f3f3f
int t,m,n,ans,flag,sum,total;
char mmp[maxn][maxn];
bool vis[maxn][maxn];
int to[5][3]= {{1,0},{0,1},{0,-1},{-1,0}};
vector<pair<int,int> >gra;
bool judge(int x,int y)
{
    if(mmp[x][y]=='#'&&x>=0&&x<n&&y>=0&&y<m&&vis[x][y]==0)
        return true;
    return false;
}
struct node
{
    int x,y,cnt;
} top1,top2,temp;
void bfs(int s1x,int s1y,int s2x,int s2y)
{
    queue<node>q1;
    q1.push((node)
    {
        s1x,s1y,0
    });
    q1.push((node)
    {
        s2x,s2y,0
    });
    vis[s1x][s1y]=vis[s2x][s2y]=1;
    total=0;
    while(!q1.empty())
    {
        if(!q1.empty())
        {
            top1=q1.front();
            q1.pop();
            total++;
        }
        if(total==sum)
        {
            ans=min(top1.cnt,ans);
            return;
        }
        for(int i=0; i<4; i++)
        {
            temp.cnt=top1.cnt+1;
            temp.x=top1.x+to[i][0];
            temp.y=top1.y+to[i][1];
            if(judge(temp.x,temp.y))
            {
                q1.push(temp);
                vis[temp.x][temp.y]=1;
            }
        }
    }
}
int main()
{
    scanf("%d",&t);
    for(int q=1; q<=t; q++)
    {
        flag=sum=0;
        gra.clear();
        scanf("%d%d",&n,&m);
        for(int i=0; i<n; i++)
        {
            getchar();
            for(int j=0; j<m; j++)
            {
                scanf("%c",&mmp[i][j]);
                if(mmp[i][j]=='#')
                {
                    sum++;
                    gra.push_back(make_pair(i,j));
                }
            }
        }
        printf("Case %d: ",q);
        if(sum<3)
        {
            printf("0\n");
            continue;
        }
        int len=gra.size();
        ans=inf;
        for(int i=0; i<len-1; i++)
            for(int j=i+1; j<len; j++)
            {
                memset(vis,0,sizeof(vis));
                bfs(gra[i].first,gra[i].second,gra[j].first,gra[j].second);
            }
        if(ans==inf)
            printf("-1\n");
        else
            printf("%d\n",ans);
    }
    return 0;
}

 

FPGA笔试题知识点汇总(21~40) 阅读详情

相关推荐

Unidbg补环境实战:复现Shopee风控Native层运行环境

Android App风控已从HTTP层签名校验,演进为深度依赖Native层系统调用与硬件特征的多维验证。其核心原理在于通过JNI桥接Java与Native代码,调用openat、sysconf、getrandom等系统接口读取/proc、/sys、/dev等路径的真实状态,并结合SELinux策略、CPU拓扑、分区哈希等硬性指标构建设备可信画像。这种技术架构显著提升了对抗黑灰产的能力,但也对逆向分析与自动化调用提出更高要求——必须精准模拟底层环境而非仅Hook逻辑。Unidbg补环境正是为此而生:它支持

weixin_30533109的博客 641

Fire Game

K - Fire Game Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just empt

路漫漫 始于足下 2893

【机械视觉】C#+VisionPro实战:位深图(CogImage8Grey)与Bitmap互转技巧及工业检测应用

本文详细介绍了在工业检测中如何使用C#和VisionPro实现位深图(CogImage8Grey)与Bitmap的高效互转技巧。通过实战代码示例和工业应用案例,帮助开发者解决图像处理中的常见问题,提升检测精度和系统性能,适用于半导体、汽车零部件等高精度检测场景。

weixin_29250573的博客 188

Fire Game(判断联通块+2元起点)

Fire Game FZU - 2150 胖哥和迷宫在 N*M 棋盘(N 行,M 列)上玩一种特殊的(无尽)游戏。一开始,这个板的每个网格都由草组成或只是空的,然后他们开始发射所有的草。首先他们选择两个由草和火组成的网格。众所周知,火可以在草丛中蔓延。如果网格 (x, y) 在时间 t 触发,则与该网格相邻的网格将在时间 t+1 触发,该时间指的是网格 (x+1, y), (x-1, y), (x, y+1), (x, y-1)。当没有新网格起火时,此过程结束。如果然后所有由草组成的网格都被烧毁,胖哥和迷

weixin_53158895的博客 234

Halcon实战:5分钟搞定灰度图转热力图(附完整代码)

本文提供了一份Halcon实战指南,详细讲解如何在5分钟内将灰度图转换为直观的热力图。通过核心代码演示了利用HSV颜色模型进行色彩映射的原理与步骤,包括图像归一化、通道构建与空间转换,并附赠了深度图可视化等进阶应用技巧,帮助工程师快速提升图像分析效果。

weixin_29240343的博客 285

C#与数据采集卡集成开发全指南:从硬件连接到实时数据处理(附工业传感器监测实战)

C#数据采集卡集成开发指南 本文系统介绍了不同类型数据采集卡(DAQ卡)与C#的集成方法。主要内容包括: 数据采集卡分类:按接口分为PCIe/PCI(高带宽低延迟)、USB(便携即插即用)和以太网(远距离组网);按信号类型分为模拟量输入、数字量输入/输出等。 C#集成核心方法: 优先使用厂商SDK(如NI DAQmx),提供完整功能封装 无SDK时采用通用协议(如USB HID、Modbus TCP) 具体实现示例: NI DAQmx采集热电偶温度代码 USB HID协议读取模拟量电压值 工业应用要点:实时

这里只有干货:从 Modbus 通信到 MES 对接,从 YOLO 训练到工控机部署,带你搞定工业软件开发全流程。 1977

Fire Game(双起点BFS)

传送门FZU2150描述 Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisti...

umalaka的博客 240

9.16华为OD机试真题 新系统 - 矩阵螺旋遍历 (Java/Py/C/C++/Js/Go)

9.16华为OD机试真题 新系统 - 矩阵螺旋遍历 (Java/Py/C/C++/Js/Go)

算法大师! 685

FZU 2150 Fire Game (双起点BFS)

Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just empty and then they start

LiQiyao的博客 1369

【Unity 实用工具篇】 | Unity网格破碎插件 unity-fracture

前面写过一篇Unity中物体破碎效果的插件:【Unity 实用工具篇】 | Unity物体破碎效果 OpenFracture 本文介绍一个另外的工具unity-fracture,也可以实现网格破碎效果,且功能与OpenFracture略有差异。

努力前行,总会成为自己心中的那道光 1万+

基于OpenClaw的AI数字员工协同团队架构设计

随着大型语言模型从被动的文本生成器向具备自主规划与执行能力的智能代理演进,企业级人工智能的应用范式正在发生根本性转变。在这一演进过程中,OpenClaw(前身为Clawdbot及Moltbot)作为一种开源的、本地优先的个人AI智能体网关基础设施,凭借其对持续内存、多通道接入以及沙盒化工具执行的原生支持,迅速成为构建“始终在线”数字劳动力的核心框架 1。然而,将单体个人助理扩展为能够处理复杂业务逻辑、支持跨组织协同并严格保障数据隔离的多智能体(Multi-Agent)团队,绝非简单的API拼接。系统架构必须

形上得其象,形下合于数;阴阳自济,玄理自明。 1050

fzu 2150 Fire Game(双起点BFS)

传送门 Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just empty and then they start to fire all the grass. Firstly they choose two grid

lllllan 251

Android14 Qcom 从Framework到Driver带你打开WIFI(二)

上篇文章讲到了UI打开WIFI以后,逐步调用到加载底层驱动以及通知等相关流程。这篇接着上文继续往下看WIFI ON的后续动作。

IAYLBL的博客 769

I - Fire Game FZU - 2150(多起点BFS)

I - Fire Game FZU - 2150 Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or jus...

石旭先森的博客 636

华为的C语言编程规范.pdf

华为技术有限公司内部技术规范。本规范制定了编写C语言程序的基本原则、规则和建议。从代码的清晰、简洁、可测试、安全、程序效率、可移植各个方面对C语言编程作出了具体指导。

Probability and Statistics - 4th edition

Probability and Statistics - 4th edition

FZU 2150 Fire Game 双起点bfs

FZU 2150 Fire Game 双起点bfs题意大概意思题解代码 链接: 原题网址. 题意 Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just empty and then they start to fi

zkpj12的博客 638

计算机控制技术及应用

《计算机控制技术及应用》通过总结作者的科研成果和吸收国内外的先进理论、方法和技术,以计算机控制系统的网络化、开放化、智能化和集成化发展趋势为主线索,主要介绍计算机控制系统的基本概念和计算机控制系统的典型形式,计算机控制系统的数学描述与基本分析方法,以及数字PID控制器、最少拍控制系统、达林算法、状态变量设计法等设计方法及其各种改进算法。重点突出计算机控制系统输入输出通道接口的设计方法和典型控制系统的设计案例与实现方法等。

FZU 2150 Fire Game(bfs--两个起点)

- FZU 2150 -

Pandora_heart的博客 309

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

kuangbin搜索专题 I - Fire Game(BFS)(双起点的bfs)

Fire Game:

Aurox_的博客 272

Fire Game FZU - 2150(双起点bfs)

两个熊孩子在n*m的平地上放火玩,#表示草,两个熊孩子分别选一个#格子点火,火可以向上向下向左向右在有草的格子蔓延,点火的地方时间为0,蔓延至下一格的时间依次加一。求烧完所有的草需要的最少时间。 Input 第一行,输入一个T,表示有T组测试数据。 每组数据包含n,m分别表示行和列 1 <= T <=100, 1 <= n <=10, 1 <= m <=10 O...

Jungle~St... 321

【简单搜索】Fire Game

Fire Game 问题描述 Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just empty and...

Mark_Eleven的学习笔记 387

FZU 2150 Fire Game(点火游戏)

FZU2150FireGame(点火游戏) TimeLimit:1000mSecMemoryLimit:32768KB ProblemDescription - 题目描述   Fat brother and Maze are playing a kind of special (hentai) game on an N*M board ...

221

【简单搜索】FZU 2150 Fire Game详解

Fire Game Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consisting of grass or just empty and then they start to fire all the grass. Firstly they choose

Qiuker_jl的博客 712

E - Fire Game——双起点BFS

Think: 1双起点BFS 2队列思想(结构体队列)实现BFSE - Fire Game Fat brother and Maze are playing a kind of special (hentai) game on an N*M board (N rows, M columns). At the beginning, each grid of this board is consis

BlessingXRY的博客 546

FZU - 2150 Fire Game bfs+双起点枚举

题意,10*10的地图,有若干块草地“#”,草地可以点燃,并在一秒后点燃相邻的草地。有墙壁‘·‘阻挡。初始可以从任意两点点火。问烧完最短的时间。若烧不完输出-1. 题解:由于100的数据量,直接暴力。枚举两个起点,推入队列,然后bfs。烧完就返回深度,更新一个min值。 坑:(帮同学照bug) return t.step+1;bfs后没有算上最后一步 ac代码 #defin...

Vincent19999999的博客 221
上一篇: C - 地铁 CSU - 维护边最短路
下一篇: Fire! UVA - 分步BFS
ID_BePosit
博客等级 码龄9年 76粉丝 647原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址