HDU 1312 Red and Black

自适应陷波器的原理与实现 x(t)是叠加有两个频率干扰信号的输入信号,s(t)是需要保留的有用信号,在输入信号中,我们只知道频率w1和w2,但不知道信号的幅度A和相位θ,自适应陷波器可以估计两个未知的幅度和相位值,这需要我们提供两路相互正交的单频信号,如cos(w1t)、sin(w1t),通过调整其权值,从而合成出与干扰信号完全相同的信号A1cos(w1t+θ1),从而实现干扰信号的滤除。采用LMS算法,在保证不损失其他有用信号的情况下,有效地抑制输入信号中某一频率的干扰,如需滤除多个频率,只需要增加相应的输入信号。 阅读详情

看了好多天的DFS,基本上的程序都是要借助解题报告才可以实现

但是这一题,确实依照自己的思路,完全靠自己写出来的,或许比较简单吧,所以特此发表下文章,犒劳一下自己,再接再厉

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): 2364    Accepted Submission(s): 1551


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
 
#include<iostream>
#include<string.h>
#include<stdio.h>
using namespace std;
int direct[4][2] = { -1, 0, 1, 0, 0, 1, 0, -1 };  /*定义方向, 左右,上下*/

char map[21][21];               /*输入的字符串*/
bool mark[21][21];              /*标记走过的路程*/
bool flag;
int W, H;
int Dx, Dy;            //记录起始位置@,从这里开始进行搜索
int ans;                //记录满足的个数。初始化为1,因为@也包含在内
/*****底下是核心算法,主要是从
上下左右这四个方向进行搜索,注意
满足搜索的条件是不能越界,不能是#,
还有就是没有搜索过的--》主要是靠mark[i][j]
来实现*******/
void DFS( int x, int y )
{
    mark[x][y] = true;
    for( int k = 0; k < 4; k ++ )
    {
        int p = x + direct[k][0];
        int q = y + direct[k][1];
        if( p >= 0 && q >= 0 && p < H && q < W && !mark[p][q] && map[p][q] != '#' )
        {
            ans ++;
            DFS( p, q );
        }
    }
    return;
}

int main()
{
    int i, j, k;
    while( cin >> W >> H && ( W || H ) )   // W -> column, H -> row;
    {
        memset( mark, false, sizeof( mark ) );
        for( i = 0; i < H; i ++ )
            for( j = 0; j < W; j ++ )
            {
                cin >> map[i][j];
                if( map[i][j] == '@' )
                {
                    Dx = i;
                    Dy = j;
                }
            }
        ans = 1;
        DFS( Dx, Dy );
        cout << ans << endl;
    }
}

QT5.14.2离线安装包保姆级教程:断网、选组件、避坑全记录 本文详细介绍了QT5.14.2离线安装包的完整流程,特别针对Windows平台开发者提供断网安装、组件选择及避坑指南。作为QT5系列中最后一个免费离线版本,5.14.2具有免注册、全组件离线安装等独特优势,是开源开发者的理想选择。文章涵盖从环境准备到安装后配置的全方位指导,帮助开发者高效完成安装并避免常见问题。 阅读详情

相关推荐

SoC低功耗设计实战:28nm工艺下四核A7的Hierarchical Flow全流程解析

本文深入解析了在TSMC 28nm工艺上,采用Hierarchical Flow(层次化流程)实现四核Cortex-A7 SoC低功耗设计的全流程。文章从项目背景切入,详细探讨了基于UPF的电源规划、时钟树综合、接口时序收敛以及物理验证等关键环节,分享了使用Cadence Innovus等工具进行低功耗物理实现的实战经验与挑战。

weixin_29231263的博客 330

Red and Black

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 he can’t move o...

cuijunrongaa的博客 385

从零到一:在K210上实现YOLO模型在线训练与部署全流程

本文详细介绍了在K210芯片上实现YOLO模型在线训练与部署的全流程,涵盖数据采集、模型优化、量化转换及内存管理等关键环节。通过实战案例和代码示例,帮助开发者高效利用K210的超低功耗特性与YOLO模型的实时检测能力,适用于边缘计算和物联网应用场景。

weixin_29094539的博客 357

HDU1312 Red and Black(黑红砖块)(dfs入门水题)

题目链接:点击打开链接 题目大意:有一个长方形的房间,铺满了正方形瓷砖。每个瓷砖都是红色或黑色的。一个人站在一块黑色的瓷砖上。从一个瓷砖上,他可以移动到四个相邻(上下左右)的瓷砖中的一个。但是他不能移动到红色的瓷砖,只能在黑色的瓷砖上移动。通过重复上面描述的动作,编写一个程序来计算他能达到的黑瓷砖的数量。 输入:多个数据。第一行给出两个数m,n(0,0代表结束输入);m代表列,n代表行。m,n...

本该如此 1305

西门子WinCC VBS脚本实战:5分钟搞定变量记录导出到Excel(附完整代码)

本文提供了一套高效的西门子WinCC VBS脚本方案,帮助工程师在5分钟内将变量记录数据导出至Excel。方案详细解析了时区转换、数据库连接、SQL查询优化等核心难点,并附带了完整、可直接使用的VBS代码,解决了工业自动化项目中数据导出的实际痛点。

moss5的博客 616

【深度强化学习】(2) Double DQN 模型解析,附Pytorch完整代码

Double DQN 算法是 DQN 算法的改进版本,解决了 DQN 算法过估计行为价值的问题。Double DQN 算法不直接通过最大化的方式选取目标网络计算的所有可能 Q 值,而是首先通过估计网络选取最大 Q 值对应的动作。在 Double DQN 框架中存在两个神经网络模型,分别是训练网络与目标网络。这两个神经网络模型的结构完全相同,但是权重参数不同;每训练一段之间后,训练网络的权重参数才会复制给目标网络。

