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;
    }
  • 相关阅读:
    Sqlite && EF Code FIRST 终极解决方案 2019.5.17
    网卡 API 相关
    (依赖注入框架:Ninject ) 一 手写依赖注入
    Nlog 日志框架简单教程
    调试时候输出信息到输出窗口
    利用VS 性能探查器 解决代码性能不高问题
    Image 释放
    记一次数据丢失(电脑硬盘closed to down)的经历
    [极短]数字求和
    在博客园中使用pixijs
  • 原文地址:https://www.cnblogs.com/qscqesze/p/6169078.html
Copyright © 2011-2022 走看看