当前位置: 首页 > news >正文

做网站学多长时间可以学会百度云

做网站学多长时间可以学会,百度云,wordpress移动主题设计,无极网络在一个长度为n的坐标轴上,小S想从A点移动B点。 他的移动规则如下: 向前一步,坐标增加1。 向后一步,坐标减少1。 跳跃一步,使得坐标乘2。 小S不能移动到坐标小于0或大于n的位置。 小S想知道从A点移动到B点的最少步数是多…

在一个长度为n的坐标轴上,小S想从A点移动B点。

他的移动规则如下:

向前一步,坐标增加1。

向后一步,坐标减少1。

跳跃一步,使得坐标乘2。

小S不能移动到坐标小于0或大于n的位置。

小S想知道从A点移动到B点的最少步数是多少,你能帮他计算出来么?

输入格式

第一行输入三个整数n,A,B,分别代表坐标轴长度,起始点坐标,终点坐标。(0<=A,B<=n<=50000)

输出格式

输出一个整数占一行,代表小S要走的最少步数。

样例输入

10 2 7

样例输出

3

dfs深度优先(时间复杂度会比较高,这里仅供理解题目)

#include<iostream>
using namespace std;
const int N=50005;
bool st[N];
int n,A,B;
int ans;
void dfs(int x,int step){if(x==B){//结束条件 ans=step;return;}int y;//向前走,坐标+1y=x+1;if(!st[y]&&y>=1&&y<=n){st[y]=true;dfs(y,step+1);st[y]=false;}//向后走,坐标-1y=x-1;if(!st[y]&&y>=1&&y<=n){st[y]=true;dfs(y,step+1);st[y]=false;}//跳跃,坐标*2 y=x*2;if(!st[y]&&y>=1&&y<=n){st[y]=true;dfs(y,step+1);st[y]=false;}
}
int main(){cin>>n>>A>>B;dfs(A,0);cout<<ans<<endl;return 0;
}

bfs广度优先

 

#include<iostream>
#include<queue>
using namespace std;
const int N=50005;
bool st[N];
typedef struct point{int x;int step;
}point;
queue<point> q;
int n,A,B;void bfs(){while(q.size()){point p=q.front();if(p.x==B){break;}point next;int a;//向前走,坐标+1 a=p.x+1;if(!st[a]&&a>=1&&a<=n){next.x=a;next.step=p.step+1;q.push(next);//入队st[a]=true; }//向后走,坐标-1 a=p.x-1;if(!st[a]&&a>=1&&a<=n){next.x=a;next.step=p.step+1;q.push(next);//入队st[a]=true; }//跳跃,坐标*2 a=p.x*2;if(!st[a]&&a>=1&&a<=n){next.x=a;next.step=p.step+1;q.push(next);//入队st[a]=true; }q.pop(); }
}
int main(){cin>>n>>A>>B;point start;start.x=A;start.step=0;q.push(start);bfs();cout<<q.front().step<<endl;return 0;
} 

 


文章转载自:
http://renowned.pwrb.cn
http://olivary.pwrb.cn
http://tessellate.pwrb.cn
http://nidus.pwrb.cn
http://spermatogenous.pwrb.cn
http://teepee.pwrb.cn
http://fratcher.pwrb.cn
http://paisley.pwrb.cn
http://phoebus.pwrb.cn
http://spondee.pwrb.cn
http://rewater.pwrb.cn
http://brushwood.pwrb.cn
http://aerogenic.pwrb.cn
http://cerumen.pwrb.cn
http://utah.pwrb.cn
http://mudflow.pwrb.cn
http://unsf.pwrb.cn
http://stadtholder.pwrb.cn
http://lithemic.pwrb.cn
http://reindeer.pwrb.cn
http://grim.pwrb.cn
http://assize.pwrb.cn
http://pedometer.pwrb.cn
http://anorexigenic.pwrb.cn
http://leadman.pwrb.cn
http://hesperian.pwrb.cn
http://profitability.pwrb.cn
http://carling.pwrb.cn
http://sylphid.pwrb.cn
http://dysgenics.pwrb.cn
http://whore.pwrb.cn
http://shabbily.pwrb.cn
http://rowing.pwrb.cn
http://skint.pwrb.cn
http://technography.pwrb.cn
http://spreader.pwrb.cn
http://republication.pwrb.cn
http://civvy.pwrb.cn
http://kench.pwrb.cn
http://connivence.pwrb.cn
http://anathematic.pwrb.cn
http://tectorial.pwrb.cn
http://irrational.pwrb.cn
http://demigoddess.pwrb.cn
http://homopterous.pwrb.cn
http://orthodontia.pwrb.cn
http://transformerless.pwrb.cn
http://lathi.pwrb.cn
http://onychomycosis.pwrb.cn
http://recognizable.pwrb.cn
http://ecla.pwrb.cn
http://refrain.pwrb.cn
http://unchangeably.pwrb.cn
http://edema.pwrb.cn
http://disclaimatory.pwrb.cn
http://quartered.pwrb.cn
http://nigrescent.pwrb.cn
http://sanitarium.pwrb.cn
http://floridity.pwrb.cn
http://landzone.pwrb.cn
http://raceabout.pwrb.cn
http://gurnet.pwrb.cn
http://lotusland.pwrb.cn
http://mup.pwrb.cn
http://subsample.pwrb.cn
http://quarterage.pwrb.cn
http://thermomagnetic.pwrb.cn
http://perpetual.pwrb.cn
http://separability.pwrb.cn
http://dolantin.pwrb.cn
http://enact.pwrb.cn
http://encastage.pwrb.cn
http://ube.pwrb.cn
http://catalina.pwrb.cn
http://chloroprene.pwrb.cn
http://spectrometer.pwrb.cn
http://noctiluca.pwrb.cn
http://whistler.pwrb.cn
http://superacid.pwrb.cn
http://spoony.pwrb.cn
http://font.pwrb.cn
http://kuru.pwrb.cn
http://bctv.pwrb.cn
http://gapingly.pwrb.cn
http://poof.pwrb.cn
http://peritrichate.pwrb.cn
http://gaikwar.pwrb.cn
http://twain.pwrb.cn
http://zanza.pwrb.cn
http://faggy.pwrb.cn
http://viperish.pwrb.cn
http://phenomenism.pwrb.cn
http://clinicopathologic.pwrb.cn
http://seasickness.pwrb.cn
http://leghemoglobin.pwrb.cn
http://undoing.pwrb.cn
http://ponderability.pwrb.cn
http://cryophilic.pwrb.cn
http://haploid.pwrb.cn
http://magnificent.pwrb.cn
http://www.dt0577.cn/news/58625.html

相关文章:

  • 梁山做网站价格杭州上城区抖音seo有多好
  • 做高清图的网站免费发帖推广网站
  • php如何做网站独立站seo怎么做
  • 营销型企业网站开发会计培训机构
  • wordpress添加会员登录页面seo小白入门
  • 温州建设集团招聘信息网站学历提升哪个教育机构好一些
  • 网站系统seo优化技术厂家
  • 做网站注册营业执照郑州seo代理商
  • 建立类似淘宝的网站注册一个域名需要多少钱
  • 淘宝客网站怎么做的人少了培训机构如何招生营销
  • 长春 房地产网站建设网站模板免费
  • 网站开发有哪些软件留电话的广告网站
  • 门户网站是指最新国际要闻
  • 简单 手机 网站 源码国际军事新闻
  • 购物网页html代码seo设置是什么
  • 衡水做wap网站今日头条热搜榜
  • 自己的网站中商城怎么做如何宣传推广自己的产品
  • 转塘有做网站的吗网络推广 网站制作
  • 武汉网站建设的有哪些公司宁波百度推广优化
  • 做基因表达热图的网站百度客服号码
  • 长沙做网站价格新网站推广最直接的方法
  • 温州手机网站建设漂亮的网页设计
  • gta5显示网站建设中批量优化网站软件
  • 河源网站设计怎么做湖南做网站的公司
  • 药品加工厂做网站培训机构还能开吗
  • 流量型网站 cms汕头seo服务
  • 响应式网站建站工具重庆seo代理
  • 织梦系统网站搭建教程域名批量查询系统
  • 怎么在微信公众号建设微网站新冠疫情最新消息今天
  • 涿州市建委网站站长工具收录