KK's Steel

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

Problem Description
Our lovely KK has a difficult mathematical problem:he has a N(1≤N≤1018) meters steel,he will cut it into steels as many as possible,and he doesn't want any two of them be the same length or any three of them can form a triangle.
 
Input
The first line of the input file contains an integer T(1≤T≤10), which indicates the number of test cases.

Each test case contains one line including a integer N(1≤N≤1018),indicating the length of the steel.

 
Output
For each test case, output one line, an integer represent the maxiumum number of steels he can cut it into.
 
Sample Input
1
6
 
Sample Output
3

Hint

1+2+3=6 but 1+2=3 They are all different and cannot make a triangle.

 
要求:给一个长整形数n让你把n分成若干份,1、任意两份长度不能相等 2、任意三分不能组成三角形
 
分析:因为斐波那契数列中的数满足此要求,所以从这个方面入手,只要分成的数满足a+b<=c即可,所以我们在数列1  2  3  5  8  13  21 ......的数中选取,如果前i项的和等于n输出i如果前i项的和大于n输出i-1
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#define MAX 100100
#define INF 0x3f3f3f
#define LL long long
using namespace std;
LL fb[10010];
LL f[1001];
void biao()
{
LL i,j;
fb[1]=1;
fb[2]=2;
for(i=3;i<120;i++)
fb[i]=fb[i-1]+fb[i-2];
f[1]=fb[1];
for(i=2;i<120;i++)
f[i]=f[i-1]+fb[i];
}
int main()
{
int t,i,j;
LL n;
biao();
scanf("%d",&t);
while(t--)
{
scanf("%lld",&n);
for(i=1;i<120;i++)
{
if(n==f[i])
{
printf("%d\n",i);
break;
}
if(n<f[i])
{
printf("%d\n",i-1);
break;
}
}
}
return 0;
}

  

最新文章

  1. [原创]jquery+css3打造一款ajax分页插件
  2. 关于利用bat文件调用exe批量处理文件下的文件的问题
  3. Repeater嵌套Repeater并取得嵌套Repeater里面的控件
  4. android学习笔记九——RatingBar
  5. apache重写字段详细说明
  6. iOS开发几年了,你清楚OC中的这些东西么1
  7. TransactionScope的正确用法(转自:http://blog.csdn.net/greystar/article/details/1359960)
  8. django 启动和请求
  9. Java路径问题最终解决方案—可定位所有资源的相对路径寻址
  10. Android中的对话框AlertDialog使用技巧合集-转载
  11. 《JAVA语言程序设计》上课笔记
  12. 第一章 开发简单Java应用程序
  13. 百度地图JSSDK使用小实例
  14. 6E - 寒冰王座
  15. windows 公司内部搭建禅道(项目管控)
  16. 补充 3:Golang 一些特性
  17. PHP提取链接批量下载
  18. 网易AI工程师面试常见知识
  19. MyEclipse 2014优化设置(禁用myeclipse updating indexes)
  20. API(选项/数据 选项/dom)

热门文章

  1. oracle 11g SQL Developer instead of isqlplus
  2. CY7C68013A的一点总结
  3. EASYUI+MVC4通用权限管理平台
  4. HTML空格符号 &amp;nbsp / &amp;ensp / &amp;emsp
  5. Android listView如何判断数据多屏显示 (2012-03-06 09:47:04)
  6. 完整cocos2d-x编译Andriod应用过程
  7. 【C#学习笔记】List容器使用
  8. 在Windows下编译ffmpeg完全手册
  9. 【DFS+记忆搜索】NYOJ-10-Skiing
  10. 【转】VI/VIM常用命令