HDU 5620 KK's Steel <贪心思维>
2016-07-24 16:17
344 查看
KK's Steel
Submit Status
Description
Our lovely KK has a difficult mathematical problem:he has a N\left( 1\leq N\leq {10}^{18}\right) 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\left( 1\leq T\leq 10\right),
which indicates the number of test cases.
Each test case contains one line including a integer N\left( 1\leq N\leq {10}^{18}\right),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
Source
BestCoder Round #71 (div.2)
每次减一个尽可能小的木棒--
代码:
#include<cstdio>
#define LL long long
void solve()
{
LL n;scanf("%lld",&n);
if (n<3)
{
printf("1\n");
return ;
}
LL shu[150];n-=3;
shu[0]=1;shu[1]=2;
for (int i=2;i;i++)
{
shu[i]=shu[i-1]+shu[i-2];
if (n<shu[i])
{
printf("%d\n",i);
return ;
}
n-=shu[i];
}
}
int main()
{
int t;scanf("%d",&t);
while (t--)
solve();
return 0;
}
Time Limit: 1000MS | Memory Limit: 65536KB | 64bit IO Format: %I64d & %I64u |
Description
Our lovely KK has a difficult mathematical problem:he has a N\left( 1\leq N\leq {10}^{18}\right) 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\left( 1\leq T\leq 10\right),
which indicates the number of test cases.
Each test case contains one line including a integer N\left( 1\leq N\leq {10}^{18}\right),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
BestCoder Round #71 (div.2)
每次减一个尽可能小的木棒--
代码:
#include<cstdio>
#define LL long long
void solve()
{
LL n;scanf("%lld",&n);
if (n<3)
{
printf("1\n");
return ;
}
LL shu[150];n-=3;
shu[0]=1;shu[1]=2;
for (int i=2;i;i++)
{
shu[i]=shu[i-1]+shu[i-2];
if (n<shu[i])
{
printf("%d\n",i);
return ;
}
n-=shu[i];
}
}
int main()
{
int t;scanf("%d",&t);
while (t--)
solve();
return 0;
}
相关文章推荐
- CentOS 7 源码安装MySQL 5.6.31
- HDU 2199 Can you solve this equation?(二分)
- POJ 2376 - Cleaning Shifts(最小区间覆盖)
- Linux笔记2
- 廖雪峰JS教程学习记录---字符串
- sort,qsort排序
- HTML5学习笔记(二)
- 搭建hibernate.cfg.xml时配合错误分享Referenced file contains errors
- 【Unity Shader】1.Unity的基本Shader框架学习(颜色,光照,材质)
- servlet
- (OK) VNC & RDP - 利用virtual box 自带remote display 实现windows 远程桌面连接ubuntu
- 关于rtsp客户端接收数据、解码、处理性能的有关问题
- leetcode 278. First Bad Version
- Linux 使用 ffmpeg 开发
- 页面跳转与重定向
- Ugly Number
- C++中的RAII机制
- BBC之时间之旅--加来道雄
- 负margin在页面布局中的应用
- Java异常处理-----java异常体系