博观而约取,厚积而薄发 1万+

hdu1312 “Red and Black”——DFS与递归的应用

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 he can’t move on red tiles, he can move only on b

m0_52380556的博客 478

AD7920实战:从咪头到ADC的音频信号采集电路设计全解析(附电路图)

本文详细解析了基于AD7920 ADC芯片的音频信号采集电路设计全流程。从驻极体咪头的驱动、AD8542运放的两级增益与偏置设计,到关键的抗混叠滤波器配置,以及ADC接口的驱动缓冲与PCB布局要点,提供了完整的实战指南与电路图,帮助开发者实现高质量音频信号采集。

red88的博客 827

HDU 1312 Red and Black(经典搜索,DFS&BFS三种方式)

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

AC_Dreameng 4850

科研级YOLOv8 Neck革新:BiFPN双向特征金字塔赋能,让多尺度融合更高效的实战指南

在文件夹下新建BiFPN.py,将上述BiFPNLayer和BiFPN类的代码写入其中。这一步是为了让YOLOv8的代码架构能识别我们的自定义Neck模块。

m0_64661770的博客 156

Win7 x64位系统下几乎完美使用安装RTX3050 6G显卡驱动详细教程

RTX3050 6G显卡驱动安装指南:由于该显卡发布时间晚于驱动,需手动修改安装文件。首先在NVIDIA官网下载驱动并解压,通过设备管理器获取硬件ID(PCI\VEN_10DE&DEV_2584),然后在解压目录的.inf文件中添加对应的设备标识。安装完成后可能出现设备管理器感叹号问题,推荐通过命令提示符启用测试模式(bcdedit /set testsigning on)解决,此方法无需每次启动按F8,但会显示测试模式水印。文中提供了详细的图文操作步骤和两种解决方案。

m0_67194883的博客 2929

hdu 1312 Red and Black

hdu  1312  Red and Black                 题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 DFS水 题目大意:一个人被困在一个迷宫里,问他的生存空间。 题目分析:DFS就好了。 code: #include #include char mp[26][26],vis[26][26]; int m

slicer的技术交流栈 915

跟踪雷达点迹处理

1,点迹定义: 假设研究对象为位置x和速度v,预测值是根据这一时刻的x值、v值来预测下一时刻的x、v;测量值是根据传感器也就是雷达得到的,因为各种误差的存在,这两个值都不准确,所以把他们加权融合,得到一个新的量—状态值。 点迹就是所谓的测量值,由雷达对同一个目标探测到的一系列点(假设目标静止,但由于误差的存在,会扫描出不止一个点),航迹对应状态值,是点迹和预测轨迹的加权融合。 2,雷达信号和点迹处理关系: 3,点迹航迹处理流程 4,仿真 clear all; RealData=G

wangjie36的博客 1万+

HDU T1312 Red and Black

                          HDU T1312 Red and Black 题解:     因为是遍历所有可以走的点,所以不需要回溯。需要注意的是写完要测试最小值     例如:1 1                @     答案应该为1,本身也算一个。   Dfs代码 #include&lt;cstdio&gt; #include&lt;iostrea...

Mr__Charles的博客 206

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

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

LinePhone3.2.7(android端最新版本) sip客户端

SIP客户端For android:LinePhone3.2.7(最新版本),官网地址:http://www.linphone.org/

Hdu 1312 Red and black(BFS)

HDU 1312 Red and black#include<iostream> #include<cstring> #include<algorithm> #include<queue> using namespace std; char map[25][25]; int flag[25][25];//标记 已经走过的路 int step[4][2] = { { 1, 0 }, { 0, 1 },

勇于尝试,却要三思后行。 403

复分析 阿尔福斯(Ahlfors) 第三版答案 英文

答案分为十章,有部分习题没有答案,全英文复分析阿尔福斯(Ahlfors) 第三版答案

HDU-1312 Red and Black

HDU 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...

你呢的博客 752

霍尼韦尔SoftMaster使用说明

霍尼韦尔SoftMaster使用说明

hdu1312 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 adjacen

506

HDU1312——Red and Black

http://acm.hdu.edu.cn/showproblem.php?pid=1312 这倒题用的是广搜:广搜用的是队列。就是从一个点有四个方向,所以把四个可能都放进队列里。 广搜也是状态改变。就像是泼水的感觉。 题意:就是从@位置最多能走多少步。明显的广搜 #include<stdio.h> #include<cstring> #inclu...

aozhe0658的博客 128

HDU 1312 Red and Black【递归】

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

dxx_111的博客 717

hdu 1312 Red and Black

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

h2017010687的博客 186

hdu 1312 Red And Black

hdu 1312 的传送门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

代码改变世界 962

HDU 1312 Red and Black <BFS>

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

其实我是C先生--的博客 582

hdu_1312 Red and Black

原题链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 分析:简单的BFS。使用广搜,使每个满足添加的点进队列,统计删除的点,有多少个点被删除就有多少个满足题意的点。 我的代码: #include #include #include using namespace std; char map[21][21]; bool visited[21][

徵羽調_xiao賤的专栏 899

hdu 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): 11962    Accepte

GrEedWish_X的专栏 502
上一篇: HDU 1010 Tempter of the Bone
下一篇: HDU 1879 继续畅通工程
小do在努力
博客等级 码龄16年 58粉丝 161原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

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

抵扣说明:

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

余额充值
⌂ 换网址