HDU 5914 Triangle 数学找规律
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 数学找规律的更多相关文章
- # E. Mahmoud and Ehab and the xor-MST dp/数学+找规律+xor
E. Mahmoud and Ehab and the xor-MST dp/数学/找规律 题意 给出一个完全图的阶数n(1e18),点由0---n-1编号,边的权则为编号间的异或,问最小生成树是多少 ...
- HDU 4861 Couple doubi(找规律|费马定理)
Couple doubi Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u Submit ...
- hdu 2604 Queuing dp找规律 然后矩阵快速幂。坑!!
http://acm.hdu.edu.cn/showproblem.php?pid=2604 这题居然O(9 * L)的dp过不了,TLE, 更重要的是找出规律后,O(n)递推也过不了,TLE,一定 ...
- hdu 3951 - Coin Game(找规律)
这道题是有规律的博弈题目,,, 所以我们只需要找出规律来就ok了 牛人用sg函数暴力找规律,菜鸟手工模拟以求规律...[牢骚] if(m>=2) { if(n<=m) {first第一口就 ...
- HDU 5703 Desert (找规律)
题意:一杯水有n的容量,问有多少种方法可以喝完. 析:找规律,找出前几个就发现规律了,就是2的多少次幂. 代码如下: #include <cstdio> #include <stri ...
- hdu 4952 Number Transformation (找规律)
题目链接 题意:给你个x,k次操作,对于第i次操作是:要找个nx,使得nx是>=x的最小值,且能整除i,求k次操作后的数 分析: 经过打表找规律,会发现最后的x/i,这个倍数会趋于一个固定的值, ...
- hdu 5241 Friends(找规律?)
Friends Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 262144/262144 K (Java/Others)Total S ...
- HDU 4279 Number(找规律)
Number Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
- Harmonic Number (II) 数学找规律
I was trying to solve problem '1234 - Harmonic Number', I wrote the following code long long H( int ...
随机推荐
- json+servlet+ajax
json-lib-2.3-jdk15.jar commons-beanutils-1.7.0.jar commons-httpclient-3.1.jar commons-lang-2.3.jar c ...
- Ubuntu下修改hosts文件
Ubuntu系统的Hosts只需修改/etc/hosts文件,修改完之后要重启网络.具体过程如下:1.修改hostssudo gedit /etc/hosts2.添加解析记录( . )或者从githu ...
- 给AOP的after函数使用原函数局部变量
引:AOP为Aspect Oriented Programming的缩写,意为:面向切面编程,通过预编译方式和运行期动态代理实现程序功能的统一维护的一种技术. 这里我们可以理解为在执行某函数时,要先执 ...
- First Blog, “Hello, world!”
As every single book says as a tradition, "Hello, world!" An explanation about the name – ...
- WPF 虚拟键盘
之前做了一款WPF虚拟键盘,调用Win32的API,可以模拟键盘事件. 现将代码分享如下: 按键布局如下: <Button Name="> <StackPanel Orie ...
- (原创)即使最可怕的自然力量,也不失美丽——火山喷发(摄影,欣赏)
文中图片摘自腾讯文化:www.cal.qq.com 1.Abstract 最可怕的力量也潜含着最美丽的风景奇观,虽然不能亲眼目睹,但透过大师的视角,一样也能体会到自然力量撼动的美丽. 2.Co ...
- 数据库知识整理<四>
使用DML语句更改数据: 所谓DML语句是指数据库操作语句,其中包括的是对数据库数据的修改.删除.插入. 4.1添加新数据: 插入单行的记录:基本的SQL语句为-insert into <表明& ...
- wordnet的一些入门性介绍
关于wordnet的介绍很多,中英文都有,我这里主要是参考了别人的.自己组织了一下. 1.简介 1.1关于词典 Wordnet是一个由普林斯顿大学认识科学实验室在心理学教授乔治·A·米勒的指导下建立和 ...
- 打包解决方案后,安装时提示只能在IIS5.1以上运行解决方法
环境:vs2010 sp1,mvc4,WIN10 生成安装项目后进行安装提示: 此安装程序需要Internet Information Server 5.1或更高版本和Windows XP和更高的安装 ...
- 在项目中引用GreenDroid库
1.下载GreenDroid库 首先,我们得从Git上下载这个库,我用的是git for windows下载的.先下载,安装.安装完后,打开git for windows ,直接将浏览器中GreenD ...