[001] leap_stage
[Description] There is a number in each stages that indicates the most stages you can leap up. Now, giving an array which represents one kind of stair, please return if you can leap to the last stage, true if ok and vice versa.
e.g. stair[] = {4,3,1,0,2,1,0} return true;
stair[] = {2,1,0,4,3,1,0} return false;
[Thought] think about: what condition it would be true and false in current stair[0]? how to recursively call itself?
[Implementation] C code:
#include<stdio.h> int leapStage(int stair[], int size)
{
int i;
// if current stage number is zero, false, of course!
if(stair[] == )
{
return ;
}
// if current stage number indicate that we can jump over last stage, true.
else if(stair[] >= size-)
{
return ;
}
// try each way while can't touch the last stages.
for(i = stair[]; i>; i--)
{
// if there is one way can do it, true.
if(leapStage(stair+i, size-i))
{
return ;
}
}
// after try all the way, can't get it.
return ;
} int main()
{
int i;
int stair[]={,,,,,,};
int size=sizeof(stair)/sizeof(stair[]);
for(i=; i<size; i++)
{
printf("%d, ",stair[i]);
}
if(leapStage(stair,size))
{
printf(" is true!\n");
}
else
{
printf(" is false!\n");
}
}
[001] leap_stage的更多相关文章
- swift 001
swift 001 = 赋值是没有返回值的 所以 int a=10; int b=20; if(a=b){ printf("这个是错误的"); } swift 中的模运算 是支 ...
- [SDK2.2]Windows Azure Virtual Network (4) 创建Web Server 001并添加至Virtual Network
<Windows Azure Platform 系列文章目录> 在上一章内容中,笔者已经介绍了以下两个内容: 1.创建Virtual Network,并且设置了IP range 2.创建A ...
- 《zw版·Halcon-delphi系列原创教程》 Halcon分类函数001·3D函数
<zw版·Halcon-delphi系列原创教程> Halcon分类函数001·3D函数 为方便阅读,在不影响说明的前提下,笔者对函数进行了简化: :: 用符号“**”,替换:“proce ...
- Android 开发错误信息001
Error:Execution failed for task ':app:dexDebug'. > com.android.ide.common.process.ProcessExceptio ...
- python解无忧公主的数学时间编程题001.py
python解无忧公主的数学时间编程题001.py """ python解无忧公主的数学时间编程题001.py http://mp.weixin.qq.com/s?__b ...
- php大力力 [005节] php大力力简单计算器001
2015-08-22 php大力力005. php大力力简单计算器001: 上网看视频,看了半天,敲击代码,如下: <html> <head> <title>简单计 ...
- php大力力 [001节]2015-08-21.php在百度文库的几个基础教程新手上路日记 大力力php 大力同学 2015-08-21 15:28
php大力力 [001节]2015-08-21.php在百度文库的几个基础教程新手上路日记 大力力php 大力同学 2015-08-21 15:28 话说,嗯嗯,就是我自己说,做事认真要用表格,学习技 ...
- Web前端学习笔记(001)
....编号 ........类别 ............条目 ................明细....................时间 一.Web前端学习笔记 ...
- 001 The Hello World In Csharp
C#是面向对象编程语言,语法和JAVA非常相似.接下来让我们看一下C#的Hello world. //001.cs using System; public class Hello { public ...
随机推荐
- delphi完美经典--第十八章
第18章数据感知组件 一.TDBText组件 用来以只读.一次一条记录的方式,显示DataSet中的某一字段值.因同样继承自TCustomLabel,TDBText组件除了数据感知功能外,与标准组件T ...
- HDU4747——2013 ACM/ICPC Asia Regional Hangzhou Online
啦啦啦. 这是杭州网赛的一个题目,当时没做出来,当然这个想法确实比较难想到. 题目质量很高,这个题目也很特别,以前都没做过类似的题目.让我又一次体验了线段树的强大力量. 题目的意思是给你n个数a1-a ...
- 【bzoj3774】最优选择 网络流最小割
题目描述 小N手上有一个N*M的方格图,控制某一个点要付出Aij的代价,然后某个点如果被控制了,或者他周围的所有点(上下左右)都被控制了,那么他就算是被选择了的.一个点如果被选择了,那么可以得到Bij ...
- Codeforces 671C. Ultimate Weirdness of an Array(数论+线段树)
看见$a_i\leq 200000$和gcd,就大概知道是要枚举gcd也就是答案了... 因为答案是max,可以发现我们很容易算出<=i的答案,但是很难求出单个i的答案,所以我们可以运用差分的思 ...
- 【hdu6051】If the starlight never fade
Portal --> hdu6051 Solution 神仙题qwq好吧我个人感觉是神仙题 这题其实有一个比较野路子的做法..就是..打表观察..反正场上ckw大佬就是这样把这题A穿的 ...
- centos上部署nginx服务
Nginx ("engine x") 是一个高性能的HTTP和反向代理服务器,也是一个IMAP/POP3/SMTP服务器.Nginx是由Igor Sysoev为俄罗斯访问量第二的R ...
- Python3 字典 get() 方法
Python3 字典 描述 Python 字典 get() 函数返回指定键的值,如果值不在字典中返回默认值. 语法 get()方法语法: dict.get(key, default=None) 参数 ...
- vector 和数组 之间的转化
1.数组转vector float arrHeight[] = { 1.68,1.72,1.83,2.05,2.35,1.78,2.1,1.96 }; vector<float> vec ...
- Virtual Box虚拟机下CentOS网络设置
VirtualBox中有4中网络连接方式: a. NAT 网络地址转换模式(Network Address Translation)b. Bridge ...
- gdb常用命令小结
用了这么长时间gdb, 总结下常用用法: http://note.youdao.com/noteshare?id=4a2d1a34624f7197d8e2304c4beb4578