• 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;
    }
  • 相关阅读:
    全角 半角转换 .net
    [下载]微软Windows命令行PowerShell 2.0
    logstash收集java程序日志
    使用filebeat替代logstash收集日志
    Kibanna图形统计
    MySQL Blind Sql Injection
    超级后门泄露版
    HACKING WITH JAVASCRIPT
    Exploiting Common Vulnerabilities in PHP Applications
    3389安全记录批处理
  • 原文地址:https://www.cnblogs.com/qscqesze/p/6169078.html
Copyright © 2020-2023  润新知