社区讨论
这题可以BFS吗
学术版参与者 2已保存回复 1
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 1 条
- 当前快照
- 1 份
- 快照标识符
- @lo18mxj4
- 此快照首次捕获于
- 2023/10/22 16:59 2 年前
- 此快照最后确认于
- 2023/11/02 16:50 2 年前
rt,q,b,p,q,s,k<=500
我bfs没过第2个点

CPP我bfs没过第2个点

#include<iostream>
#include<queue>
using namespace std;
struct node{
int rx,gx,t,x,y;
//steve血 怪血 时间
};
int a,b,p,q,s,k;
bool map[1000][1000];
queue<node>qu;
node make_node(int rx,int gx,int t,int x,int y){
node make;
make.rx=rx,make.gx=gx,make.t=t,make.x=x,make.y=y;
return make;
}
void dfs(){
while(!qu.empty()){
int len=qu.size();
while(len--){
node now=qu.front();
//操作不可逆 所以是x+1 或者y+1
if(!map[now.x+1][now.y]){
bool flag=true;
map[now.x+1][now.y]=true;
node last=make_node(now.rx-p,now.gx-p,now.t+1,now.x+1,now.y);
if(last.gx<=0&&last.rx==k){
cout<<last.rx<<" "<<last.gx<<" "<<last.t<<" "<<last.x<<" "<<last.y<<endl;
cout<<last.t;
return;
//怪死了且人血量为k
}
if(last.rx<=0||last.gx<=0){
flag=false;
//人死了或怪死了
}
last.gx=min(last.gx+q,b);
//血量加回去
if(flag)qu.push(last);
}
if(!map[now.x][now.y+1]){
bool flag=true;
map[now.x][now.y+1]=true;
node last=make_node(min(now.rx+s,a),now.gx,now.t+1,now.x,now.y+1);
if(last.gx<=0&&last.rx==k){
cout<<last.rx<<" "<<last.gx<<" "<<last.t<<" "<<last.x<<" "<<last.y<<endl;
cout<<last.t;
return;
//怪死了且人血量为k
}
if(last.rx<=0||last.gx<=0){
flag=false;
//人死了或怪死了
}
last.gx=min(last.gx+q,b);
//血量加回去
if(flag)qu.push(last);
}
printf("%d %d %d %d %d\n",now.rx,now.gx,now.t,now.x,now.y);
qu.pop();
}
}
cout<<-1;
return;
}
int main(){
cin>>a>>b>>p>>q>>s>>k;
node qd=make_node(a,b,0,0,0);
map[0][0]=true;
qu.push(qd);
dfs();
return 0;
}
回复
共 1 条回复,欢迎继续交流。
正在加载回复...