Mr. Frog has n sticks, whose lengths are 1,2, 3⋯⋯n
respectively. Wallice is a bad man, so he does not want Mr. Frog to form a triangle with three of the sticks here. He decides to steal some sticks! Output the minimal number of sticks he should steal so that Mr. Frog cannot form a triangle with
any three of the remaining sticks.
any three of the remaining sticks.
For each test case, there is only one line describing the given integer n (1≤n≤201≤n≤20).
3 4 5 6
Case #1: 1 Case #2: 1 Case #3: 2
刚开始看有点蒙,后来猜了几组数据,看着眼熟,于是搞出来了;
上代码;
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int T;
int n;
int vis[20];
int main()
{
scanf("%d", &T);
vis[1] = vis[0] = 1;
for(int i=2; i<=20; i++)
{
vis[i] = vis[i-1] + vis[i-2];//构建斐波那契
}
for(int w=1; w<=T; w++)
{
scanf("%d", &n);
printf("Case #%d: ",w);
for(int i=1; i<=20; i++)
{
if(vis[i] > n){cout << n-i+1 << endl;break;}
}
}
return 0;
}
水波.