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

    B. World Cup
    time limit per test
    1 second
    memory limit per test
    256 megabytes
    input
    standard input
    output
    standard output

    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 n, a 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
    Copy
    4 1 2
    Output
    1
    Input
    Copy
    8 2 6
    Output
    Final!
    Input
    Copy
    8 7 5
    Output
    2
    Note

    In the first example teams 1 and 2 meet in the first round.

    In the second example teams 2 and 6 can only meet in the third round, which is the Final, if they win all their opponents in earlier rounds.

    In the third example the teams with ids 7 and 5 can meet in the second round, if they win their opponents in the first round.

    直接模拟 每一轮a,b属于第几小组。

    每次分组一定是按2的幂(1,2一定第一轮第一组,1,2,3,4一定第二轮第一组,1-8一定第三轮第一组)依次分。

    代码如下:

    #include <cstdio>
    #include <iostream>
    #include <algorithm>
    using namespace std;
    typedef long long LL;
    int main()
    {
        int n,a,b,ans,numa,numb,cnt,flag=0;
        cin>>n>>a>>b;
        cnt=1;
        for(int i=2;i<=n;i*=2)
        {
           numa=a/i;
           if(a%i!=0)
             numa++;
            numb=b/i;
            if(b%i!=0)
             numb++;
             if(numa==numb)
              {
                if(i==n)
                flag=1;
                ans=cnt;
                break;
             }
             cnt++;
        }
        if(flag==1)cout<<"Final!"<<endl;
        else cout<<ans<<endl;
        return 0;
    }
  • 相关阅读:
    jQuery EasyUI dialog 居中最简单的办法
    Sql Server 查看存储过程最后修改时间
    MyEclipse格式化JSP代码,其中Javascript无法格式化的原因
    MyEclipse格式化JSP代码导致Java表达式<%= %>自动换行的解决办法
    重新格式化hadoop的namenode导致datanode无法启动的最简单解决办法
    端口映射
    你以为的Jquery选择器是什么样子的?
    JS&Jquery基础之窗口对象的关系总结
    JS&Jquery基础之对象和数组以及类型转换
    SQL Server关于AlwaysOn的理解
  • 原文地址:https://www.cnblogs.com/a249189046/p/8513460.html
Copyright © 2011-2022 走看看