【CF#931.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?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
4 1 2Output
1Input
8 2 6Output
Final!Input
8 7 5Output
2Note
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.
題目大意:
? ? ?有2^n支球隊(但是輸入的不是這里的n,而是相當于n=2^n,即 輸入的n一定是2的整數次冪),兩兩之間對決,輸入a,b兩支喜歡的球隊(他們很強,永遠不會輸),問兩支隊會在第幾輪相遇,如果到總決賽就輸出final,否則輸出第幾輪。(他們都足夠強的情況下)
解題報告:
? ? ? 以l2^k支球隊那里為分界線,看a,b是否是在其兩側,如果在同側那說明不會在k輪后相遇(即還打不到k輪他倆就相遇了)
? ?那就k從log2(n)到1模擬就好了。(這里的n就是輸入的n)
AC代碼:
#include<bits/stdc++.h>using namespace std;int main() {int n,a,b,t; cin>>n>>a>>b;if(a>b) {//a<b t=a;a=b;b=t;}int cll = 1;int cl=n/2;for(cl = 0; cll!=n; cl++) {cll *=2;}cll = cl;while(n>0) {if(a<=(n/2) && b>(n/2)) {cl == cll ? printf("Final!\n") : printf("%d\n",cl) ;return 0 ;}if(b<= n/2) {n/=2;cl--;continue;} else {a-=n/2;b-=n/2; cl--;n=n/2;continue;}}printf("1\n");return 0 ; }?
總結
以上是生活随笔為你收集整理的【CF#931.B】World Cup (思维,模拟)的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【HDU - 5672】String(尺
- 下一篇: 2017招行信用卡排名:这几张卡值得你申