zoukankan      html  css  js  c++  java
  • hdu2653 Waiting ten thousand years for Love

    题意:还是类似迷宫问题,已知起点和终点,在规定时间内求出到达终点的最少时间。

    有俩种行走方式

    1)飞行:

    除了遇到‘#’ 以外,任何地方都能穿过,但需要消耗1s,同时消耗1 魔法值

    注意:理论上遇到一个‘@’要消耗俩点魔法值,因为离开这个‘@’ 要消耗2点魔法值

    2)行走:

    有俩种情况不能走,1,遇到‘#’;2当前点是‘@’ 或者遇到的点是‘@’

    View Code
    #include<iostream>
    #include<algorithm>
    #include<queue>
    using namespace std;
    char g[100][100];
    bool vis[88][88][88];
    int n,m,p,t,si,sj,ans;
    int dir[4][2]={{1,0},{0,1},{-1,0},{0,-1}};
    struct node
    {
    int step,p,x,y;
    node(int a=0,int b=0,int c=0,int d=0):x(a),y(b),p(c),step(d){}
    bool friend operator <(const node a,const node b)
    {
    return a.step>b.step;
    }
    };
    void BFS()
    {
    priority_queue<node> Q;
    node f=node(si,sj,p,0);
    Q.push(f);
    memset(vis,false,sizeof(vis));
    vis[si][sj][p]=true;
    node temp;
    while(!Q.empty())
    {
    temp=Q.top();
    Q.pop();
    if(temp.step>t)
    return ;
    if(g[temp.x][temp.y]=='L')
    {
    ans=temp.step;
    return ;
    }
    for(int k=0;k<4;k++)
    {
    int i=dir[k][0]+temp.x;
    int j=dir[k][1]+temp.y;
    if(i<0||i>n-1 || j<0 || j>m-1||g[i][j]=='#')
    continue;
    if(temp.p!=0 && !vis[i][j][temp.p-1])
    {
    vis[i][j][temp.p-1]=true;
    Q.push(node(i,j,temp.p-1,temp.step+1));
    }
    if(g[temp.x][temp.y]!='@' && g[i][j]!='@'&&!vis[i][j][temp.p])
    {
    vis[i][j][temp.p]=true;
    Q.push(node(i,j,temp.p,temp.step+2));
    }
    }
    }
    return ;
    }
    int main()
    {
    int cas=0;
    while(scanf("%d %d %d %d",&n,&m,&t,&p)==4)
    {
    for(int i=0;i<n;i++)
    {
    scanf("%s",g[i]);
    for(int j=0;j<m;j++)
    if(g[i][j]=='Y')
    si=i,sj=j;
    }
    ans=100001;
    BFS();
    printf("Case %d:\n",++cas);
    if(ans>t)
    printf("Poor Yifenfei, he has to wait another ten thousand years.\n");
    else printf("Yes, Yifenfei will kill Lemon at %d sec.\n",ans);
    }
    return 0;
    }
  • 相关阅读:
    No bean named 'springSecurityFilterChain' is defined
    Spring管理hibernate Session
    集成hibernate
    Maven setting.xml
    SpringMVC集成Spring
    搭建SpringMVC
    一个简单的web project
    一文带你认识Java8中接口的默认方法
    抽象类和模板方法模式
    可能你不知道的,关于自动装箱和自动拆箱
  • 原文地址:https://www.cnblogs.com/nanke/p/2349480.html
Copyright © 2011-2022 走看看