Triangle HDU

来源:互联网 发布:直播狗网络电视apk 编辑:程序博客网 时间:2024/06/10 14:32

Mr. Frog has n sticks, whose lengths are 1,2, 3n 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.
Input
The first line contains only one integer T (T20T≤20), which indicates the number of test cases. 

For each test case, there is only one line describing the given integer n (1n201≤n≤20).
Output
For each test case, output one line “Case #x: y”, where x is the case number (starting from 1), y is the minimal number of sticks Wallice should steal.
Sample Input
3456
Sample Output
Case #1: 1Case #2: 1Case #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;}




水波.



原创粉丝点击