首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >专栏 >【杭电oj】5620 - KK's Steel(递推)

【杭电oj】5620 - KK's Steel(递推)

作者头像
FishWang
发布2025-08-26 17:54:02
发布2025-08-26 17:54:02
9800
代码可运行
举报
运行总次数:0
代码可运行

KK's Steel

Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submission(s): 650 Accepted Submission(s): 301 Problem Description

Our lovely KK has a difficult mathematical problem:he has a 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 , which indicates the number of test cases. Each test case contains one line including a integer ,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

代码语言:javascript
代码运行次数:0
运行
复制
   1
6

Sample Output

代码语言:javascript
代码运行次数:0
运行
复制
   3


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

Source

BestCoder Round #71 (div.2)

类似斐波那契数列,递推过去就行了,时间上足够,注意数据类型就行了。

代码如下:

代码语言:javascript
代码运行次数:0
运行
复制
#include <cstdio>
#include <algorithm>
using namespace std;
long long f[1000000];
int main()
{
	f[1] = 1;
	f[2] = 2;
	for (int i = 3 ; i <= 1000 ; i++)
		f[i] = f[i-1] + f[i-2];
	int u;
	long long n;
	long long sum;
	scanf ("%d",&u);
	while (u--)
	{
		scanf ("%lld",&n);
		sum = 0;
		for (int i = 1 ;; i++)
		{
			sum += f[i];
			if (sum == n)
			{
				printf ("%d\n",i);
				break;
			}
			else if (sum > n)
			{
				printf ("%d\n",--i);
				break;
			}
		}
	}
	return 0;
}
本文参与 腾讯云自媒体同步曝光计划,分享自作者个人站点/博客。
原始发表:2016-03-22,如有侵权请联系 cloudcommunity@tencent.com 删除

本文分享自 作者个人站点/博客 前往查看

如有侵权,请联系 cloudcommunity@tencent.com 删除。

本文参与 腾讯云自媒体同步曝光计划  ,欢迎热爱写作的你一起参与!

评论
登录后参与评论
0 条评论
热度
最新
推荐阅读
目录
  • KK's Steel
领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档