KK ' s Steel
Time limit:2000/1000 MS (java/others) Memory limit:65536/65536 K (java/others)
Total submission (s): Accepted submission (s): 166
Problem Descriptionour Lovely KK has a difficult mathematical problem:he have an(1≤n≤ten) Meters Steel,he would cut it into steels as many as possible,and he doesn ' t want any of the them is the same length or any Three of them can form a triangle.
Inputthe first line of the input file contains an integerT(1≤t≤) , which indicates the number of test cases.
Each test case contains one line including a integer N(1≤n≤ten), indicating the length of the steel.
Outputfor each test case, output one line, a integer represent the maxiumum number of steels he can cut it into.
Sample Input16
Sample OUTPUT3
Hint1+2+3=6 but 1+2=3 they is all different and cannot make a triangle. Requirements: Give a long shape number n let you divide n into several parts, 1, any two part length cannot equal 2, any three points can not be composed of triangle analysis: Because the number in the Fibonacci sequence to meet this requirement, so from this aspect, as long as the number of a+b<=c can be satisfied, so we in the series 1 2 3 5 8 13 21st...... The number of the first and equal to the N output I if the first and greater than n output i-1
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <algorithm> #define MAX 100100#define INF 0x3f3f3f#define LL long longusing namespace std; LL fb[10010]; ll F[1001];void Biao () {ll i,j;fb[1]=1;fb[2]=2;for (i=3;i<120;i++) fb[i]=fb[i-1]+fb[i-2];f[1]=fb[1];for (i=2; i<120;i++) f[i]=f[i-1]+fb[i];} int main () {int t,i,j; LL N;biao (); scanf ("%d", &t), while (t--) {scanf ("%lld", &n), for (i=1;i<120;i++) {if (N==f[i]) {printf ("%d\n", i); break;} if (N<f[i]) {printf ("%d\n", i-1); break;}}} return 0;}
Bestcoder Round #71 (Div.2) (Hdu 5620)