悉心指点下写出的 加1乘2平方 虽然估计没多少人会看
2017-11-07 10:18
225 查看
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<queue>
using namespace std;
int used[10001];
int step[10001];
int m,n;
queue<int> d;
int search();
int mov(int x,int y);
int main()
{
scanf("%d %d",&m,&n);
used[m]=1;
step[m]=0;
d.push(m);
search();
printf("%d\n",step
);
return 0;
}
int search()
{
int o,p,i;
while(!d.empty())
{
o=d.front();
d.pop();
for(i=0;i<3;i++)
{
p=mov(o,i);
if(p==n)
{
step[p]=step[o]+1;
return 0;
}
if(p<n&&used[p]==0)
{
step[p]=step[o]+1;
used[p]=1;
d.push(p);
}
}
}
}
int mov(int x,int y)
{
if(y==0)
{
return (x+1);
}
if(y==1)
{
return (x+x);
}
else
{
return (x*x);
}
}
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
#include<string.h>
#include<queue>
using namespace std;
int used[10001];
int step[10001];
int m,n;
queue<int> d;
int search();
int mov(int x,int y);
int main()
{
scanf("%d %d",&m,&n);
used[m]=1;
step[m]=0;
d.push(m);
search();
printf("%d\n",step
);
return 0;
}
int search()
{
int o,p,i;
while(!d.empty())
{
o=d.front();
d.pop();
for(i=0;i<3;i++)
{
p=mov(o,i);
if(p==n)
{
step[p]=step[o]+1;
return 0;
}
if(p<n&&used[p]==0)
{
step[p]=step[o]+1;
used[p]=1;
d.push(p);
}
}
}
}
int mov(int x,int y)
{
if(y==0)
{
return (x+1);
}
if(y==1)
{
return (x+x);
}
else
{
return (x*x);
}
}
相关文章推荐
- 欧拉工程第17题 用英文写出1到1000的所有数字需要多少个字母
- 关注C++细节——你能直接写出多少个C++关键字?
- 参加了华为奖学金答辩,哎。。。太紧张了,估计没多少希望了
- 小明很喜欢数学,有一天他在做数学作业时,要求计算出9~16的和,他马上就写出了正确答案是100。但是他并不满足于此,他在想究竟有多少种连续的正数序列的和为100(至少包括两个数)。没多久,他就得到另一组连续正数和为100的序列:18,19,20,21,22。现在把问题交给你,你能不能也很快的找出所有和为S的连续正数序列? Good Luck!
- 通过观测到的公交车线路估计城市共有多少路公交车
- 一只青蛙从第一级台阶跳到第n级,每次可以跳任意级,共有多少种跳法,并写出递推式
- 榨干委托那些知识点,能写出多少种委托(Action Func委托+异步委托)
- 从1数到n,1出现多少次,有多少个1的问题,想了好长时间,才写出这个。算的速度还是可以的
- 一个牧场目前一共有20头刚出生的羊,母羊、公羊各一半。假如母羊5岁时后每年生一胎(母羊,公羊各一半)。羊活到10岁后死亡。请问20年后这个牧场有多少只羊? 请用C#写出算法。
- 你能直接写出多少个C++关键字?
- Java进阶之欧拉工程 第十七篇【用英文写出1到1000的所有数字需要多少个字母?】
- 小娴的男友小旭不幸患了一种怪病,这种怪病吞噬了他的大部分记忆,同时让他突然间不会书写符合正确语序的英文。神奇的是,虽然他写出的句子看上去杂乱无章,不过经过仔细分析可以发现,如果把单词的顺序倒过来,语法
- 用英文写出1到1000的所有数字需要多少个字母?
- 如果不用jQuery,Ajax你还能写出多少?
- ZOJ 2022题解,起初此题纠结了很久。方法没有用对,后经大牛指点恍然大悟,原来就是求1到N有多少是5的倍数,再求25的倍数,125的倍数如此循环。
- 小明很喜欢数学,有一天他在做数学作业时,要求计算出9~16的和,他马上就写出了正确答案是100。但是他并不满足于此,他在想究竟有多少种连续的正数序列的和为100(至少包括两个数)。没多久,他就得到另一
- 手机归属地查询----自学了这么久总算可以不copy他人代码写出一款APP了 虽然有点丑
- 写出宏定义 输出一年有多少秒
- 黑马程序员—估计除了我,四期的没多少人会上来了
- 第六题:航天飞行器是一项复杂而又精密的仪器,飞行器的损耗主要集中在发射和降落的过程,科学家根据实验数据估计,如果在发射过程中,产生了 x 程度的损耗,那么在降落的过程中就会产生 x2 程度的损耗,如果飞船的总损耗超过了它的耐久度,飞行器就会爆炸坠毁。问一艘耐久度为 h 的飞行器,假设在飞行过程中不产生损耗,那么为了保证其可以安全的到达目的地,只考虑整数解,至多发射过程中可以承受多少程度的损耗?