CCPC 2016 长春区域赛 D - Triangle(思维)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/hxxjxw/article/details/83963855

HDU - 5914

题目大意:

       有n根棒,长度分别为1,2,3......n,要求从中删掉一些棒,使得剩下的任意三根不能构成三角形,问最少删除几根

题解: 

     一看数据范围觉得应该是个水题。

    三根棒能构成三角形则较短的两条边之和>第三边,推了一番之后很神奇地能想到斐波那契数列。而20以内的斐波那契数列只有6项 1,2,3,5,8,13,也就是说,当遇到这几个数字长度的木棒要删掉,其他的留着就好了

#include <bits/stdc++.h>
#include<cstring>
using namespace std;
int main()
{
    //freopen("input.txt","r",stdin);
    int T;
    cin>>T;
    int n;
    int ca=1;
    while(T--)
    {
        cin>>n;
        cout<<"Case #"<<ca++<<": ";
        if(n<=3)
        {
            cout<<0<<endl;
        }
        else if(n<5)
        {
            cout<<(n-3)<<endl;
        }
        else if(n<8)
        {
            cout<<(n-4)<<endl;
        }
        else if(n<13)
        {
            cout<<n-5<<endl;
        }
        else
            cout<<(n-6)<<endl;
    }
    return 0;
}

猜你喜欢

转载自blog.csdn.net/hxxjxw/article/details/83963855
今日推荐