hud 1312
Write a program to count the number of black tiles which he can reach by repeating the moves described above.
InputThe 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)
OutputFor 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 解题思路:
直接dfs,
实现代码:
#include <stdio.h>
#include <string.h>
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <bitset>
using namespace std; #define rep(i,a,b) for (int i=(a),_ed=(b);i<=_ed;i++)
#define per(i,a,b) for (int i=(b),_ed=(a);i>=_ed;i--)
#define pb push_back const int inf_int = 2e9;
const long long inf_ll = 2e18;
#define inf_add 0x3f3f3f3f
#define mod 1000000007
#define LL long long
#define ULL unsigned long long
#define MS0(X) memset((X), 0, sizeof((X)))
#define SelfType int
SelfType Gcd(SelfType p,SelfType q){return q==?p:Gcd(q,p%q);}
SelfType Pow(SelfType p,SelfType q){SelfType ans=;while(q){if(q&)ans=ans*p;p=p*p;q>>=;}return ans;}
#define Sd(X) int (X); scanf("%d", &X)
#define Sdd(X, Y) int X, Y; scanf("%d%d", &X, &Y)
#define Sddd(X, Y, Z) int X, Y, Z; scanf("%d%d%d", &X, &Y, &Z)
#define reunique(v) v.resize(std::unique(v.begin(), v.end()) - v.begin())
#define all(a) a.begin(), a.end()
#define mem(x,v) memset(x,v,sizeof(x))
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
typedef vector<int> vi;
typedef vector<long long> vll;
#define PI acos(-1.0)
#define exp 1e-9
char mp[][];
int vis[][];
int ans;
void dfs(int x,int y)
{
if(mp[x-][y]=='.'&&vis[x-][y]==){
ans++;
vis[x-][y] = ;
dfs(x-,y);
}
if(mp[x][y-]=='.'&&vis[x][y-]==){
ans++;
vis[x][y-] = ;
dfs(x,y-);
}
if(mp[x][y+]=='.'&&vis[x][y+]==){
ans++;
vis[x][y+]= ;
dfs(x,y+);
}
if(mp[x+][y]=='.'&&vis[x+][y]==){
ans++;
vis[x+][y] = ;
dfs(x+,y);
}
}
int main()
{
int n,m,i,j;
while(scanf("%d%d",&m,&n),m+n)
{
getchar();
ans=;
memset(vis,,sizeof(vis));
memset(mp,'#',sizeof(mp));
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
scanf("%c",&mp[i][j]);
}
getchar();
}
for(i=;i<=n;i++)
{
for(j=;j<=m;j++)
{
if(mp[i][j]=='@')
{
ans++;
vis[i][j]=;
dfs(i,j);
i=n;
j=m;
}
}
}
printf("%d\n",ans);
}
return ;
}
hud 1312的更多相关文章
- hud 1312 Red and Black
题目: 链接:pid=1312">点击打开链接 题意: DFS搜索 算法: dfs 思路: 简单题 代码: #include<iostream> #include<c ...
- 如何用Unity GUI制作HUD
若知其所以然,自然知其然. HUD是指平视显示器,就是套在脸上,和你的眼睛固定在一起,HUD的意思就是界面咯,一般我们说HUD特指把3D空间中的界面的某些信息(比如血条,伤害之类)的贴在界面上,对应3 ...
- xamarin UWP平台下 HUD 自定义弹窗
在我的上一篇博客中我写了一个在xamarin的UWP平台下的自定义弹窗控件.在上篇文章中介绍了一种弹窗的写法,但在实际应用中发现了该方法的不足: 1.当弹窗出现后,我们拖动整个窗口大小的时候,弹窗的窗 ...
- xamarin UWP设置HUD加载功能
使用xamarin开发的时候经常用到加载HUD功能,就是我们常见的一个加载中的动作,Android 下使用 AndHUD , iOS 下使用 BTProgressHUD, 这两个在在 NuGet 上都 ...
- JZOJ 1312:关灯问题
传送门 少见的DP再DP题目.题面不短,但是可以看出来这是一道DP题.而且正解的算法复杂度应该是$O(N^3)$.而且给了部分$O(N^4)$的算法的分.可以看出来要AC是要在DP上加上优化的. 设$ ...
- OSG中的HUD
OSG中的HUD 所谓HUD节点,说白了就是无论三维场景中的内容怎么改变,它都能在屏幕上固定位置显示的节点. 实现要点: 关闭光照,不受场景光照影响,所有内容以同一亮度显示 关闭深度测试 调整渲染顺序 ...
- HDU 1312 Red and Black (dfs)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1312 Red and Black Time Limit: 2000/1000 MS (Java/Oth ...
- CREATE A ENERGY / HEALTH BAR HUD
Now then, let's get started. 1. Open the Play scene which you had created in the previous post. If y ...
- iOS之UI--指示器HUD的创建和设置
指示器的创建和设置 渐变动画 描述: 使用label就能制作指示器,原理:就是让label以动画的形式慢慢显示和消失 最好是半透明的 指示器有时候也被称为:HUD,遮盖,蒙版 思路步骤: 1.先在st ...
随机推荐
- GIT 工作区和暂存区
工作区和暂存区 Git和其他版本控制系统如SVN的一个不同之处就是有暂存区的概念. 先来看名词解释. 工作区(Working Directory) 就是你在电脑里能看到的目录,比如我的studygit ...
- BZOJ 5475: [WC 2019] 数树
WC2019 数树 解决了一个心头大患 考试的时候本人太智障了QwQ 本文的参考链接,膜了一发rqy的题解 题目链接 Subtask 0 好像可以直接做... 推一推就能发现,是$y^k$,其中$k$ ...
- UVA1265 Tour Belt Kruskal重构树、倍增、树上差分
题目传送门 题意:定义$Tour \, Belt$为某张图上的一个满足以下条件的点集:①点集中至少有$2$个点②任意两点互相连通③图上两个端点都在这个点集中的边的权值的最小值严格大于图上只有一个端点在 ...
- Ionic App之国际化(2) json数组的处理
在Ionic App值国际化(1)中我们实现了对单个参数的多语言处理,下面开始如何进行数组的处理. 1.在我们的多语言文件中设置要访问的json数组,en.json和zh.json,此处就以en.js ...
- Luogu P4053 [JSOI2007]建筑抢修
一道贪心题,看数据范围就知道要套一个数据结构上去. 别走啊不是什么很高级的数据结构 考虑最朴素的想法,按建筑的抢修时间排序并先拿小的 然后随便想想都可以找到一堆反例 所以我们就直接考虑模拟这个过程,按 ...
- python语言程序设计8
1, 说实话,我挺伤心的,感觉 有点像烂剧里的主演...也许我早几天明白的话,会不会结果会不一样?但是之前还真没往这方面想过,但是确实是开了一个口子了,也不急吧.努力把现在的事给做好,变帅变高,那很 ...
- hadoop-hdfs编程
1.开发环境搭建 一.新建一个普通的java工程 二.引入hdfs相关的jar包 需要引入的jar包: common下的jar hdfs下的jar 2.编写HDFS相关的程序 package com. ...
- Java的首次学习和了解
先来说说自己对于Java的了解.Java是一种面向对象的语言,而c++则是面向过程的.Java在网页的开发设计制作过程中必不可少,另外我们还可以用它来做手机的移动开发,还有一些基于服务器的架构设计.J ...
- #科委外文文献发现系统——导出word模板1.0
ps:该篇文档由实验室ljg提供. Crowdsourcing 一. 技术简介 Crowdsourcing, a modern business term coined in ...
- M2 终审
1.团队成员简介 左边:马腾跃 右边:陈谋 左上:李剑锋 左下:仉伯龙 右:卢惠明 团队成员及博客: 李剑锋: Blog: http://www.cnblogs.com/Po ...