题意:有一场比赛,两两之间对决,问其中两支队会在第几轮相遇。(他们都足够强的情况下)
解题思路:模拟即可。详见代码。
#include <iostream>
#include <algorithm>
#include <string.h>
#include <vector>
#include <memory.h>
#include <bitset>
#include <map>
#include <deque>
#include <math.h>
#include <stdio.h>
using namespace std;
using namespace std;
typedef long long int ll;
const int MAXN = 1005;
int team[300];//每一队的排名,设为1000代表被淘汰。
int main()
{
int n, a, b;
while (cin >> n >> a >> b)
{
for (int j = 1; j <= n; j++)
{
team[j] = j;
}
bool flag = 0;
for (int i = 1; i < 1000; i++)//模拟每一轮
{
for (int j = 1; j <= n / (1<<(i-1)); j += 2)
{
if ((team[j] == a && team[j + 1] == b) || (team[j] == b && team[j + 1] == a))//如果相遇
{
if (n / (1<<(i-1)) == 2)
{
cout << "Final!" << endl;
flag = 1;
break;
}
cout << i << endl;
flag = 1;
break;
}
if (team[j] == a)
team[j + 1] = 1000;
else if (team[j + 1] == a)
team[j] = 1000;
else if (team[j + 1] == b)
team[j] = 1000;
else if (team[j] == b)
team[j + 1] = 1000;
else
team[j] = 1000;
}
sort(team + 1, team + n + 1);//重新排序
if (flag)
break;
}
}
return 0;
}