Codeforces Round #468 B. World Cup

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 ≤ 2561 ≤ 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

题意:有n支球队,从1-n编号,规定每一轮比赛:排在第一个的和第二个比,排在第三个的和第四个比,以此类推,

例如有8支球队,假设胜出方任意:第一轮 12  34  56  78    第二轮 14  57    第三轮(Final)1 5。

现在给你两个球队编号ab,保证这两个球队每轮必胜,问你这两个球队能否在Final场中见面,是的话输出Final,否则就输出见面的那一场。

思路:超水的题...自己想太多了,以为可以找规律,试了半天发现不行,其实直接模拟就odk了

代码如下:

#include<cstdio>
#include<iostream>
#include<cstdlib>
using namespace std;
int main()
{
    int n,a,b;
    while(scanf("%d %d %d",&n,&a,&b))
    {
        int flag=0;
        int r=0;
        int p=0;
        int team[300];
        for(int i=1;i<=n;i++)
        {
            team[i]=i;
        }
        while(1)
        {
            r++;
            for(int i=1;i<=n;i=i+2)
            {
                if(team[i]==a&&team[i+1]==b)
                {
                    flag=1;
                    break;
                }
                else if(team[i]==a||team[i+1]==a)
                {
                    team[p]=a;
                    p++;
                }
                else if(team[i]==b||team[i+1]==b)
                {
                    team[p]=b;
                    p++;
                }
                else
                {
                    team[p]=i;
                    p++;
                }
            }
            n=n/2;
            if(flag==1)
            {
                break;
            }
        }
        if(n==2)printf("Final!\n");
        else printf("%d\n",r);
    }
}

猜你喜欢

转载自blog.csdn.net/acm513828825/article/details/79486958
今日推荐