Hdoj 1312.Red and Black 题解

Problem Description

There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But he can't move on red tiles, he can move only on black tiles.

Write a program to count the number of black tiles which he can reach by repeating the moves described above.

Input

The input consists of multiple data sets. A data set starts with a line containing two positive integers W and H; W and H are the numbers of tiles in the x- and y- directions, respectively. W and H are not more than 20.

There are H more lines in the data set, each of which includes W characters. Each character represents the color of a tile as follows.

'.' - a black tile
'#' - a red tile
'@' - a man on a black tile(appears exactly once in a data set)

Output

For each data set, your program should output a line which contains the number of tiles he can reach from the initial tile (including itself).

Sample Input

6 9
....#.
.....#
......
......
......
......
......
#@...#
.#..#.
11 9
.#.........
.#.#######.
.#.#.....#.
.#.#.###.#.
.#.#..@#.#.
.#.#####.#.
.#.......#.
.#########.
...........
11 6
..#..#..#..
..#..#..#..
..#..#..###
..#..#..#@.
..#..#..#..
..#..#..#..
7 7
..#.#..
..#.#..
###.###
...@...
###.###
..#.#..
..#.#..
0 0

Sample Output

45
59
6
13

Source

Asia 2004, Ehime (Japan), Japan Domestic


思路

平平无奇的一道简单bfs问题,只要每次广搜入队的时候都统计一次就好了,最后返回结果并输出

代码

#include<bits/stdc++.h>
using namespace std;
int a,b,c,t;
const int d[][2]={ {-1,0},{0,1},{1,0},{0,-1} };
struct node
{
    int x;
    int y;
}st,ed;
int n,m;
char maps[21][21];
bool judge(node x)
{
    if(x.x<=m && x.x>=1 && x.y<=n && x.y>=1 && maps[x.x][x.y]=='.')
        return true;
    return false;
}
int bfs(node st)
{
    queue<node> q;
    q.push(st);
    maps[st.x][st.y] = '#';
    node now,next;
    int t = 0;
    while(!q.empty())
    {
        now = q.front();
        q.pop();
        for(int i=0;i<4;i++)
        {
            next.x = now.x + d[i][0];
            next.y = now.y + d[i][1];           
            if(judge(next))
            {
                q.push(next);
                t++;
                maps[next.x][next.y] = '#';
            }
        }

    }
    return t+1;//起点也算
}
        
int main()
{
    while(cin>>n>>m)
    {
        if(n==0 && m==0) break;
        for(int i=1;i<=m;i++)
            for(int j=1;j<=n;j++)
            {
                cin >> maps[i][j];
                if(maps[i][j]=='@')
                {
                    st.x = i; st.y = j;
                }
            }
        int ans = bfs(st);
        cout << ans << endl;
    }
    return 0;
}

转载于:https://www.cnblogs.com/MartinLwx/p/9902686.html

道通无人机信号分析 本文分析了道通无人机及其遥控器的EIRP参数(表1-2),发现不同地区的功率标准存在差异。针对5230MHz图传信号,观测到四帧连续信号结构类似LORA分包传输。脉冲分析(表3)显示固定3.9ms脉宽和1.1ms间隔。频谱异常表现为非矩形窗特征,经分析系多径效应引起的频率选择性衰落所致——不同路径传播导致特定频率出现相长/相消干涉,形成波峰波谷的起伏频谱特征。这种现象与无线信道的多径时延、衰减差异直接相关。 阅读详情

相关推荐

避坑指南:RK3576+Android14适配移远5G模组(RG200U)时,我遇到的3个‘巨坑’及解决方案

本文详细记录了RK3576芯片适配Android14系统与移远RG200U 5G模组过程中遇到的三大技术难题:RIL服务启动失败、HIDL兼容性矩阵配置错误及ttyUSB权限冲突。通过实战案例提供了动态库拷贝、HIDL版本链声明和SELinux策略调整等解决方案,帮助开发者高效完成5G模组集成,特别适用于基于kernel6.1的嵌入式开发场景。

weixin_30664051的博客 401

hdoj--1312--Red and Black(dfs)

Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14311    Accepted Submission(s): 8870 Problem Description There is a re

playboy307 369

IC/FPGA笔试/面试题分析(七)建立时间和保持时间类型考题汇总分析

自从召集2020届校招同行加入新建立的“IC/FPGA校招笔试面试交流群“,见识到了很多关于建立时间和保持时间分析的题目,在为别人解答疑惑,以及别人为自己解答疑惑的同时,自己对于知识的理解更加深刻了。 对于建立时间而言,从单独的对触发器的建立时间和保持时间的分析到了对电路(系统)的建立时间到保持时间的分析,前者是核心,后者是扩展,后者建立在前者的基础之上进行推到得到,同时也是芯片内部实际遵循的时...

Reborn Lee 1万+

AcWing803 区间合并(区间贪心)

