Triangle

Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 127    Accepted Submission(s): 89

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
 
 
题意:给出 1 - n 根木棍,问最少去掉多少根使其余的不能组成三角形..
强行 DFS...后面看别人说的只要剩下的全部是斐波拉契数列的项就可以了..
#include <bits/stdc++.h>
using namespace std;
map<int ,int> value;
int ans[] = {,,,,,,,,,,,,,,,,,,,};
int main()
{
int tcase,t=;
scanf("%d",&tcase);
while(tcase--){
int n;
scanf("%d",&n);
printf("Case #%d: %d\n",t++,ans[n-]);
}
return ;
}
 
 

hdu 5914(斐波拉契数列)的更多相关文章

  1. 斐波拉契数列加强版——时间复杂度O(1),空间复杂度O(1)

    对于斐波拉契经典问题,我们都非常熟悉,通过递推公式F(n) = F(n - ) + F(n - ),我们可以在线性时间内求出第n项F(n),现在考虑斐波拉契的加强版,我们要求的项数n的范围为int范围 ...

  2. 剑指offer三: 斐波拉契数列

    斐波拉契数列是指这样一个数列: F(1)=1; F(2)=1; F(n)=F(n-1)+F(n); public class Solution { public int Fibonacci(int n ...

  3. 关于斐波拉契数列(Fibonacci)

    斐波那契数列指的是这样一个数列 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233,377,610,987,1597,2584,4181,6765,10 ...

  4. 剑指offer-第二章算法之斐波拉契数列(青蛙跳台阶)

    递归与循环 递归:在一个函数的内部调用这个函数. 本质:把一个问题分解为两个,或者多个小问题(多个小问题相互重叠的部分,会存在重复的计算) 优点:简洁,易于实现. 缺点:时间和空间消耗严重,如果递归调 ...

  5. 剑指offer-面试题9.斐波拉契数列

    题目一:写一个函数,输入n,求斐波拉契数列的第n项. 斐波拉契数列的定义如下: { n=; f(n)={ n=; { f(n-)+f(n-) n>; 斐波拉契问题很明显我们会想到用递归来解决: ...

  6. C语言数据结构----递归的应用(斐波拉契数列、汉诺塔、strlen的递归算法)

    本节主要说了递归的设计和算法实现,以及递归的基本例程斐波拉契数列.strlen的递归解法.汉诺塔和全排列递归算法. 一.递归的设计和实现 1.递归从实质上是一种数学的解决问题的思维,是一种分而治之的思 ...

  7. [NEUQ-OJ] 1012 SZ斐波拉契数列

    一道水题,让我看清基础我的基础是多么薄弱. 递归,数组清零,数组名/变量名重复层出不穷...路漫漫啊.......... http://ncc.neuq.edu.cn/oj/problem.php?i ...

  8. 浅谈C#中的斐波拉契数列

    突然对那些有趣的数学类知识感兴趣了,然后就简单研究了一下斐波拉契数列,看看它的有趣之处! 斐波拉契数列(Fibonacci Sequence),又称黄金分割数列,该数列由意大利的数学家列奥纳多·斐波那 ...

  9. Go斐波拉契数列(Fibonacci)(多种写法)

    1 前言 斐波拉契数列有递归写法和尾递归和迭代写法. 2 代码 //recursion func fib(n int) int{ if n < 2{ return n }else{ return ...

随机推荐

  1. 【Django实例】博客1

    (上一篇) 一.概述 Blog是一个博客应用. dbe工程的目录结构,参考<序言>的最后部分.blog应用位于/home/russellluo/Django/dbe/dbe/blog目录下 ...

  2. 【agc006C】Rabbit Exercise

    Portal --> agc006C Solution 啊感觉是好有意思的一道题qwq官方题解里面的说辞也是够皮的哈哈哈..(大概就是说如果你没有意识到那个trick的话这题这辈子都做不出来qw ...

  3. Codeforces Round #336 (Div. 2)B 暴力 C dp D 区间dp

    B. Hamming Distance Sum time limit per test 2 seconds memory limit per test 256 megabytes input stan ...

  4. 协程-遇到I/O自动切换

    参考博客:http://www.cnblogs.com/alex3714/articles/5248247.html 一.前言 Gevent 是一个第三方库,可以轻松通过gevent实现并发同步或异步 ...

  5. 「Django」rest_framework学习系列-视图

    方式一 1.settings设置 INSTALLED_APPS = [ ... 'rest_framework', ] 2.views设置 from rest_framework.response i ...

  6. Patch multi versions of windows via Power shell

    Patch multi versions of windows via Power shell $version = Get-WmiObject -Class Win32_OperatingSyste ...

  7. centos 7 pdo

    在windows本机上测试好的Thinkphp5代码部署到centos7阿里云主机上面就提示class pdo not found,网上搜索了一大堆终于解决了.不过隔了这么几个小时详细的步骤就有些忘记 ...

  8. [LeetCode] 28. Implement strStr() ☆

    Implement strStr(). Returns the index of the first occurrence of needle in haystack, or -1 if needle ...

  9. UVA 1647 Computer Transformation

    https://vjudge.net/problem/UVA-1647 题意: 开始有一个1,接下来每一步1变成01,0变成10 问n不之后00的个数 打表找规律 第3步之后: 如果第i步之后有x个字 ...

  10. linux中操作数据库的使用命令记录

    1,mysql 查看数据库表编码格式: show create table widget; 修改数据库表编码格式: alter table widget default character set u ...