QAZ likes to play League of Legends and watch league matches as well.
He thinks the double-elimination system of this year's league matches is not fair, so he invented a pro-double-elimination system.
Specifically, in his system:
- There are three teams competing with each other.
- Firstly, two teams are selected with equal probability and compete.
- In each round, the losing team temporarily leaves, and the winning team continues to play against the other of the three teams that did not participate in this round.
- When a team loses two round in total, the elimination competition ends.
- For the sake of simplicity, any two teams have a 50% chance of winning against each other.
- Now please find out the expected number of rounds in this elimination competition.
QAZ喜欢玩《英雄联盟》,也喜欢观看联赛。
他认为今年联赛的双淘汰制度不公平,于是发明了亲双淘汰制。
具体来说,在他的系统中:
有三个队在互相竞争。
首先,以相等的概率选出两支队伍进行竞争。
在每一轮比赛中,失败的队伍暂时离开,获胜的队伍继续与未参加这一轮比赛的三支队伍中的另一支进行比赛。
当一个队总共输掉两轮比赛时,淘汰赛结束。
为了简单起见,任何两支队伍都有50%的胜率。
现在请查看本次淘汰赛的预计参赛轮数。
题解:
模拟(队列记得清空):
#include <bits/stdc++.h>
using namespace std;
queue<int> q;
int main()
{
int t = 100000;
int ans = 0;
srand(time(NULL));
while (t--)
{
while (!q.empty())
q.pop();
q.push(2), q.push(1), q.push(0);
int a = 0, b = 0, c = 0;
int now = 0;
int s = 0;
while (1)
{
if (a == 2 || b == 2 || c == 2)
break;
now++;
float num, random;
random = rand() / double(RAND_MAX);
//printf("%f\n", random);
int one = q.front();
q.pop();
int two = q.front();
q.pop();
int lose;
if (random > 0.5)
{
q.push(one);
q.push(two);
lose = two;
s = s * 100 + (one)*10 + (two);
}
else
{
q.push(two);
q.push(one);
lose = one;
s = s * 100 + (two)*10 + (one);
}
if (lose == 0)
a++;
else if (lose == 1)
b++;
else if (lose == 2)
c++;
}
ans += now;
}
cout << ans;
return 0;
}
搜:
#include <bits/stdc++.h>
using namespace std;
double total = 0;
double now = 0;
int cnt[3];
void dfs(int step, int last, double p)
{
for (int i = 0; i < 3; ++i)
{
if (cnt[i] == 2)
{
now += p * step;
//cout << p << ' ' << step << ' ' << p * step << endl;
return;
}
}
for (int i = 0; i < 3; ++i)
{
if (i == last)
continue;
for (int j = i + 1; j < 3; ++j)
{
if (j == last)
continue;
++cnt[i];
dfs(step + 1, i, p / 2);
--cnt[i];
++cnt[j];
dfs(step + 1, j, p / 2);
--cnt[j];
}
}
}
int main()
{
dfs(0, -1, 1.0 / 3);
printf("%.1f", now);
return 0;
}