HDU 5620 KK's Steel(思维题)
2016-04-25 18:18
253 查看
KK’s Steel
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 737 Accepted Submission(s): 345
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.
Source
BestCoder Round #71 (div.2)
题意:给出一个钢管,你可以把它拆分为任意个数,并且要满足一下要求。
应该满足的条件为:
1.这组数的任意两个数都不相等。
2.并且任意三个不能形成三角形。
问你可以分为多少个数
求出划分的个数。
首先从6开始推起,6可以划分为1,2,3。
7的话可以划分为1,2,4。
8的话可以分为1,2,5。
9的话可以分为1,2,6。
10的话可以分为2,3,5或者1,4,5。
11的话可以分为1,2,3,5。4个
相信到现在大家应该可以发现规律了,如果还没有发现的话,可以先看下代码。
下面是AC代码:
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others)
Total Submission(s): 737 Accepted Submission(s): 345
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.
Source
BestCoder Round #71 (div.2)
题意:给出一个钢管,你可以把它拆分为任意个数,并且要满足一下要求。
应该满足的条件为:
1.这组数的任意两个数都不相等。
2.并且任意三个不能形成三角形。
问你可以分为多少个数
求出划分的个数。
首先从6开始推起,6可以划分为1,2,3。
7的话可以划分为1,2,4。
8的话可以分为1,2,5。
9的话可以分为1,2,6。
10的话可以分为2,3,5或者1,4,5。
11的话可以分为1,2,3,5。4个
相信到现在大家应该可以发现规律了,如果还没有发现的话,可以先看下代码。
下面是AC代码:
#include<cstdio> #include<cstring> #include<algorithm> using namespace std; long long a[200]; long long b[200]; void init() { a[1]=1; a[2]=2; for(int i=3;i<=200;i++) { a[i]=a[i-1]+a[i-2]; } long long sum=0; for(int i=1;i<=200;i++) { sum+=a[i]; b[i]=sum; } } int main() { int t; init(); scanf("%d",&t); while(t--) { long long n; scanf("%lld",&n); int flag=0; for(int i=1;i<190;i++) { if(b[i]==n) { flag=i; break; } else if(b[i]>n) { flag=i-1; break; } } if(flag<3) { flag=0; } printf("%d\n",flag); } return 0; }
相关文章推荐
- STL学习_SGI空间配置器
- LBS(定位)的使用
- Java中Vector和ArrayList的区别
- redis sentinel(哨兵)模式
- Java多线程系列--“基础篇”03之 Thread中start()和run()的区别
- Android开发本地及网络Mp3音乐播放器(七)循环模式与专辑倒影
- Android开发本地及网络Mp3音乐播放器(七)循环模式与专辑倒影
- svn ignore 的用法(忽略文件及目录)
- UVA 10341 Solve It (二分)
- UIColor 使用起来的坑
- Android开发面试经——4.常见Android进阶笔试题(更新中...)
- char与varchar、nvarchar区别
- MySQL定时执行脚本(计划任务)命令实例
- mysql 重复数据只留一条
- Mysql常用命令详解
- 如何获取按键的字码符?
- Android app如何正确读写系统sys设备节点
- Linux计划任务,自动删除n天前的旧文件
- java实现冒泡排序,选择排序,插入排序算法详解
- 九.Shell基础