Luogu 1588(dfs)(false)
来源:互联网 发布:淘宝木子禅佛珠怎么样 编辑:程序博客网 时间:2024/04/28 23:47
#include<stdio.h>
#include<stdlib.h>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
int minn=99999;
int cnt,x,y,t;
void search(int x,int y,int step)
{
if(x==y)
{
minn=min(minn,step);
return;
}
else if(x<y)
{
search(x+1,y,step+1);
search(x-1,y,step+1);
search(2*x,y,step+1);
}
else if(x>y)
{
search(x-1,y,step+1);
}
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&x,&y);
search(x,y,0);
printf("%d\n",minn);
}
return 0;
}
#include<stdlib.h>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
int minn=99999;
int cnt,x,y,t;
void search(int x,int y,int step)
{
if(x==y)
{
minn=min(minn,step);
return;
}
else if(x<y)
{
search(x+1,y,step+1);
search(x-1,y,step+1);
search(2*x,y,step+1);
}
else if(x>y)
{
search(x-1,y,step+1);
}
}
int main()
{
scanf("%d",&t);
while(t--)
{
scanf("%d%d",&x,&y);
search(x,y,0);
printf("%d\n",minn);
}
return 0;
}
阅读全文
0 0
- Luogu 1588(dfs)(false)
- luogu P1019 单词接龙 【dfs】
- luogu P1101 单词方阵【dfs】
- Luogu 1074(DFS)(NOIP 2009)
- luogu P1141 01迷宫【dfs记忆化】
- luogu P1443 马的遍历 【队列 dfs】
- HDU 1152. False Mirrors(DFS)
- URAL 1152 False Mirrors (DFS枚举)
- 【luogu】【DFS+神剪枝】小木棍(数据加强)
- Luogu-p1164小A点菜(dp dfs)
- FALSE
- Luogu 1197
- 【Luogu】 食物链
- lUOGU P1540
- luogu 1313
- luogu 1082
- luogu 1024
- luogu 1044
- API学习java.lang.Object.equals
- 百练1481:Maximum sum
- web.xml中servlet ,filter ,listener ,interceptor的作用与区别
- mysql多表操作2 多表查询
- [笔记]随手写写画画(1)
- Luogu 1588(dfs)(false)
- get请求后台获取时乱码解决方法
- 对jdk和jre的理解
- YOLO选择出只有某一类的检测框并将框保存在txt中
- opencv CvMat数组调用函数后计算值出错可能的问题
- API学习java.lang.Object.hashCode
- Springboot-async
- java nio
- zepto源码之fx_methods.js