题目链接:

http://acm.hdu.edu.cn/showproblem.php?pid=5914

Problem Description
Mr. Frog has n sticks, whose lengths are 1,2, 3⋯n respectively. Wallice is a bad man, so he does not want Mr. Frog to form a triangle with three of the sticks here. He decides to steal some sticks! Output the minimal number of sticks he should steal so that Mr. Frog cannot form a triangle with
any three of the remaining sticks.
 
Input
The first line contains only one integer T (T≤20), which indicates the number of test cases.

For each test case, there is only one line describing the given integer n (1≤n≤20).

 
Output
For each test case, output one line “Case #x: y”, where x is the case number (starting from 1), y is the minimal number of sticks Wallice should steal.
 
Sample Input
3
4
5
6
 
Sample Output
Case #1: 1
Case #2: 1
Case #3: 2
 
Source
题意描述:
输入数字n(1≤n≤20),代表有n根长度为1,2,3...到n的木棒
计算并输出至少去掉几根木棒使得剩下的木棒不能构成任何一个三角形
解题思路:
先说结论:在保证不构成三角形的情况下,尽量取程度短的木棒。
因为在取舍时,较短木棒相比较长木棒更不容易构成三角形,但是选择短的时候不能和之前确定长度的木棒构成三角形。
那么取木棒时,首先1,2,3必取(既不构成三角形也最短),4不能取(与2,3构成三角形),5(取,相对比5长的木棒,5最不容易构成三角形,且与之前的木棒均构不成三角形),6(不取,与3和5构成三角形)...依次取得可知,n根木棒(从3根起),留下出的数构成斐波那契数1,2,3,5,8,13,14(很神奇有木有),那么只需要数一下,1到n有几个非斐波那契数即可。
故打表int map[21]={0,0,0,0,1,1,2,3,3,4,5,6,7,7,8,9,10,11,12,13,14};//首位存个0
AC代码:
 #include<stdio.h>
int main()
{
//注意首位多存一个0
int map[]={,,,,,,,,,,,,,,,,,,,,};
int n,t=,T;
scanf("%d",&T);
while(T--)
{
scanf("%d",&n);
printf("Case #%d: %d\n",t++,map[n]);
}
return ;
}
 
 
 
Recommend

HDU 5914 Triangle(打表——斐波那契数的应用)的更多相关文章

  1. HDU 1568 Fibonacci【求斐波那契数的前4位/递推式】

    Fibonacci Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Proble ...

  2. hdu 4983 线段树+斐波那契数

    http://acm.hdu.edu.cn/showproblem.php?pid=4893 三种操作: 1 k d, 修改k的为值增加d 2 l r, 查询l到r的区间和 3 l r, 从l到r区间 ...

  3. {HDU}{2516}{取石子游戏}{斐波那契博弈}

    题意:给定一堆石子,每个人最多取前一个人取石子数的2被,最少取一个,最后取石子的为赢家,求赢家. 思路:斐波那契博弈,这个题的证明过程太精彩了! 一个重要的定理:任何正整数都可以表示为若干个不连续的斐 ...

  4. HDU 1021(斐波那契数与因子3 **)

    题意是说在给定的一种满足每一项等于前两项之和的数列中,判断第 n 项的数字是否为 3 的倍数. 斐波那契数在到第四十多位的时候就会超出 int 存储范围,但是题目问的是是否为 3 的倍数,也就是模 3 ...

  5. hdu1568&&hdu3117 求斐波那契数前四位和后四位

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1568 题意:如标题所示,求斐波那契数前四位,不足四位直接输出答案 斐波那契数列通式: 当n<=2 ...

  6. C++求斐波那契数

    题目内容:斐波那契数定义为:f(0)=0,f(1)=1,f(n)=f(n-1)+f(n-2)(n>1且n为整数) 如果写出菲氏数列,则应该是: 0 1 1 2 3 5 8 13 21 34 …… ...

  7. POJ 3070(求斐波那契数 矩阵快速幂)

    题意就是求第 n 个斐波那契数. 由于时间和内存限制,显然不能直接暴力解或者打表,想到用矩阵快速幂的做法. 代码如下: #include <cstdio> using namespace ...

  8. 穷举法、for循环、函数、作用域、斐波那契数

    1.穷举法 枚举所有可能性,直到得到正确的答案或者尝试完所有值. 穷举法经常是解决问题的最实用的方法,它实现起来热别容易,并且易于理解. 2.for循环 for语句一般形式如下: for variab ...

  9. hdu1316(大数的斐波那契数)

    题目信息:求两个大数之间的斐波那契数的个数(C++/JAVA) pid=1316">http://acm.hdu.edu.cn/showproblem.php? pid=1316 这里 ...

随机推荐

  1. Thomas Hobbes: Leviathan

    Man is distinguished, not only by his reason, but by this singular passion from other animals, which ...

  2. Nodejs真.多线程处理

    前言 Threads à gogo 是nodejs 的原生模块,使用这个模块可以让nodejs 具备多线程处理功能 安装方法 npm install threads_a_gogo 下载测试源码 git ...

  3. C#用DataTable实现Group by数据统计

    http://www.cnblogs.com/sydeveloper/archive/2013/03/29/2988669.html 1.用两层循环计算,前提条件是数据已经按分组的列排好序的. Dat ...

  4. thinkinginjava学习笔记02_对象

    对象 1. 对象通过一个引用来操作,但是java中的对象是按值传递的,基本上可以在操作中认为对象本身,在内部结构中仍然要记得是对象实体的引用:如:String s = "abcd" ...

  5. 原生 js 实现点击按钮复制文本

    最近遇到一个需求,需要点击按钮,复制 <p> 标签中的文本到剪切板 之前做过复制输入框的内容,原以为差不多,结果发现根本行不通 尝试了各种办法,最后使了个障眼法,实现了下面的效果 一.原理 ...

  6. SQL SERVER 日期转换大全

    博客转自:http://blog.csdn.net/baiduandxunlei/article/details/9180075 CONVERT(data_type,expression[,style ...

  7. NFS : device is busy

    unmount [ options ] -f : Force unmount (in case of an unreachable NFS system). -l  : Lazy unmount. D ...

  8. ldap命令的使用

    转自:http://blog.chinaunix.net/uid-20690190-id-4085176.html 增:ldapadd 1)选项: -x   进行简单认证 -D   用来绑定服务器的D ...

  9. micropython TPYBoard v202 超声波测距

    实验目的 了解超声波模块的工作原理 学习使用超声波模块测量距离 实验器材 TPYBoard v202 1块 超声波模块(HC-SR04)1个 micro USB数据线 1条 杜邦线 若干 超声波模块的 ...

  10. MySQL中各种数据类型的长度及在开发中如何选择

    接触MySQL这个数据库大概快要两年了,不过由于没有特别深入系统的去学习,大多也是停留在一知半解的状态.今天在工作中刚好碰到了表设计的问题,顺便写篇博客,把MySQL中数据类型和字段类型选择这方面给弄 ...