Waiting ten thousand years for Love

Yifenfei为了复仇并拯救爱人,要在限定时间内穿越迷宫般的城堡找到恶魔Lemon。利用广度优先搜索结合优先队列算法,考虑走动与飞行的不同成本及魔法值限制,帮助Yifenfei制定最优路径。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

最后一道搜索题,关键是划分状态。分析这道题:

如果以(x,y)为状态,无法唯一确定状态。因为(‘.’ Indicate the road that Yifenfei can walk on it, or fly over it.)

所以必须要(x,y,p)为状态区分。

本题采用bfs+优先队列

It was ten thousand years, after Demon Lemon caught Yifenfei’s love. In order to revenge and save his love, Yifenfei have been practising sword all day long and his Kongfu skills becomes so powerful that he can kill Demon Lemon immediately. Recently, Yifenfei have found Lemon’s castle, and now he is going to kill Lemon. At the same time, hearing about the terrible news, Demon Lemon is now preparing for escaping...

Now Yifenfei has got the map of the castle.
Here are all symbols of the map:
Only one ‘Y’ Indicates the start position of Yifenfei.
Only one ‘L’ Indicates the position of Demon Lemon.
‘.’ Indicate the road that Yifenfei can walk on it, or fly over it.
‘#’ Indicate the wall that Yifenfei can not walk or flay through it.
‘@’ Indicate the trap that Yifenfei can not walk on it, but can fly over it.

Yifenfei can walk or fly to one of up, down, left or right four directions each step, walk costs him 2 seconds per step, fly costs him 1 second per step and 1 magic power. His magic power will not increased, and if his magic power is zero, he can not fly any more.

Now Yifenfei asks you for helping him kill Demon Lemon smoothly. At the same time, Demon Lemon will Leave the castle Atfer T seconds. If Yifenfei can’t kill Demon Lemon this time, he have to wait another ten thousand years.
 

Input
Lots of test cases, please process to end of file. In each test case, firstly will have four integers N, M, T, P(1 <= N, M, P <= 80, 1 <= T <= 100000), indicates the size of map N * M, the Lemon’s leaving time(after T seconds, Lemon will disappeared) and Yifenfei’s magic power. Then an N * M two-dimensional array follows indicates the map.
 

Output
For each test case, first Print a line “Case C:”, C indicates the case number. Then, if Yifenfei can kill Demon Lemon successfully, Print “Yes, Yifenfei will kill Lemon at T sec.”, T indicates the minimum seconds he must cost. Otherwise, Print ”Poor Yifenfei, he has to wait another ten thousand years.”
 

Sample Input
2 3 2 2 Y@L ### 2 3 4 1 Y@L ### 2 3 4 0 Y.L ### 2 3 3 0 Y.L ###
 

Sample Output
Case 1: Yes, Yifenfei will kill Lemon at 2 sec. Case 2: Poor Yifenfei, he has to wait another ten thousand years. Case 3: Yes, Yifenfei will kill Lemon at 4 sec. Case 4: Poor Yifenfei, he has to wait another ten thousand years.
Hint
Hint Case 1: Yifenfei cost 1 second and 1 magic-power fly to ‘@’, but he can not step on it, he must cost another 1 second and 1 magic-power fly to ‘L’ and kill Lemon immediately. Case 2: When Yifenfei Fly to ‘@’, he has no power to fly, and is killed by trap.


#include<iostream>
#include<queue>
using namespace std;
typedef struct node{
    int i;
int j;
int t;
int p;


    
}Node;
struct qcmp
 {
     bool operator() (const Node a,const Node b)
     {
         return a.t>b.t;
     }
 };
char field[81][81];


int N,M,T,P;
bool isvisit[81][81][81];
bool cross(int a,int b)
{
   if(a>=0&&a<N&&b>=0&&b<M&&field[a][b]!='#')
   {
      return true;
   }
   return false;


}
int dir[][2]={{0,1},{1,0},{-1,0},{0,-1}};
 
