题目链接:

  http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1039

题目大意

  给定n,m(1<=n,m<=1000),一张n*m的地图,求从X出发上下左右走能找到多少*(#为障碍,*为宝藏)。

题目思路:

  【搜索】

  找到出发点坐标,之后上下左右搜索即可,在过程中统计走到的宝藏数。

 //
//by coolxxx
//
#include<iostream>
#include<algorithm>
#include<string>
#include<iomanip>
#include<memory.h>
#include<time.h>
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
//#include<stdbool.h>
#include<math.h>
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define abs(a) ((a)>0?(a):(-(a)))
#define lowbit(a) (a&(-a))
#define sqr(a) ((a)*(a))
#define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
#define eps (1e-8)
#define J 10000000
#define MAX 0x7f7f7f7f
#define PI 3.1415926535897
#define N 1004
#define M 50004
using namespace std;
typedef long long LL;
int cas,cass;
int n,m,lll,ans;
int dx[]={-,,,};
int dy[]={,,-,};
int sx,sy;
int q[M][];
char map[N][N];
bool u[N][N];
void spfa()
{
int i,j,x,y,xx,yy,h,t;
q[][]=sx;q[][]=sy;
h=;t=;u[sx][sy]=;
while(h!=t)
{
if(++h==M)h=;
x=q[h][];y=q[h][];
for(j=;j<;j++)
{
xx=x+dx[j];yy=y+dy[j];
if(map[xx][yy]=='#' || u[xx][yy] || xx< || yy< || xx>n || yy>m)continue;
if(++t==M)t=;
q[t][]=xx;q[t][]=yy;
u[xx][yy]=;
if(map[xx][yy]=='*')ans++;
}
}
}
int main()
{
#ifndef ONLINE_JUDGE
// freopen("1.txt","r",stdin);
// freopen("2.txt","w",stdout);
#endif
int i,j;
// for(scanf("%d",&cas);cas;cas--)
// for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
// while(~scanf("%s",s))
while(~scanf("%d",&n))
{
ans=;
memset(u,,sizeof(u));
scanf("%d",&m);
for(i=;i<=n;i++)
scanf("%s",map[i]+);
for(i=;i<=n;i++)
for(j=;j<=m;j++)
if(map[i][j]=='X'){sx=i;sy=j;break;}
spfa();
printf("%d\n",ans);
}
return ;
}
/*
// //
*/

千万不要点

【宽搜】XMU 1039 Treausure的更多相关文章

  1. poj1399 hoj1037 Direct Visibility 题解 (宽搜)

    http://poj.org/problem?id=1399 http://acm.hit.edu.cn/hoj/problem/view?id=1037 题意: 在一个最多200*200的minec ...

  2. 利用深搜和宽搜两种算法解决TreeView控件加载文件的问题。

    利用TreeView控件加载文件,必须遍历处所有的文件和文件夹. 深搜算法用到了递归. using System; using System.Collections.Generic; using Sy ...

  3. POJ1426 Find The Multiple (宽搜思想)

    Find The Multiple Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 24768   Accepted: 102 ...

  4. Colorado Potato Beetle(CF的某道) & 鬼畜宽搜

    题意: 一个人在一张大图上走,给你路径与起点,求他走出的矩形面积并.(大概这个意思自行百度标题... SOL: 与其说这是一道图论题不如说是一道生动活泼的STL-vector教学.... 离散化宽搜, ...

  5. BZOJ_1615_[Usaco2008_Mar]_The Loathesome_Hay Baler_麻烦的干草打包机_(模拟+宽搜/深搜)

    描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1615 一个主动轮带着一些轮子转,轮子带着轮子转,轮子带着轮子转...一个非主动轮只会被一个轮子 ...

  6. 【宽搜】ECNA 2015 D Rings (Codeforces GYM 100825)

    题目链接: http://codeforces.com/gym/100825 题目大意: 给你一张N*N(N<=100)的图表示一个树桩,'T'为年轮,'.'为空,求每个'T'属于哪一圈年轮,空 ...

  7. 【宽搜】ECNA 2015 E Squawk Virus (Codeforces GYM 100825)

    题目链接: http://codeforces.com/gym/100825 题目大意: N个点M条无向边,(N<=100,M<=N(N-1)/2),起始感染源S,时间T(T<10) ...

  8. 【拓扑】【宽搜】CSU 1084 有向无环图 (2016湖南省第十二届大学生计算机程序设计竞赛)

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1804 题目大意: 一个有向无环图(DAG),有N个点M条有向边(N,M<=105 ...

  9. 【图论】【宽搜】【染色】NCPC 2014 A Ades

    题目链接: http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1787 题目大意: N个点M条无向边(N,M<=200000),一个节点只能有一个 ...

随机推荐

  1. PermGen space错误解决方法

    在看下文之前,首先要确认意见事情,就是你是怎样启动tomcat的,我们在平时的开发环境其中,都是通过startup.bat方式启动tomcat的,那么你依照以下的方式,去改动/bin/catalina ...

  2. Java基础知识强化之集合框架笔记07:Collection集合的遍历之迭代器遍历

    1. Collection的迭代器: Iterator iterator():迭代器,集合的专用遍历方式 2. 代码示例: package cn.itcast_03; import java.util ...

  3. Android(java)学习笔记244:多媒体之SurfaceView

    1. SurfaceView:     完成单位时间内界面的快速切换(游戏界面流畅感). 我们之前知道一般的View,只能在主线程里面显示,主线程中更新UI.但是SurfaceView可以在子线程中里 ...

  4. android中获取时间

    android中获取时间 1)通过calendar类获取 Calendar calendar = Calendar.getInstance();int moth = calendar.get(Cale ...

  5. 3xian之所在

    最后一天,漫天飘起了雪花,假装欢送我离去. 这次WF之战不太顺利,早期的C题大概花了1秒钟构思,然而由于输出格式多了一个空格直到两个半小时才逃脱Wrong Answer的纠缠.还好lynncui在期间 ...

  6. AmazeUI 模态框封装

    /** * 模态窗口 */ window.Modal = { tpls:{ alert:'<div class="am-modal am-modal-alert" tabin ...

  7. 谷歌插件postman如果不能用,就用git命令发送post请求

     curl -X POST --data '{"name":"zfpx"}' -H 'Content-Type:application/json' http:/ ...

  8. Linux下安装php加速组件XCache

    这里选择的是稳定版本的1.2.2版本,2.0版本的不稳定.wget http://xcache.lighttpd.net/pub/Releases/1.2.2/xcache-1.2.2.tar.gzt ...

  9. javascript基础学习(十三)

    javascript之文档对象 学习要点: 文档对象 文档对象的应用 一.文档对象 Document对象是代表一个浏览器窗口或框架中的显示HTML文件的对象.javascript会为每个HTML文档自 ...

  10. JDK1.5中LOCK,Condition的使用

    import java.util.concurrent.locks.Condition; import java.util.concurrent.locks.Lock; import java.uti ...