bfs遍历一遍就行了。

/* ***********************************************
Author :guanjun
Created Time :2016/6/15 18:50:31
File Name :1012.cpp
************************************************ */
#include <iostream>
#include <cstring>
#include <cstdlib>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <string>
#include <math.h>
#include <stdlib.h>
#include <iomanip>
#include <list>
#include <deque>
#include <stack>
#define ull unsigned long long
#define ll long long
#define mod 90001
#define INF 0x3f3f3f3f
#define maxn 10010
#define cle(a) memset(a,0,sizeof(a))
const ull inf = 1LL << ;
const double eps=1e-;
using namespace std;
priority_queue<int,vector<int>,greater<int> >pq;
struct Node{
int x,y;
};
struct cmp{
bool operator()(Node a,Node b){
if(a.x==b.x) return a.y> b.y;
return a.x>b.x;
}
}; bool cmp(int a,int b){
return a>b;
}
struct node{
int x,y;
};
char mp[][];
int sx,sy;
int n,m;
int dir[][]={,,,,,-,-,};
int vis[][];
int bfs(){
queue<node>q;
cle(vis);
node u={
sx,sy
};
int ans=;
q.push(u);
while(!q.empty()){
u=q.front();
ans++;
q.pop();
node v;
for(int i=;i<;i++){
v.x=u.x+dir[i][];
v.y=u.y+dir[i][];
if(v.x<=n&&v.x>=&&v.y<=m&&v.y>=&&mp[v.x][v.y]=='.'&&!vis[v.x][v.y]){
vis[v.x][v.y]=;
q.push(v);
}
}
}
return ans; }
int main()
{
#ifndef ONLINE_JUDGE
freopen("in.txt","r",stdin);
#endif
//freopen("out.txt","w",stdout);
int T;
cin>>T;
for(int t=;t<=T;t++){
scanf("%d%d",&m,&n);
for(int i=;i<=n;i++){
for(int j=;j<=m;j++){
cin>>mp[i][j];
if(mp[i][j]=='@')sx=i,sy=j;
}
}
printf("Case %d: %d\n",t,bfs());
}
return ;
}

Lightoj 1012 - Guilty Prince的更多相关文章

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

  2. light 1012 Guilty Prince

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

  3. LightOJ 1012 简单bfs,水

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

  4. Guilty Prince LightOJ - 1012

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

  5. lightoj 1012

    水题,dfs #include<cstdio> #include<string> #include<cstring> #include<iostream> ...

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

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

  7. lightoj刷题日记

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

  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. jenkins 提示No emails were triggered

    发送邮件 Jenkins->系统管理->系统设置,在“邮件通知”里设置smtp服务器地址,以及发送者邮箱地址,在具体的任务构建完成以后,可以设置发送邮件,在某一个任务的"Add ...

  2. BZOJ 3926: [Zjoi20150]诸神眷顾的幻想乡

    3926: [Zjoi20150]诸神眷顾的幻想乡 Time Limit: 10 Sec  Memory Limit: 512 MBSubmit: 438  Solved: 273 Descripti ...

  3. 【数据传输 1】服务器—>客户端之间的数据类型转换

    导读:在做项目的时候,在controller中,将List数据类型转换为了JSON字符串,那么,为什么要将其数据转换为JOSN呢?这样的转换是否是必须的,在这个转换过程中,又经过了那些步骤?注:本篇博 ...

  4. [Go]指针操作

    指针类型比较常见 type Dog struct { name string } func (dog *Dog) SetName (name string){ dog.name = name } 对于 ...

  5. k/3cloud表格控件块粘贴代码逻辑

    大家可以在表单插件EntityBlockPasting事件中自己处理,然后将cancel设置为true.以下代码可以参考一下,插件代码中需要将其中一些属性或方法修改,例如this.BusinessIn ...

  6. 新版VS-code如何自动换行?

    文件  -> 首选项 -> 设置 -> 编辑器 找到 // 控制折行方式.可以选择: - "off" (禁用折行), - "on" (视区折行 ...

  7. centos 中找不到 php-config

    两种解决方式: 1.CentOS6 PHP extension install: Cannot find php-config. Please use --with-php-config=PATH 2 ...

  8. CodeForces 593A 2Char

    暴力. #include<cstdio> #include<cstring> #include<cmath> #include<algorithm> u ...

  9. express 写接口

    实例下载:百度云盘免密码 (): 指注释 一.准备工作 1.安装express npm install express -g npm install express-generator -g 2.初始 ...

  10. 动态规划:Ignatius and the Princess IV

    #include<stdio.h> #include<string.h> #include<math.h> int main() { _int64 n,a; whi ...