Triangle

题目连接:

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

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

Hint

题意

你有1-n的n条边,让你拿走尽量少的边,使得剩下的边,任意取三个都不能组成三角形。

题解:

最后剩下的边是Fib数列就可以了,这样就保证了任意三个都不能组成三角形。

证明也很简单。

代码

#include<bits/stdc++.h>
using namespace std;
const int maxn = 25;
int dp[maxn];
int main()
{
dp[1]=1,dp[2]=1,dp[3]=1,dp[5]=1,dp[8]=1,dp[13]=1,dp[21]=1;
for(int i=1;i<=20;i++)
dp[i]+=dp[i-1];
for(int i=1;i<=20;i++)
dp[i]=i-dp[i];
int t;
scanf("%d",&t);
for(int cas=1;cas<=t;cas++){
int x;scanf("%d",&x);
printf("Case #%d: %d\n",cas,dp[x]);
}
}

HDU 5914 Triangle 数学找规律的更多相关文章

  1. # E. Mahmoud and Ehab and the xor-MST dp/数学+找规律+xor

    E. Mahmoud and Ehab and the xor-MST dp/数学/找规律 题意 给出一个完全图的阶数n(1e18),点由0---n-1编号,边的权则为编号间的异或,问最小生成树是多少 ...

  2. HDU 4861 Couple doubi(找规律|费马定理)

    Couple doubi Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & %I64u Submit ...

  3. hdu 2604 Queuing dp找规律 然后矩阵快速幂。坑!!

    http://acm.hdu.edu.cn/showproblem.php?pid=2604 这题居然O(9 * L)的dp过不了,TLE,  更重要的是找出规律后,O(n)递推也过不了,TLE,一定 ...

  4. hdu 3951 - Coin Game(找规律)

    这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就 ...

  5. HDU 5703 Desert (找规律)

    题意:一杯水有n的容量,问有多少种方法可以喝完. 析:找规律,找出前几个就发现规律了,就是2的多少次幂. 代码如下: #include <cstdio> #include <stri ...

  6. hdu 4952 Number Transformation (找规律)

    题目链接 题意:给你个x,k次操作,对于第i次操作是:要找个nx,使得nx是>=x的最小值,且能整除i,求k次操作后的数 分析: 经过打表找规律,会发现最后的x/i,这个倍数会趋于一个固定的值, ...

  7. hdu 5241 Friends(找规律?)

    Friends Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 262144/262144 K (Java/Others)Total S ...

  8. HDU 4279 Number(找规律)

    Number Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  9. Harmonic Number (II) 数学找规律

    I was trying to solve problem '1234 - Harmonic Number', I wrote the following code long long H( int  ...

随机推荐

  1. WebService 基本操作

    1.新建asp.net web 应用程序 2.添加web 服务webservice.asmx public string HelloWorld(int a) { if (a==1) { return ...

  2. VO,DO,DTO,PO,POJO,EJB

    PO:persistent Object,持久化对象,和数据库一一对应. VO:view Object,视图对象,用于展示,把某个页面或者组件的数据封装起来. DO:Domain Object,领域对 ...

  3. Jplayer歌词同步显示插件

    http://blog.csdn.net/wk313753744/article/details/38758317 1.该插件是一个jquery的编写的跟jplayer实现歌词同步的插件,最终效果如图 ...

  4. 修改默认MYSQL数据库data存放位置

    随着业务量的增长,mysql默认安装所在分区大小出现瓶颈,通常需要将datadir换到较大的分区 示例原目录:/usr/local/mysql/data/示例新目录:/data/mysqldata/ ...

  5. 『TCP/IP详解——卷一:协议』读书笔记——06

    2013-08-20 14:41:01 2.8 最大传输单元MTU MTU,最大传输单元:以太网和802.3对数据帧的长度都有一个限制,其最大值分别是1500和1492字节.这个不同网络对应的传输上限 ...

  6. jsf2.0 tomcat 修改页面后无法立马看到页面修改效果

    转载于  http://stackoverflow.com/questions/12203657/jsf2-myfaces-xhtml-modifications-do-not-affect-unti ...

  7. python学习笔记:Day01

    一.python 简介 1.  python是Guido van Rossum在1989年圣诞节期间,为了打发无聊的假期而编写的一个编程语言   2.  pyhton主要应用于数据分析.组件集成.网络 ...

  8. PhoneJS - HTML5 JavaScript 移动开发框架

    大伙儿都知道有很多基于HTML5的移动应用框架.下一代开发工具将帮助开发者远离那些难学和让人费劲的原生SDK语言,如Objective-C,Java等.大家都知道,HTML5代表着交叉平台如移动应用程 ...

  9. javascript中的call()和apply()方法的使用

    1.方法定义 call方法: 语法:call([thisObj[,arg1[, arg2[,   [,.argN]]]]]) 定义:调用一个对象的一个方法,以另一个对象替换当前对象. 说明: call ...

  10. 辐射4 中文武器命名方法, 不用winhex, 直接游戏内操作

    参考资料:https://www.reddit.com/r/fo4/comments/3t354b/tip_you_can_add_text_formatting_italic_underline/h ...