1、LightOJ 1012  Guilty Prince  简单bfs

2、总结:水

题意:迷宫,求有多少位置可去

#include<iostream>
#include<cstring>
#include<cmath>
#include<queue>
#include<algorithm>
#include<cstdio>
#define F(i,a,b) for (int i=a;i<=b;i++)
using namespace std;
#define LL long long
#define INF 0x3f3f3f3f
const int N=; struct Point
{
int x,y;
}; char mapn[N][N];
int visit[N][N];
int w,h,ii,jj;
int dirw[]={,,,-};
int dirh[]={,-,,}; bool charge(Point e)
{
if(e.x>=&&e.x<h&&e.y>=&&e.y<w&&!visit[e.x][e.y]&&mapn[e.x][e.y]=='.')
return true;
return false;
} int dfs()
{
int ans=;
Point st,en;
queue<Point>q;
st.x=ii,st.y=jj; q.push(st);
while(!q.empty()){
st=q.front();
q.pop();
for(int i=;i<;i++){
en.x=st.x+dirh[i];
en.y=st.y+dirw[i];
if(charge(en)){
q.push(en);
visit[en.x][en.y]=;
ans++;
}
}
}
return ans;
} int main()
{
int n;
scanf("%d",&n);
for(int cas=;cas<=n;cas++)
{
memset(visit,,sizeof(visit));
scanf("%d%d",&w,&h);
for(int i=;i<h;i++){
scanf("%s",mapn[i]); //从0开始,故下面j要注意
for(int j=;j<w;j++){
if(mapn[i][j]=='@')
ii=i,jj=j,visit[i][j]=;
}
}
int ans=dfs();
printf("Case %d: %d\n",cas,ans);
} return ;
}

LightOJ 1012 简单bfs,水的更多相关文章

  1. POJ3185(简单BFS,主要做测试使用)

    没事做水了一道POJ的简单BFS的题目 这道题的数据范围是20,所以状态总数就是(1<<20) 第一次提交使用STL的queue,并且是在队首判断是否达到终点,达到终点就退出,超时:(其实 ...

  2. 【POJ 3669 Meteor Shower】简单BFS

    流星雨撞击地球(平面直角坐标第一象限),问到达安全地带的最少时间. 对于每颗流星雨i,在ti时刻撞击(xi,yi)点,同时导致(xi,yi)和上下左右相邻的点在ti以后的时刻(包括t)不能再经过(被封 ...

  3. hdu1312 Red and Black 简单BFS

    简单BFS模版题 不多说了..... 直接晒代码哦.... #include<cstdlib> #include<iostream> #include<cstdio> ...

  4. POJ 3984 - 迷宫问题 - [BFS水题]

    题目链接:http://poj.org/problem?id=3984 Description 定义一个二维数组: int maze[5][5] = { 0, 1, 0, 0, 0, 0, 1, 0, ...

  5. Guilty Prince LightOJ - 1012

    Guilty Prince LightOJ - 1012 #include<cstdio> #include<cstring> ][]; int ans,h,w,T,TT; ] ...

  6. 逃脱 (简单BFS)

    题目传送门 G逃脱  题目描述 这是mengxiang000和Tabris来到幼儿园的第四天,幼儿园老师在值班的时候突然发现幼儿园某处发生火灾,而且火势蔓延极快,老师在第一时间就发出了警报,位于幼儿园 ...

  7. Lightoj 1174 - Commandos (bfs)

    题目链接: Lightoj  1174 - Commandos 题目描述: 有一军队秉承做就要做到最好的口号,准备去破坏敌人的军营.他们计划要在敌人的每一个军营里都放置一个炸弹.军营里有充足的士兵,每 ...

  8. 暑期训练狂刷系列——Lightoj 1084 - Winter bfs

    题目连接: http://www.lightoj.com/volume_showproblem.php?problem=1084 题目大意: 有n个点在一条以零为起点的坐标轴上,每个点最多可以移动k, ...

  9. hdu1240 bfs 水题

    原题链接 思路:水题,直接搜 #include "map" #include "queue" #include "math.h" #incl ...

随机推荐

  1. oracle JOB学习(一)---基础

    oracle job简介   下面文章来自网友(格式稍加整理)   主要的使用情景 定时在后台执行相关操作:如每天晚上0点将一张表的数据保存到另一张表中,2:定时备份数据库等   熟化说万事开头难,这 ...

  2. git push 使用总结

    git push命令用于将本地分支的更新,推送到远程主机.它的格式与git pull命令相仿. $ git push <远程主机名> <本地分支名>:<远程分支名> ...

  3. 全零网络IP地址0.0.0.0表示意义详谈

    转自:http://liuzhigong.blog.163.com/blog/static/17827237520114207278610/ RFC: 0.0.0.0/8 - Addresses in ...

  4. Eclipse调试方法及快捷键

    基本操作 断点,breakpoint: F5键与F6键均为单步调试: F5是step into,也就是进入本行代码中执行,跳入 F6是step over,跳过,也就是执行本行代码,跳到下一行 F7是跳 ...

  5. 在Salesforce中实现对Object的增删改查操作

    1): Insert Statement    http://www.salesforce.com/us/developer/docs/apexcode/index_Left.htm#CSHID=ap ...

  6. HDU 4812 D Tree 树分治+逆元处理

    D Tree Problem Description   There is a skyscraping tree standing on the playground of Nanjing Unive ...

  7. Java学习笔记(八)——封装

    一.封装 1.定义 将类的信息隐藏在类的内部,不允许外部程序直接进行访问,而是通过该类提供的方法来实现对隐藏信息的操作和方法. 2.优点 (1)只能通过规定的方法访问数据 (2)隐藏类的细节,方便修改 ...

  8. 主流IM协议简介

    四种主流的IM协议, XMPP协议.即时信息和空间协议(IMPP).空间和即时信息协议(PRIM).针对即时通讯和空间平衡扩充的进程开始协议SIP(SIMPLE). XMPP协议: 在这四种协议中,X ...

  9. T-SQL 高级查询

    基本常用查询 --select select * from student; --all 查询所有 select all sex from student; --distinct 过滤重复 selec ...

  10. 【hibernate 报错】No serializer found for class org.hibernate.proxy.pojo.javassist.JavassistLazyInitializer 【get和load的区别】

    报错: HTTP Status 500 - Could not write content: No serializer found for class org.hibernate.proxy.poj ...