- 抓住那头牛
90wa第一个点-1就对
- 2025-2-26 13:37:48 @
#include<iostream>
#include<queue>
using namespace std;
struct node{
int idx,cnt;
};
int n,k;
bool s[100010];
queue<node> q;
void bfs(int x){
s[x]=1;
q.push({x,0});
while(!q.empty()){
node t=q.front();
q.pop();
if(t.idx==k){
cout<<t.cnt;
return;
}
for(int i=0;i<3;i++){
if(i==0){
int nx=t.idx-1;
if(nx<=k&&s[nx]==0){
s[nx]=1;
q.push({nx,t.cnt+1});
}
}
else if(i==1){
int nx=t.idx+1;
if(nx<=k&&s[nx]==0){
s[nx]=1;
q.push({nx,t.cnt+1});
}
}
else{
int nx=t.idx*2;
if(nx<=k&&s[nx]==0){
s[nx]=1;
q.push({nx,t.cnt+1});
}
}
}
}
}
int main(){
cin>>n>>k;
bfs(n);
return 0;
}
4 comments
-
C24liukaiwen LV 7 @ 2025-3-3 13:52:02Edited
空想太全责
右边界可以超过k但不能超过100000
-
2025-3-3 13:43:44@
已看搜
-
2025-2-27 13:24:24@
注意左右边界,农夫起始位于点N(0≤N≤100000),牛位于点K(0≤K≤100000)。不要浪费时间打低质量的表
-
2025-2-26 21:00:50@
打如表
- 1
Information
- ID
- 738
- Time
- 1000ms
- Memory
- 256MiB
- Difficulty
- 7
- Tags
- # Submissions
- 144
- Accepted
- 33
- Uploaded By