zoukankan      html  css  js  c++  java
  • Codeforces Round #382 (Div. 2)C. Tennis Championship 动态规划

    C. Tennis Championship

    题目链接

    http://codeforces.com/contest/735/problem/C

    题面

    Famous Brazil city Rio de Janeiro holds a tennis tournament and Ostap Bender doesn't want to miss this event. There will be n players participating, and the tournament will follow knockout rules from the very first game. That means, that if someone loses a game he leaves the tournament immediately.

    Organizers are still arranging tournament grid (i.e. the order games will happen and who is going to play with whom) but they have already fixed one rule: two players can play against each other only if the number of games one of them has already played differs by no more than one from the number of games the other one has already played. Of course, both players had to win all their games in order to continue participating in the tournament.

    Tournament hasn't started yet so the audience is a bit bored. Ostap decided to find out what is the maximum number of games the winner of the tournament can take part in (assuming the rule above is used). However, it is unlikely he can deal with this problem without your help.

    输入

    The only line of the input contains a single integer n (2 ≤ n ≤ 1018) — the number of players to participate in the tournament.

    输出

    Print the maximum number of games in which the winner of the tournament can take part.

    样例输入

    2

    样例输出

    1

    题意

    有n个人参加比赛,输了就淘汰,赢了就留下来,最后留下来的是胜利者。

    每个人只会和胜利场次和自己绝对值不超过1的人比赛。

    问你最多比赛多少场

    题解

    dp[i]表示比赛i场最多需要多少个人。

    那么显然dp[i] = dp[i-1] + dp[i-2]

    其实就是fib数列,扫一遍就好了

    代码

    #include<bits/stdc++.h>
    using namespace std;
    long long n;
    long long ans = 0;
    int main()
    {
        scanf("%lld",&n);
        long long a=2,b=1,c;
        while(1){
            if(a>n)break;
            ans++;
            c=a;
            a=a+b;
            b=c;
        }
        cout<<ans<<endl;
    }
  • 相关阅读:
    2016012061 小学四则运算练习软件项目报告
    阅读《构建之法》的几点思考
    软件工程之我见
    作业五
    结对作业
    第4.17章读书笔记
    week_2 四则运算
    第1.2.16章读书笔记
    我与软件工程
    团队项目Alpha冲刺阶段之学习总结
  • 原文地址:https://www.cnblogs.com/qscqesze/p/6169078.html
Copyright © 2011-2022 走看看