hdu 5620 KK's Steel(推理)

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)

题意:

给你一个长度为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<iostream>
 3 #include<cstdio>
 4 #include<cstring>
 5 #include<cmath>
 6 #include<math.h>
 7 #include<algorithm>
 8 #include<queue>
 9 #include<set>
10 #include<bitset>
11 #include<map>
12 #include<vector>
13 #include<stdlib.h>
14 using namespace std;
15 #define ll long long
16 #define eps 1e-10
17 #define MOD 1000000007
18 #define N 1000000
19 #define inf 1e12
20 ll n;
21 ll f[N];
22 void init(){
23     f[1]=1;
24     f[2]=2;
25     for(ll i=3;i<N;i++){
26         f[i]=f[i-2]+f[i-1];
27     }
28 }
29 int main()
30 {
31     init();
32     int t;
33     scanf("%d",&t);
34     while(t--){
35         scanf("%I64d",&n);
36         ll sum=0;
37         ll i;
38         for(i=1;i<N;i++){
39             sum+=f[i];
40             if(sum>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 }

hdu 5620 KK's Steel(推理)

时间: 2024-08-07 00:18:06

hdu 5620 KK's Steel(推理)的相关文章

HDU 5620 KK&#39;s Steel

想了一下发现是斐波那契数列.....水题 #include <stdio.h> #include <algorithm> #include <string.h> #include <queue> #include <stack> #include <map> #include <vector> using namespace std; const int maxn=1000; long long n; long long

hdu 5621 KK&#39;s Point(数学,推理题)

题解: 在圆上点三个点时,除圆上三个交点外,圆内没有交点:在圆上点四个点时,除圆上四个交点外,圆内出现了一个交点,因此,在N个点中每四个点便可以在圆内产生一个交点,因此N个点在圆内形成的点的个数为CN4,总的交点数就是CN4+N 1 #pragma comment(linker, "/STACK:1024000000,1024000000") 2 #include<iostream> 3 #include<cstdio> 4 #include<cstrin

hdu 5623 KK&#39;s Number(dp)

问题描述 我们可爱的KK有一个有趣的数学游戏:这个游戏需要两个人,有N\left(1\leq N\leq 5*{10}^{4} \right)N(1≤N≤5∗10?4??)个数,每次KK都会先拿数.每次可以拿任意多个数,直到NN个数被拿完.每次获得的得分为取的数中的最小值,KK和对手的策略都是尽可能使得自己的得分减去对手的得分更大.在这样的情况下,最终KK的得分减去对手的得分会是多少? 输入描述 第一行一个数T\left( 1\leq T\leq 10\right)T(1≤T≤10),表示数据组

HDU 5624 KK&#39;s Reconstruction(最小生成树)

题目链接:点击打开链接 题意:n个城市, m条可以修建的路, 修每条路有一个费用, 要求修建路将n个城市全部联通,并且最大费用减去最小费用最小. 思路:枚举最小边, 然后重新求一遍最小生成树,复杂度m^2, 出的数据水了, 左边BC水过了.. 细节参见代码: #include<cstdio> #include<cstring> #include<algorithm> #include<iostream> #include<string> #inc

HDU 4923 Room and Moor(推理+栈维护)

HDU 4924 Room and Moor 题目链接 题意:给定一个01组成的a序列,要求一个b序列,b序列每个数值为[0, 1]之间的数,并且b序列为非递减序列,要求∑(ai?bi)2最小,求这个最小值 思路:推理,很容易看出,开头一段的0和末尾一段的1等于没有,然后中间每段类似111000这样1在前,0在后的序列,都可以列出一个公式,很容易推出选择的x为共同的一个值,为1的个数/(1的个数+0的个数)a,那么问题就变成要维护一个递增的x,利用一个栈去做维护,如果遇到一个位置递减了,那么就把

HDU 4925 Apple Tree(推理)

HDU 4925 Apple Tree 题目链接 题意:给一个m*n矩阵种树,每个位置可以选择种树或者施肥,如果种上去的位置就不能施肥,如果施肥则能让周围果树产量乘2,问最大收益 思路:推理得到肯定是果树和肥料交叉种好,类似国际象棋棋盘,黑的种,白的施肥,由于格子数不多,直接去枚举每个位置即可.如果题目格子数多的话,其实也可以推出公式一步得到答案 代码: #include <cstdio> #include <cstring> const int d[4][2] = {{0, 1}

HDU 5624 KK&#39;s Reconstruction

KK's Reconstruction Time Limit: 12000/6000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/Others)Total Submission(s): 360    Accepted Submission(s): 151 Problem Description Our lovely KK has a difficult Social problem.A big earthquake happened

BestCoder Round #71 (div.2) (hdu 5620 菲波那切数列变形)

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 s

HDU5620 KK&#39;s Steel(C++语言版)

问题链接:HDU5620 刚读到题,有点难解,没有头绪. 看了暗示才明白点,有点像菲波拉契数列,不过每一项求的是数列到该项之和.另外略有不同的是,第1项是1,第2项是2.也许是为了三个钢管围起来不能成为三角形的原因. 既然知道以上这些,那就先打表备查,这是为了节省计算时间,尽管有时候是多余的,但是多数程序都需要打表,那就打表吧. 这个C++版的采用顺序查找,逻辑就要简单一些.参见:HDU5620 KK's Steel(C语言版). 需要说明的一点是,菲波拉契序列的各项值增长是极快的,其和的增长就