zoukankan      html  css  js  c++  java
  • HDU 3345

     1 #include<cstdio>
     2 #include<queue>
     3 #include<cstring>
     4 using namespace std;
     5 int n,m,mv;char map[103][103];bool vis[103][103];
     6 struct type{
     7     int i,j,mv;
     8     bool operator<(const type &oth)const  
     9     {
    10         return mv<oth.mv;  
    11     }  
    12 }st;
    13 int di[4]={0,-1,0,+1};
    14 int dj[4]={+1,0,-1,0};
    15 bool isout(int i,int j){
    16     if(i<1 || i>n || j<1 || j>m) return true;
    17     else return false;
    18 }
    19 bool is_near_enemy(int i,int j){
    20     for(int k=0;k<4;k++){
    21         type next;
    22         next.i=i+di[k],next.j=j+dj[k];
    23         if(!isout(next.i,next.j) && map[next.i][next.j] == 'E') return true;
    24     }
    25     return false;
    26 }
    27 void bfs()
    28 {
    29     priority_queue<type> q;
    30     type now,next;
    31     memset(vis,0,sizeof(vis));
    32     q.push(st);vis[st.i][st.j]=1;
    33     while(!q.empty())
    34     {
    35         now=q.top();q.pop();
    36         if(now.mv<=0) continue;
    37         for(int k=0;k<4;k++)
    38         {
    39             next.i=now.i+di[k] , next.j=now.j+dj[k] , next.mv=now.mv;
    40             if(vis[next.i][next.j] || isout(next.i,next.j) || map[next.i][next.j]=='E' || map[next.i][next.j] == '#') continue;
    41             if(map[next.i][next.j]=='.') next.mv--;  
    42             else if(map[next.i][next.j]=='T') next.mv-=2; 
    43             else if(map[next.i][next.j]=='R') next.mv-=3;  
    44             else if(map[next.i][next.j]=='P') next.mv--;
    45             
    46             if(next.mv<0) continue;
    47             if(is_near_enemy(next.i,next.j)) next.mv=0;
    48             if(map[next.i][next.j] != 'P') map[next.i][next.j]='*';
    49             vis[next.i][next.j]=1;q.push(next);
    50         }
    51     }
    52 }
    53 int main()
    54 {
    55     int t;
    56     scanf("%d",&t);
    57     while(t--)
    58     {
    59         scanf("%d%d%d",&n,&m,&mv);
    60         for(int i=1;i<=n;i++){
    61             scanf("%s",map[i]+1);
    62             for(int j=1;j<=m;j++) if(map[i][j]=='Y') st.i=i , st.j=j , st.mv=mv;
    63         }
    64         bfs();
    65         for(int i=1;i<=n;i++){
    66             printf("%s
    ",map[i]+1);
    67         }
    68         printf("
    ");
    69     }
    70 }

  • 相关阅读:
    数据集冲突
    苹果如何设计iPad的商业模式
    IT部门应如何制定技术路线图
    关于软件测试
    c#写文件
    正则表达式语法及常用表达式。
    使用Mysql的Replication功能实现数据库同步
    CMMI=大象关冰箱?
    asp.net 中RegularExpressionValidator的bug|IE的bug?
    Singleton 模式的Java和C#的实现方法
  • 原文地址:https://www.cnblogs.com/dilthey/p/6804150.html
Copyright © 2011-2022 走看看