void bfs(int a,int b)
{
    bool isfind=false;
int count=0;
Node start={a,b,0,P};
isvisit[a][b][P]=true;
priority_queue<Node,vector<Node>,qcmp> myqueue;
myqueue.push(start);
while(!myqueue.empty())
{
  Node pre=myqueue.top();
  myqueue.pop();
  if(pre.t<=T&&field[pre.i][pre.j]=='L')
  {
    isfind=true;
count=pre.t;

break; 
  }
  if(pre.t>T)
  break;
  
  for(int i=0;i<4;i++)
  {
  int curi=pre.i+dir[i][0];
  int curj=pre.j+dir[i][1];
  int curp=pre.p;
  int curt=pre.t;
     if(cross(curi,curj)&&pre.t<T)
 {
    if(field[pre.i][pre.j]!='@'&&field[curi][curj]!='@'&&!isvisit[curi][curj][curp])
{
   
  isvisit[curi][curj][curp]=true;
  int tempt=curt;
  tempt+=2;
  Node cur1={curi,curj,tempt,curp};
  myqueue.push(cur1);
 

if(!isvisit[curi][curj][curp-1]&&curp>0)
{
 isvisit[curi][curj][curp-1]=true;
 curt+=1;
 curp-=1;
 Node cur2={curi,curj,curt,curp};
 myqueue.push(cur2);
 
}
 
 }
  
  
  
  }
  
     
  }
     

  
 






   if(isfind)
   {
    printf("Yes, Yifenfei will kill Lemon at %d sec.\n",count);  
   }
   else
   {
     printf("Poor Yifenfei, he has to wait another ten thousand years.\n");
   }


}
int main()
{
//freopen("in.txt","r",stdin);
int icase=0;
int i,j;
while(scanf("%d%d%d%d",&N,&M,&T,&P)!=EOF)
{
int s1,s2;
  for(i=0;i<N;i++)
  {
    for(j=0;j<M;j++)
{
   cin>>field[i][j];
if(field[i][j]=='Y')
{
 s1=i;
 s2=j;

}

}
  }
  memset(isvisit,false,sizeof(isvisit));
 
       cout<<"Case "<<++icase<<":"<<endl;
  bfs(s1,s2);



}
  return 0;
}

### 如何解决 `waiting for device` 连接问题 #### 设备未被正确识别的情况 当遇到设备连接等待问题时,可能是因为ADB未能成功识别目标设备。这通常发生在Android Studio中启动虚拟机或真实设备调试过程中。如果出现`waiting for target device to come online`的信息,则可以尝试重启adb服务来解决问题[^1]。 ```bash adb kill-server adb start-server ``` #### USB驱动程序缺失或不兼容 对于物理设备而言,USB驱动程序的缺乏或是版本不合适也会造成类似的错误提示。确保已经安装了适用于操作系统的正确USB驱动,并且开启了手机上的开发者选项以及USB调试模式。另外,在Windows平台上还需要确认是否已启用“允许未知来源的应用”。 #### 使用Frida工具集时特定情况下的处理方式 针对使用Frida框架进行逆向工程分析时碰到的`Waiting for USB device to appear...`状况,除了更新至最新稳定版之外,还可以考虑采用远程主机转发端口的方法绕过此障碍。具体做法如下: - 建立本地到远端指定端口号之间的映射关系; ```bash adb forward tcp:27042 tcp:27042 ``` - 利用该通道执行后续指令 ```bash frida-ps -H 127.0.0.1:27042 ``` 这种方法能够有效规避因某些原因造成的直接通过USB接口访问失败的问题[^2]。 #### Fastboot模式下长时间停留于等待界面 如果是处于Fastboot状态下遇到了持续性的`< waiting for device >`现象,那么可能是由于计算机与移动终端间的通信存在问题所引起的。此时建议先拔插一次Type-C线缆再试;若依旧无法恢复正常工作流程的话,不妨试着切换不同的电脑USB端口试试看能否有所改善。此外,也有可能是fastboot本身存在Bug或者是硬件层面的因素所致,必要时可联系厂商寻求技术支持帮助排查故障根源所在[^3]。 #### 开机启动项依赖性失效引发的现象 有时操作系统内部的服务间相互依存关系遭到破坏同样会表现为类似症状——即在引导阶段超时等待某个组件完成初始化动作。此类情形多见于Linux发行版之中,特别是那些经过自定义修改过的系统镜像。为了防止这类事件的发生,应当谨慎对待任何关于内核参数调整的操作,同时定期备份重要配置文件以防万一。一旦发现有异常表现,立即查阅日志记录定位根本原因并采取相应措施予以修复[^4]。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值