博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
hdu 5620 KK's Steel(推理)
阅读量:7029 次
发布时间:2019-06-28

本文共 1583 字,大约阅读时间需要 5 分钟。

 

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

 

Source
 

 

题意:
给你一个长度为N的钢管,问最多切成几个钢管,使得这些钢管不能围成三角形,并且不能有相同长度 !
思路:
要想使得钢管尽量多,那肯定从1开始吧,有了1,且不能重复,那肯定找2吧,而且三个钢管不能围成,三角形,那直接找a1 + a2 = a3的情况不就恰好不能围成三角形吗。所以很明显,这是一个a1 = 1,a2 = 2的斐波那契数列,找到第一个i  是的前i项和大于N,即可!特殊判断N = 1,N=2即可!他们都是1!
 
1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include
3 #include
4 #include
5 #include
6 #include
7 #include
8 #include
9 #include
10 #include
11 #include
12 #include
13 #include
14 using namespace std;15 #define ll long long16 #define eps 1e-1017 #define MOD 100000000718 #define N 100000019 #define inf 1e1220 ll n;21 ll f[N];22 void init(){23 f[1]=1;24 f[2]=2;25 for(ll i=3;i
n){41 break;42 }43 }44 if(n==1 || n==2){45 printf("1\n");46 continue;47 }48 printf("%I64d\n",i-1);49 }50 return 0;51 }
View Code

 

 
 
 
 
 
 
 
 
 
 
 
 

转载地址:http://psrxl.baihongyu.com/

你可能感兴趣的文章
web 缓存
查看>>
【cocos2d-x 手游研发----怪物智能AI】
查看>>
miniupnpc
查看>>
Linux 引导过程内幕
查看>>
无法打开登录所请求的数据库 "ASPState"。登录失败。 用户 'NT AUTHORITY/SYSTEM' 登录失败。...
查看>>
Windows Phone开发(47):轻松调用Web Service
查看>>
ExecuteScalar的学习日志
查看>>
解决 dotNetZip 解压乱码的问题,支持ZIP分卷解压缩
查看>>
每日英语:Who Needs to Know How to Code
查看>>
oracle11g重新安装oem
查看>>
initrd映像文档的作用和制作
查看>>
Windows Phone-框架结构和启动过程
查看>>
PHP抓取网络数据的6种常见方法
查看>>
android之RatingBar控件用法
查看>>
SkipFish
查看>>
polarssl rsa & aes 加密与解密
查看>>
水晶报表在vs2010 WPF环境下的尝试
查看>>
jquery.min.map 404 (Not Found)出错的原因及解决办法
查看>>
CSS3 滤镜
查看>>
FZU 2082 过路费(树链剖分)
查看>>