题意:一共有 T 组测试数据,每组先给两个数,w,h,表示给一个 高h,宽w的矩阵,‘#’表示不能走,‘.’表示能走,‘@’表示起始点,问,从起始点出发能访问多少个点。

  简单的BFS题,以前做过一次。

#include<stdio.h>
#include<string.h> struct node{
int x,y;
};
node q[];
int head,tail;
int visit[][];
int dx[]={,,-,};
int dy[]={,,,-};
int w,h;
int sx,sy;
int ans;
int OK(int x,int y)
{
if(x>= && x<=h && y>= && y<=w && !visit[x][y])
return ;
return ;
}
void Deal()
{
head=tail=; node t,t1;
t.x=sx;t.y=sy;
q[++tail]=t;
visit[sx][sy]=;
ans=; while(head<tail)
{
t=q[++head]; for(int i=;i<;i++)
{
int xx=t.x+dx[i];
int yy=t.y+dy[i];
if(OK(xx,yy))
{
ans++;
visit[xx][yy]=;
t1.x=xx;t1.y=yy;
q[++tail]=t1;
}
}
}
}
int main()
{
int T,cas=;
char ch[];
scanf("%d",&T);
while(T--)
{
memset(visit,,sizeof(visit));
scanf("%d%d",&w,&h);
for(int i=;i<=h;i++)
{
scanf("%s",ch+);
for(int j=;j<=w;j++)
{
if(ch[j]=='#') visit[i][j]=;
if(ch[j]=='@') sx=i,sy=j;
}
}
Deal();
printf("Case %d: %d\n",cas++,ans);
}
return ;
}

light 1012 Guilty Prince的更多相关文章

  1. Lightoj 1012 - Guilty Prince

    bfs遍历一遍就行了. /* *********************************************** Author :guanjun Created Time :2016/6/ ...

  2. Guilty Prince LightOJ - 1012

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

  3. LightOJ 1012.Guilty Prince-DFS

    Guilty Prince  Time Limit: 2 second(s) Memory Limit: 32 MB Once there was a king named Akbar. He had ...

  4. LightOJ 1012 简单bfs,水

    1.LightOJ 1012  Guilty Prince  简单bfs 2.总结:水 题意:迷宫,求有多少位置可去 #include<iostream> #include<cstr ...

  5. LightOJ——1012Guilty Prince(连通块并查集)

    1012 - Guilty Prince Time Limit: 2 second(s) Memory Limit: 32 MB Once there was a king named Akbar. ...

  6. lightoj刷题日记

    提高自己的实力, 也为了证明, 开始板刷lightoj,每天题量>=1: 题目的类型会在这边说明,具体见分页博客: SUM=54; 1000 Greetings from LightOJ [简单 ...

  7. A Game of Thrones(20) - Eddard

    Eddard Stark rode through the towering bronze doors of the Red Keep sore, tired, hungry, and irritab ...

  8. LightOJ1012-Guilty Prince-DFS

    Guilty Prince  Time Limit: 2 second(s) Memory Limit: 32 MB Once there was a king named Akbar. He had ...

  9. PAT天梯赛练习题——L3-004. 肿瘤诊断(三维连通块并查集)

    L3-004. 肿瘤诊断 时间限制 400 ms 内存限制 65536 kB 代码长度限制 8000 B 判题程序 Standard 作者 陈越 在诊断肿瘤疾病时,计算肿瘤体积是很重要的一环.给定病灶 ...

随机推荐

  1. uploadify按钮中文乱码问题

    uploadify是一款基于jQuery库的上传插件,但很可惜的是无论你怎么设置参数buttonText ,它的中文按钮都会出现乱码的情况,现把出现原因及解决方法总结如下.       那么出现这种的 ...

  2. 在美国公司架构中,LLC、LLP 和 Corporation 的区别何在?

    这个问题,首先需要弄清楚这样一个事实:LLC.LLP.Corporation分别属于三种不同类型的公司实体. 1,LLC (Limited Liability Company)是责任有限公司: 2,L ...

  3. dojo.io.script

    dojo.io.script 定义: 跨域访问数据,可以动态的将script标签插入到网页当中. 局限: 1.只支持get方式访问: 2.只支持异步调用. 使用: 1.dojo.io.script.g ...

  4. Uva 10652 Board Wrapping(计算几何之凸包+点旋转)

    题目大意:给出平面上许多矩形的中心点和倾斜角度,计算这些矩形面积占这个矩形点形成的最大凸包的面积比. 算法:GRAHAM,ANDREW. 题目非常的简单,就是裸的凸包 + 点旋转.这题自己不会的地方就 ...

  5. J - A + B Problem II(第二季水)

    Description I have a very simple problem for you. Given two integers A and B, your job is to calcula ...

  6. mysql 互为主从复制常见问题

    报错:1)change master导致的:              Last_IO_Error: error connecting to master - retry-time: 60  retr ...

  7. jquery 字符个数(数字字母长度记为1,中文记为2,超过长度自动截)

    <script type="text/javascript">  //返回val的字节长度  function getByteLen(val) {  var len = ...

  8. 《JavaScript Dom编程艺术》用例总结

    页首HTML 代码如下: <!DOCTYPE html> <html lang="en"> <head> <meta charset=&q ...

  9. 关于php输入$_post[‘’]报错的原因

    在php中输入$_post[‘’]值时页面报错,是因为变量未声明,所以页面出现提示Undefined index,是因为首先要用isset来判断是否存在这个变量. 如:isset($_POST['/* ...

  10. Leetcode 100 Same Tree python

    题目: Given two binary trees, write a function to check if they are equal or not. Two binary trees are ...