• 【宽搜】XMU 1039 Treausure


    题目链接:

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

    题目大意

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

    题目思路:

      【搜索】

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

     1 //
     2 //by coolxxx
     3 //
     4 #include<iostream>
     5 #include<algorithm>
     6 #include<string>
     7 #include<iomanip>
     8 #include<memory.h>
     9 #include<time.h>
    10 #include<stdio.h>
    11 #include<stdlib.h>
    12 #include<string.h>
    13 //#include<stdbool.h>
    14 #include<math.h>
    15 #define min(a,b) ((a)<(b)?(a):(b))
    16 #define max(a,b) ((a)>(b)?(a):(b))
    17 #define abs(a) ((a)>0?(a):(-(a)))
    18 #define lowbit(a) (a&(-a))
    19 #define sqr(a) ((a)*(a))
    20 #define swap(a,b) ((a)^=(b),(b)^=(a),(a)^=(b))
    21 #define eps (1e-8)
    22 #define J 10000000
    23 #define MAX 0x7f7f7f7f
    24 #define PI 3.1415926535897
    25 #define N 1004
    26 #define M 50004
    27 using namespace std;
    28 typedef long long LL;
    29 int cas,cass;
    30 int n,m,lll,ans;
    31 int dx[]={-1,1,0,0};
    32 int dy[]={0,0,-1,1};
    33 int sx,sy;
    34 int q[M][2];
    35 char map[N][N];
    36 bool u[N][N];
    37 void spfa()
    38 {
    39     int i,j,x,y,xx,yy,h,t;
    40     q[1][0]=sx;q[1][1]=sy;
    41     h=0;t=1;u[sx][sy]=1;
    42     while(h!=t)
    43     {
    44         if(++h==M)h=1;
    45         x=q[h][0];y=q[h][1];
    46         for(j=0;j<4;j++)
    47         {
    48             xx=x+dx[j];yy=y+dy[j];
    49             if(map[xx][yy]=='#' || u[xx][yy] || xx<1 || yy<1 || xx>n || yy>m)continue;
    50             if(++t==M)t=1;
    51             q[t][0]=xx;q[t][1]=yy;
    52             u[xx][yy]=1;
    53             if(map[xx][yy]=='*')ans++;
    54         }
    55     }
    56 }
    57 int main()
    58 {
    59     #ifndef ONLINE_JUDGE
    60 //    freopen("1.txt","r",stdin);
    61 //    freopen("2.txt","w",stdout);
    62     #endif
    63     int i,j;
    64 //    for(scanf("%d",&cas);cas;cas--)
    65 //    for(scanf("%d",&cas),cass=1;cass<=cas;cass++)
    66 //    while(~scanf("%s",s))
    67     while(~scanf("%d",&n))
    68     {
    69         ans=0;
    70         memset(u,0,sizeof(u));
    71         scanf("%d",&m);
    72         for(i=1;i<=n;i++)
    73             scanf("%s",map[i]+1);
    74         for(i=1;i<=n;i++)
    75             for(j=1;j<=m;j++)
    76                 if(map[i][j]=='X'){sx=i;sy=j;break;}
    77         spfa();
    78         printf("%d
    ",ans);
    79     }
    80     return 0;
    81 }
    82 /*
    83 //
    84 
    85 //
    86 */
    千万不要点
  • 相关阅读:
    查看文件(或文件夹)被哪个进程使用【文件已在另一程序中打开】
    MinGW32和64位交叉编译环境的安装和使用
    MinGW下编译openssl, json-c
    曲演杂坛--SQLCMD下执行命令失败但没有任何错误提示的坑
    Python2.6下基于rsa的加密解密
    MySQL--使用xtrabackup进行备份还原
    Python--过滤Mysql慢日志
    MySQL--将MySQL数据导入到SQL Server
    Python--命令行参数解析Demo
    python--同一mysql数据库下批量迁移数据
  • 原文地址:https://www.cnblogs.com/Coolxxx/p/5692753.html
Copyright © 2020-2023  润新知