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). OutputFor 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
3 4 5 6Sample Output
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;
}
水波.