设为首页 加入收藏

TOP

Openjudge 2971:抓住那头牛&&P1588 丢失的牛(二)
2019-08-23 00:33:16 】 浏览:41
Tags:Openjudge 2971: 抓住 头牛 &&P1588 丢失
00005
],dep[100005],head,tail; bool a[100005]; int d[10]; bool check(int x) { if(x>100000 || x<0) return false; if(a[x]) return false; return true; } int main() { cin>>n>>k; if(n>=k) { cout<<n-k; return 0; } head=1,tail=1; a[n]=true;dep[1]=0;que[1]=n; while(head<=tail) { if(que[head]==k) { cout<<dep[head]; break; } int t=que[head]; d[1]=t+1;d[2]=t-1;d[3]=t*2; for(int i=1;i<=3;i++) if(check(d[i])) { que[++tail]=d[i]; dep[tail]=dep[head]+1; a[d[i]]=true; } head++; } return 0; }

 

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇PHP学习课程和培训方向学习路线分.. 下一篇php三种无限分类

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目