【HDU - 5914】【Triangle】

版权声明:本人原创,未经许可,不得转载 https://blog.csdn.net/qq_42505741/article/details/82735328

题目:

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.

Input

The first line contains only one integer T (T≤20T≤20), which indicates the number of test cases. 

For each test case, there is only one line describing the given integer n (1≤n≤201≤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

3
4
5
6

Sample Output

Case #1: 1
Case #2: 1
Case #3: 2

题意:

问有n根木棒 从1-n,最少拿走几根,使他们不能构成三角形。、

解题思路:

刚上来手动计算了几组数据,之后发现是斐波那契的变形,是计算n-f[n]+1的值。因为数据给的很小 20 ,直接手动开数组存放就行。

ac代码:

#include<bits/stdc++.h>
using namespace std;

int prime[24]={0,0,0,0,1,1,2,3,3,4,5,6,7,7,8,9,10,11,12,13,14};

int main()
{
	int t;
	while(scanf("%d",&t)!=EOF)
	{
		int n;
		int Case=0;
		while(t--)
		{
			scanf("%d",&n);
			printf("Case #%d: ",++Case);
			printf("%d\n",prime[n]);
		}
	}
	return 0;
}

猜你喜欢

转载自blog.csdn.net/qq_42505741/article/details/82735328
今日推荐