题目:AcWing803 区间合并 题解目录前言一、题目陈述二、解决思路三、代码实现总结 前言 区间贪心问题,想到排序。 一、题目陈述 二、解决思路 将所有区间按照起点排序,然后进行贪心。 三、代码实现 #include<iostream> #include<algorithm> using namespace std; typedef pair<int,int> PII; const int N=10010; vector<PII> segs; int

codertea的博客 561

An AI compute of cities based on Distributed-Platform and Distributed-Databases(天池地铁流量预测)

摘要 在日益城市化的今天,城市居民出行问题逐渐成为衡量一个城市现代化能力的标准;城市出行方式多元化的同时,也对各交通系统的调度运营能力提出了更高的要求:如何提高运营效率,如何运用有限的安保力量进行有效的安检部署等问题一直在阻挠着城市交通的发展。 An AI compute of cities based on Distributed-Platform and Distributed-Databas...

Clearlove灬Star 5168

PCIe Electrical PHY(4)-PCIE SPEC第8章指标讲解

1.1 PCIE TX SPEC TX主要关心两类参数,一类是Voltage Parameters,一类是Jitter Parameters。 其中Voltage相关参数主要关心不同preset下差分电压幅度的准确性。以及共模电压的稳定性。 PCIE spec中对Jitter相关的参数测量定义如下: 分为两大类:DDJ(Data dependent Jitter)和UJ(Uncorrelated ...

maxwell2ic的博客 5967

HDOJ 1312 Red and Black(简单dfs)

Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13020    Accepted Submission(s): 8062 Problem Description There is a re

Chunzhen的博客 502

3台虚拟机部署Doris详细文档(含校验步骤)

摘要:本文详细介绍了Apache Doris在3台虚拟机上的集群部署方案。采用1主FE+1从FE+1观察者FE+3BE的混合部署模式,确保元数据高可用性。硬件配置建议测试环境4核16GB内存,生产环境8核64GB内存。部署步骤包括系统环境配置(关闭防火墙、内核参数优化)、FE/BE节点配置启动、集群初始化验证等。重点配置了IP白名单(172.30.0.115)和数据目录(/data/doris)。通过MySQL客户端和WebUI可监控集群状态,实现千万级数据的实时分析能力,后续可通过增加BE节点线性扩展。

weixin_41026747的博客 940

Red and Black(搜索题目)

Red and Black Time Limit: 1000MS Memory Limit: 32768KB 64bit IO Format: %I64d & %I64u Submit   Status Description There is a rectangular room, covered with square tiles. Each tile is colore

小小程序猿 580

Pascal Context数据集实战:从安装到格式转换的完整指南

本文提供了Pascal Context数据集的完整实战指南,从安装配置到格式转换的详细步骤。Pascal Context是计算机视觉领域重要的语义分割数据集,包含540个精细标注类别。文章涵盖数据集下载、环境配置、预处理技巧和常见问题解决方案,帮助开发者高效利用这一数据集进行场景理解任务。

weixin_30216561的博客 618

升级最新IDEA版本(2022.1.1)

升级最新IDEA版本(2022.1.1)

软件老王 3万+

POJ1979 Red and Black 题解

by BrotherRoot E - Red and Black 题意: 在M×N的棋盘上有红和黑两种方格,黑方格能够通行,红方个不能通行。求从指定的黑方格出发能够到达的方格总数 思路: 从起点进行floodfill,然后统计被访问的方格。 代码: #include const int MAXSIZE = 20; const int DIRECTNUM = 4; con

360

【反卷积算法】Richardson-Lucy (RL) :通过不断迭代更新图像估计值

Richardson-Lucy(RL)反卷积算法:是一种基于最大似然估计(Maximum Likelihood Estimation, MLE)的图像去卷积方法,常用于去模糊和图像增强。通过不断地更新图像估计值,来最小化模糊图像和恢复图像之间的误差,逐步消除模糊,最终接近真实的原始图像,每次迭代都会根据当前估计的图像来修正下次迭代的结果。

📷 图像处理践行者 | 传统算法 · 深度学习 · 多模态 | 分享实战经验与技术洞见,探索从像素到智能的无限可能。 3053

Hdoj 1312 Red and Black、DFS、水题:【题解】

题目描述: 有一个长方形的房间,覆盖了正方形的磁砖。每块磁砖的颜色,要么是红色,要么是黑色。一名男子站在一块黑色的磁砖上。他可以从一块磁砖移至相邻四块磁砖中的某一块。但是,他不允许在红色磁砖上移动,他只允许在黑色磁砖上移动。 编写一个程序,使得他允许重复上述的移动,判断他所能到达的黑色磁砖的数量。 输入 输入由多个数据集组成。数据集的起始行包含了两个正整数 W 和 H;W 和 H 分别是 x- 和...

EP的别三日 357

深度学习工具包 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&#39;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(&#39;DeepLearnToolbox&#39;));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(&#39;state&#39;,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&#39;); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand(&#39;state&#39;,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 = &#39;sigm&#39;;%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, &#39;Too big error&#39;);```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(&#39;state&#39;,0)sae = saesetup([784 100]);sae.ae{1}.activation_function = &#39;sigm&#39;;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)&#39;)% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;;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, &#39;Too big error&#39;);```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x&#39;,28,28,60000))/255;test_x = double(reshape(test_x&#39;,28,28,10000))/255;train_y = double(train_y&#39;);test_y = double(test_y&#39;);%% 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&#39;ll get around 1.2% errorrand(&#39;state&#39;,0)cnn.layers = { struct(&#39;type&#39;, &#39;i&#39;) %input layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 6, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 2) %sub sampling layer struct(&#39;type&#39;, &#39;c&#39;, &#39;outputmaps&#39;, 12, &#39;kernelsize&#39;, 5) %convolution layer struct(&#39;type&#39;, &#39;s&#39;, &#39;scale&#39;, 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, &#39;Too big error&#39;);```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(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex2 neural net with L2 weight decayrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex3 neural net with dropoutrand(&#39;state&#39;,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, &#39;Too big error&#39;);%% ex4 neural net with sigmoid activation functionrand(&#39;state&#39;,0)nn = nnsetup([784 100 10]);nn.activation_function = &#39;sigm&#39;; % 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, &#39;Too big error&#39;);%% ex5 plotting functionalityrand(&#39;state&#39;,0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);%% 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(&#39;state&#39;,0)nn = nnsetup([784 20 10]); nn.output = &#39;softmax&#39;; % 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, &#39;Too big error&#39;);```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

jdk-8u144-linux-x64.tar.gz.

该资源为搭建Linux系统Java环境用,资源的后缀为tar.gz格式的压缩包

HDOJ 1312 Red and Black

题目链接: http://acm.hdu.edu.cn/showproblem.php?pid=1312 Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 10724    Acce

MummyDing's Blog 1117

visio安装包

Microsoft Office Visio 是一款专业的制图软件。利用经过更新的形状、协作工具和数据链接图表,创建专业级图表以简化复杂的信息。

HDOJ--1312--Red and Black

题目描述: There is a rectangular room, covered with square tiles. Each tile is colored either red or black. A man is standing on a black tile. From a tile, he can move to one of four adjacent tiles. But h...

猩猩是个好程序员的博客 192

HDOJ1312 Red and Black 深搜dfs

Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 15340    Accepted Submission(s): 9498 Problem Description There is a rect

huatian5的博客 452

hdu 1312 Red and Black

本题来自:http://acm.hdu.edu.cn/showproblem.php?pid=1312 英语题意翻译:在宽、高不超过20的范围里,从@开始,统计四周有几个.(前后左右,斜方不算)。 英语不好,翻译了很久··· 1 #include <stdio.h> 2 #include<string.h> 3 char graph[21][21],vi...

weixin_30763455的博客 74

HDOJ 1312 Red and Black【dfs】

Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 14373    Accepted Submission(s): 8909 Problem Description There is a

A_ice 454

HDU1312 Red and Black 题解

一条递归搜索法题目,使用递归搜索法,但是实际不用重复计算方格。 思路是: 1 每搜索一个方格就改变当前方格的值为 ‘*’,或者任何其他非'.'的值,代表该方格已经走过了 2 递归的时候不回复这个方格的值,就实际上不用重复搜索这个方格了,故此不用回溯 #include #include #include #include using namespace std; int R,

靖空间 1300

HDOJ 1312 Red and Black (简单dfs)

Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 12655    Accepted Submission(s): 7810 Problem Description There is a rect

滴水穿石,慢慢积累,总会有成果 419

poj 1979 Red and Black(BFS)

Red and Black Time Limit: 1000MS   Memory Limit: 30000K Total Submissions: 31221   Accepted: 17047 Description There is a rectangular room, covered with square tiles. E

L-75的专栏 734

hdoj 1312 Red and Black【DFS】

Red and Black Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) Total Submission(s): 13197    Accepted Submission(s): 8181 Problem Description There is a

平平淡淡才是真 516

POJ 1979 Red and Black 解题报告

《程序设计导引及在线实践》上面有这道题,练习了递归的思想。   #include const int MAX_BRICK_SIZE = 20; /*用来存储方块符号信息*/ char bricks[MAX_BRICK_SIZE + 1][MAX_BRICK_SIZE + 1]; int W, H; /*递归调用的函数。 *假设以(i, j)为起点,则总的可以经过的黑瓷砖数为: *

Leo的博客 1261

HDU1312 / POJ1979 / ZOJ2165 Red and Black(红与黑) 解题报告

HDU1312 / POJ1979 / ZOJ2165 Red and Black(红与黑) DFS解题报告

一蓑烟雨 1447
上一篇: Hdoj 1253.胜利大逃亡 题解
下一篇: Hdoj 2717.Catch That Cow 题解
csdn2082
博客等级 码龄11年 3粉丝 0原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值