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.
题意:给定n,a,b. 一共n个队伍,问A,B是否能在总决赛见面,如果可以输出Final! ;否则输出在第几轮比赛见. 比赛队伍有规定,连续的两个比赛
思路:STL,vector模拟
#include <bits/stdc++.h>
#define MOD 10000
#define INF 0x3f3f3f3f
#define bug cout << "bug" << endl
#pragma comment(linker, "/STACK:102400000,102400000")
using namespace std;
typedef long long ll;
const int MAX_N=3;
int n,m;
vector <int> ans;
map<int,int> mp;
void init(){
int x=1;
int cnt=0;
while(x<300){
x*=2;
cnt++;
mp[x]=cnt;
}
}
int main(void){
init();
int n,a,b,round=0;
cin >> n>>a>>b;
if(a>b) swap(a,b);
for(int i=0;i<=n;i++) ans.push_back(i);
while(ans.size()){
round++;
int index2=ans.size()-1;
int index1=index2-1;
// for(int i=1;i<ans.size();i++)
// printf("%d ",ans[i]);
// puts("");
while(ans[index2]){
if(ans[index1]==a&&ans[index2]==b){
if(round==mp[n]) cout <<"Final!"<<endl;
else cout <<round << endl;
return 0;
}
else if(ans[index1]==a || ans[index1]==b){
ans.erase(ans.begin()+index2);
}
else if(ans[index2]==a || ans[index2]==b){
ans.erase(ans.begin()+index1);
}
else ans.erase(ans.begin()+index1);
index2-=2,index1-=2;
}
}
}
/*
*/