题目链接:

  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. [Angular 2] Template property syntax

    This lesson covers using the [input] syntax to change an element property such as “hidden” or “conte ...

  2. Android(java)学习笔记239:多媒体之撕衣服的案例

    1.撕衣服的案例逻辑:       是两者图片重叠在一起,上面我们看到的是美女穿衣服的图片,下面重叠(看不到的)是美女没有穿衣服的图片.当我们用手滑动画面,上面美女穿衣服的图片就会变成透明,这样的话下 ...

  3. IOS 获取wifi的SSID

    #import <SystemConfiguration/CaptiveNetwork.h> - (NSString *)currentWifiSSID { // Does not wor ...

  4. 【IOS】关于CGTransform的几个动画

    1.CGTransform主要三大功能,平移(Translation).缩放(Scale).旋转(Rotate). 平移: self.imageView.transform = CGAffineTra ...

  5. 动态用javascript来修改单选框性别

    <script> window.onload=function(){ if(<{$data.sex}>==0){//<{$data.sex}>是在数据读出来: do ...

  6. leetcode修炼之路——383. Ransom Note

    题目是这样的 Given
 an 
arbitrary
 ransom
 note
 string 
and 
another 
string 
containing 
letters from
 a ...

  7. ORACLE 解析xml字符串-转载的

    --------------------------方法一------------------------------------- 1.xml字符串 /* <orderlist>     ...

  8. GCD多线程 在子线程中获取网络图片 在主线程更新

    子线程中得所有数据都可以直接拿到主线程中使用 //当触摸屏幕的时候,从网络上下载一张图片到控制器的view上显示 -(void)touchesBegan:(NSSet *)touches withEv ...

  9. Notepad++中查找替换回车符

    用Nodepad++打开文件 View->Show Symbol->Show End of Line "End of Line"行结束符,由"CR" ...

  10. directshow filter 调试步骤

    1,编写filter 2,在debug模式下build 3,注册filter:控制台cd到工程的debug目录下,即欲注册的filter(.ax文件)目录,xx:>regsvr32 contra ...