社区讨论
求助站外题
灌水区参与者 1已保存回复 0
讨论操作
快速查看讨论及其快照的属性,并进行相关操作。
- 当前回复
- 0 条
- 当前快照
- 1 份
- 快照标识符
- @lo978au6
- 此快照首次捕获于
- 2023/10/28 06:42 2 年前
- 此快照最后确认于
- 2023/10/28 06:42 2 年前
ybt 1253
代码:
CPP#include<bits/stdc++.h>
using namespace std;
struct node{
int di;
};
int n;
int k[100000];
int ans[100000];
bool jc(int aa){
if(ans[aa]>0)return 0;
if(aa<0||aa>100000)return 0;
return 1;
}
int a,b;
void wwd(int x){
queue<node>q;
node ay;
ay.di=x;
q.push(ay);
ans[x]=1;
while(q.empty()==0){
int as;
as=q.front().di;
int ae;
ae=as-1;
if(jc(ae)){
ans[ae]=ans[as]+1;
node by;
by.di=ae;
q.push(by);
}
if(ae==b){
cout<<ans[ae]-1;
return ;
}
ae=as+1;
if(jc(ae)){
ans[ae]=ans[as]+1;
node by;
by.di=ae;
q.push(by);
}
if(ae==b){
cout<<ans[ae]-1;
return ;
}
ae=as*2;
if(jc(ae)){
ans[ae]=ans[as]+1;
node by;
by.di=ae;
q.push(by);
}
if(ae==b){
cout<<ans[ae]-1;
return ;
}
q.pop();
}
}
int main(){
cin>>a>>b;
if(a==b){
cout<<0;
return 0;
}
wwd(a);
return 0;
}
为什么但凡数据大一点就爆了!!!
回复
共 0 条回复,欢迎继续交流。
正在加载回复...