[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 ...
随机推荐
- ZooKeeper系列文章
ZooKeeper FAQ ZooKeeper客户端事件串行化处理 ZooKeeper分布式锁避免羊群效应(Herd Effect) ZooKeeper管理员指南——部署与管理ZooKeeper Zo ...
- bzoj1853-大包子的幸运数字
题意 称只含有 6 和 8 的数字为幸运数字.称幸运数字的倍数为类幸运数字.求 \([l,r]\) 中有多少个类幸运数字.\(1\le l,r\le 10^{10}\) . 分析 幸运数字最多有 \( ...
- Python基础数据类型题
Python基础数据类型 题考试时间:三个小时 满分100分(80分以上包含80分及格)1,简述变量命名规范(3分) 1.必须是字母,数字,下划线的任意组合. 2.不能是数字开头 3.不能是pytho ...
- 【JavaScript】JAVA-js中比较日期大小
业务场景:js中根据yyyy-MM-dd格式的日期进行比较来动态显示相关图标的出现与否 var DS173305 = { DS173305Grid: null, initDataGrid: funct ...
- 深入理解JVM一性能监控工具
一.前言 工欲善其事必先利其器,性能优化和故障排查在我们大都数人眼里是件比较棘手的事情,一是需要具备一定的原理知识作为基础,二是需要掌握排查问题和解决问题的流程.方法.本文就将介绍利用性能监控工具,帮 ...
- C++11线程使用总结
std::thread 在 <thread> 头文件中声明,因此使用 std::thread 需包含 <thread> 头文件. <thread> 头文件摘要 &l ...
- Static全局变量(函数)与普通的全局变量(函数)的区别
转自:http://www.cnblogs.com/zjvskn/p/5548879.html Static全局变量与普通的全局变量有什么区别? 答: 全局变量(外部变量)的说明之前再冠以static ...
- 洛谷 P3157 [CQOI2011]动态逆序对 解题报告
P3157 [CQOI2011]动态逆序对 题目描述 对于序列\(A\),它的逆序对数定义为满足\(i<j\),且\(A_i>A_j\)的数对\((i,j)\)的个数.给\(1\)到\(n ...
- OpenCV中响应鼠标消息 (转)
#include <cv.h> #include <highgui.h> #include <stdio.h> #pragma comment(lib," ...
- 洛谷P1991 无线通讯网
P1991 无线通讯网 170通过 539提交 题目提供者洛谷OnlineJudge 标签图论 难度普及+/提高 提交该题 讨论 题解 记录 最新讨论 怎么又炸了 为啥一直40!求解! UKE:inv ...