zoukankan      html  css  js  c++  java
  • Codeforces Round #468 (Div. 2, based on Technocup 2018 Final Round)B. World Cup

    The last stage of Football World Cup is played using the play-off system.

    There are n teams left in this stage, they are enumerated from 1 to n. Several rounds are held, in each round the remaining teams are sorted in the order of their ids, then the first in this order plays with the second, the third — with the fourth, the fifth — with the sixth, and so on. It is guaranteed that in each round there is even number of teams. The winner of each game advances to the next round, the loser is eliminated from the tournament, there are no draws. In the last round there is the only game with two remaining teams: the round is called the Final, the winner is called the champion, and the tournament is over.

    Arkady wants his two favorite teams to play in the Final. Unfortunately, the team ids are already determined, and it may happen that it is impossible for teams to meet in the Final, because they are to meet in some earlier stage, if they are strong enough. Determine, in which round the teams with ids a and b can meet.

    Input

    The only line contains three integers na and b (2 ≤ n ≤ 256, 1 ≤ a, b ≤ n) — the total number of teams, and the ids of the teams that Arkady is interested in.

    It is guaranteed that n is such that in each round an even number of team advance, and that a and b are not equal.

    Output

    In the only line print "Final!" (without quotes), if teams a and b can meet in the Final.

    Otherwise, print a single integer — the number of the round in which teams a and b can meet. The round are enumerated from 1.

    Examples
    input
    4 1 2
    output
    1
    input
    8 2 6
    output
    Final!
    input
    8 7 5
    output
    2

    题意:给定队伍数量以及需要查询的a队和b队,队伍之间两两比赛赢的队晋级,求在一直能赢的情况下他们会在第几轮相遇。

    区间为2的倍数,每增加一轮区间长度乘二,判断a和b是否都在当前区间内。
    #include <iostream>
    #include <cstdio>
    #include <cmath>
    #include <cstring>
    #include <algorithm>
    #include <string>
    #include <vector>
    #include <queue>
    #include <stack>
    #include <set>
    #include <map>
    #define INF 0x3f3f3f3f
    #define lowbit(x) (x&(-x))
    #define eps 0.00000001
    #define pn printf("
    ")
    using namespace std;
    typedef long long ll;
    
    int n, a, b;
    
    int main()
    {
        cin >> n >> a >> b;
        int st = 2, ans = 1, fl = 0;
        while(st < n)
        {
            for(int i=1;i<=n;i+=st)
                if(a >= i && a < i+st && b >= i && b < i+st)
                {
                    fl = 1; break;
                }
            if(fl) break;
            ans ++;
            st *= 2;
        }
        if(!fl) printf("Final!
    ");
        else printf("%d
    ",ans);
    }
  • 相关阅读:
    docker安装dvwa
    新版recon-ng安装模块
    docker多段构建nessus镜像
    docker安装Nessus
    docker快速安装openvas
    pyinstaller打包一些三方库后,报资源不存在
    python解决“failed to execute pyi_rth_pkgres”问题
    Proxmox6.2简单配置
    JavaScript全面学习(koa2.0)/MVC实现登录
    windows下react-native环境配置的那些坑
  • 原文地址:https://www.cnblogs.com/HazelNut/p/8621338.html
Copyright © 2011-2022 走看看