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.
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.
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.
4 1 2
1
8 2 6
Final!
8 7 5
2
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.
其实是暴力模拟!第一个for找pos1,第二个for找pos2,假如找到了a,b;则退出。没找到,要看a,b是不是其中之一,
假如是,保留a或b的数组为一,假如不是,去掉后面的,也就是数组改为0。这样循环,直到找到为止!flag是看第一个for
有没有找到pos1,假如有,变为j,下次从后面找,假如没有,就只是i++;题是简单的,就是循环要考虑仔细!
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cctype>
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
using namespace std;
typedef long long ll;
#define inf int(0x3f3f3f3f)
#define mod int(1e9+7)
#define pi acos(-1)
int k[300];
int main()
{
int n,a,b;
while(cin>>n)
{
for(int i=1;i<=n;i++)
k[i]=1;
cin>>a>>b;
if(a>b)
{
int t;
t=a;a=b;b=t;
}
int sum=0;
int pos1,pos2,i,j,flag;
while(1)
{
sum++;
for(i=1;i<=n;i++)
{
flag=0;
if(k[i]==1)
{
pos1=i;
for(j=i+1;j<=n;j++)
{
if(k[j]==1)
{
pos2=j;
if(pos1==a&&pos2==b) break;
if(pos1==a||pos1==b) k[pos2]=0;
else if(pos2==b||pos2==a) k[pos1]=0;
else k[pos2]=0;
break;
}
}
flag=1;
/*cout<<pos1<<" "<<pos2<<" "<<a<<" "<<b<<endl;*/
}
if(pos1==a&&pos2==b) break;
if(flag) i=j;
}
if(pos1==a&&pos2==b) break;
/*for(int w=1;w<=n;w++)
cout<<k[w]<<" ";
cout<<endl;*/
}
int s=0;
while(n!=1)
{
s++;
n=n/2;
}
if(sum==s) puts("Final!");
else cout<<sum<<endl;
}
return 0;
}