zoukankan      html  css  js  c++  java
  • 刷一刷存在感hahahh

    这两天突然觉得两空格缩进看着好舒服 感觉比四空格紧凑 连贯 hahahh

      1 #include<bits/stdc++.h>
      2 #define cl(a,b) memset(a,b,sizeof(a))
      3 #define debug(a) cerr<<#a<<"=="<<a<<endl
      4 using namespace std;
      5 typedef long long ll;
      6 typedef pair<int,int> pii;
      7 
      8 const int maxn=50+10;
      9 
     10 int n,m,k,sx,sy;
     11 int vis[maxn][maxn];
     12 int dx[maxn],dy[maxn];
     13 char mp[maxn][maxn];
     14 struct loc
     15 {
     16   pii point;
     17   int step;
     18 };
     19 
     20 bool check(pii x)
     21 {
     22   if(x.first<0||x.first>=n) return false;
     23   if(x.second<0||x.second>=m) return false;
     24   if(mp[x.first][x.second]=='X') return false;
     25   return (!vis[x.first][x.second]);
     26 }
     27 
     28 int bfs()
     29 {
     30   loc st= {{sx,sy},0};
     31   queue<loc>q;
     32   while(!q.empty()) q.pop();
     33   q.push(st);
     34   int ans=-1;
     35   while(!q.empty())
     36   {
     37     loc now=q.front();
     38     q.pop();
     39     if(mp[now.point.first][now.point.second]=='.') ans=max(ans,now.step);
     40     for(int i=0; i<k; i++)
     41     {
     42       int nextx=now.point.first+dx[i];
     43       int nexty=now.point.second+dy[i];
     44       pii next= {nextx,nexty};
     45       if(check(next))
     46       {
     47         vis[next.first][next.second]=true;
     48         q.push({next,now.step+1});
     49       }
     50     }
     51   }
     52   return ans;
     53 }
     54 
     55 int main()
     56 {
     57   scanf("%d%d",&n,&m);
     58   for(int i=0; i<n; i++)
     59   {
     60     scanf("%s",mp[i]);
     61   }
     62   scanf("%d%d",&sx,&sy);
     63   vis[sx][sy]=true;
     64   scanf("%d",&k);
     65   for(int i=0; i<k; i++)
     66   {
     67     scanf("%d%d",&dx[i],&dy[i]);
     68   }
     69   int ans=bfs();
     70   for(int i=0; i<n; i++)
     71   {
     72     for(int j=0; j<m; j++)
     73     {
     74       if(!vis[i][j]&&mp[i][j]=='.')
     75       {
     76           //printf("%d %d
    ",i,j);
     77         ans=-1;
     78       }
     79     }
     80   }
     81   printf("%d
    ",ans);
     82   return 0;
     83 }/*
     84 
     85 10 10
     86 .XXXXXXXX.
     87 X.XXXXXX.X
     88 XX.XXXX.XX
     89 XXX.XX.XXX
     90 XXXX..XXXX
     91 XXXX..XXXX
     92 XXXX.X.XXX
     93 XXX.XXX.XX
     94 XX.XXXXX.X
     95 X.XXXXXXX.
     96 0 0
     97 18
     98 0 9
     99 9 0
    100 0 -8
    101 -8 0
    102 0 7
    103 7 0
    104 0 -6
    105 -6 0
    106 0 5
    107 5 0
    108 0 -4
    109 -4 0
    110 0 3
    111 3 0
    112 0 -2
    113 -2 0
    114 0 1
    115 1 0
    116 
    117 
    118 */
  • 相关阅读:
    关于lockkeyword
    关于多层for循环迭代的效率优化问题
    Android 面试精华题目总结
    Linux基础回想(1)——Linux系统概述
    linux源代码编译安装OpenCV
    校赛热身 Problem C. Sometimes Naive (状压dp)
    校赛热身 Problem C. Sometimes Naive (状压dp)
    校赛热身 Problem B. Matrix Fast Power
    校赛热身 Problem B. Matrix Fast Power
    集合的划分(递推)
  • 原文地址:https://www.cnblogs.com/general10/p/9083764.html
Copyright © 2011-2022 走看看