清华大佬耗费三个月吐血整理的几百G的资源,免费分享!....>>>
// 篮球对阵.cpp : 定义控制台应用程序的入口点。
// 本程序采用赛制为:共有9个班参赛,每轮通过抽签,两两对决,单场淘汰制,在进入决赛之前每一轮都会有一只轮空球队。
// 本程序每组对决时采用固定胜率,此胜率为程序作者初步估计各班水平给出的胜率,不能完全反映真实情况。
// 对决时根据胜率,选择随机数的方式确定胜负与否,每组对决取10次随机数,根据随机数所在的区域确定最终胜负关系,
// 对于随机数所在区域的解释:例如A班对B班获胜几率为60%,则取1-100中的随机数字,数字在1-60内则A班胜,数字在61-100内则B班胜。
// 如在两边获胜的区域各取到了5次,则程序再重新抽取10次随机数,直至这10次中两边区域取到的数字不相同为止。
// 本程序将会对整个的比赛流程模拟10次,程序将会在模拟期间输出每次抽签的结果以及最终的胜负关系,在10次模拟结束后,系统将会给出夺冠次数最多的球队,和我班(4班)在每轮被淘汰的次数。
// 本模拟程序仅供个人练习使用,并不代表真实的赛制和比赛结果,不成为可靠参考数据。
#include "stdafx.h"
#include "iostream"
#include "ctime"
#include "windows.h"
using namespace std;
int max2(int a, int b)
{
int x;
if (a <= b)
{
x = a;
a = b;
b = x;
}
return a;
}
int max9(int a, int b, int c, int d, int e, int f, int g, int h, int i)
{
a = max2(a, b);
b = max2(c, d);
c = max2(e, f);
d = max2(g, h);
e = i;
a = max2(a, b);
b = max2(c, d);
c = e;
a = max2(a, b);
b = c;
a = max2(a, b);
return a;
}
int whowin(int a, int b)
{
int x;
if (a >= b)
{
x = a;
a = b;
b = x;
}
srand(unsigned(time(0)));
int i, j, n, k = 0, l = 0;
if (a == 1 && (b == 2 || b == 6 || b == 9) || (a == 3 && (b == 6 || b == 9)) || (a == 4 && b == 6) || (a == 5 && b == 6))
n = 20;
else if ((a == 1 && b == 7) || (a == 3 && b == 7))
n = 25;
else if ((a == 1 && (b == 4 || b == 5)) || (a == 1 && (b == 3 || b == 8)) || (a == 2 && b == 6) || (a == 3 && (b == 4 || b == 5)) || (a == 3 && b == 8) || (a == 4 && b == 9) || (a == 5 && (b == 7 || b == 9)))
n = 30;
else if ((a == 4 && b == 7) || (a == 5 && b == 8))
n = 40;
else if ((a == 2 && (b == 7 || b == 9)) || (a == 4 && b == 8))
n = 50;
else if ((a == 6 && b == 9) || (a == 7 && b == 9))
n = 60;
else if ((a == 4 && b == 5) || (a == 6 && b == 7) || (a == 7 && b == 8))
n = 70;
else if ((a == 2 && b != 6 && b != 7 && b != 9) || (a == 6 && b == 8))
n = 80;
else
n = 30;
for (i = 1;i <= 10;i++)
{
j = rand() % 100 + 1;
if (0 < j&&j <= n)
k++;
else
l++;
if (k == l)
i = 1;
continue;
}
if (k > l)
return a;
else
return b;
}
int main()
{
int round;
int win1 = 0, win2 = 0, win3 = 0, win4 = 0, win5 = 0, win6 = 0, win7 = 0, win8 = 0, win9 = 0;
int ro1 = 0, ro2 = 0, ro3 = 0, ro4 = 0, nro = 0;
for (round = 1;round <= 10;round++)
{
int a, b, c, d, e, f, g, h, i;
int firstroundout = 0, secondroundout = 0, thirdroundout = 0, fourthroundout = 0, champion = 0;
srand(unsigned(time(0)));
cout << "第" << round << "次模拟结果" << endl;
int z[10] = { 0,1,2,3,4,5,6,7,8,9 };
a = rand() % 9 + 1;
z[a] = 0;
b = rand() % 9 + 1;
while (z[b] == 0)
b = rand() % 9 + 1;
z[b] = 0;
c = rand() % 9 + 1;
while (z[c] == 0)
c = rand() % 9 + 1;
z[c] = 0;
d = rand() % 9 + 1;
while (z[d] == 0)
d = rand() % 9 + 1;
z[d] = 0;
e = rand() % 9 + 1;
while (z[e] == 0)
e = rand() % 9 + 1;
z[e] = 0;
f = rand() % 9 + 1;
while (z[f] == 0)
f = rand() % 9 + 1;
z[f] = 0;
g = rand() % 9 + 1;
while (z[g] == 0)
g = rand() % 9 + 1;
z[g] = 0;
h = rand() % 9 + 1;
while (z[h] == 0)
h = rand() % 9 + 1;
z[h] = 0;
i = rand() % 9 + 1;
while (z[i] == 0)
i = rand() % 9 + 1;
cout << "第一轮对阵:" << endl;
cout << a << "班对阵" << b << "班" << endl;
cout << c << "班对阵" << d << "班" << endl;
cout << e << "班对阵" << f << "班" << endl;
cout << g << "班对阵" << h << "班" << endl;
cout << i << "班轮空" << endl;
a = whowin(a, b);
b = whowin(c, d);
c = whowin(e, f);
d = whowin(g, h);
e = i;
if (a != 4 && b != 4 && c != 4 && d != 4 && e != 4)
{
firstroundout++;
secondroundout--;
thirdroundout--;
fourthroundout--;
}
cout << "对阵结果:" << endl;
cout << a << "班获胜" << endl;
cout << b << "班获胜" << endl;
cout << c << "班获胜" << endl;
cout << d << "班获胜" << endl;
int a1, b1, c1, d1, e1;
int y[6] = { 0,a,b,c,d,e };
a1 = rand() % 5 + 1;
a = y[a1];
y[a1] = 0;
b1 = rand() % 5 + 1;
while (y[b1] == 0)
b1 = rand() % 5 + 1;
b = y[b1];
y[b1] = 0;
c1 = rand() % 5 + 1;
while (y[c1] == 0)
c1 = rand() % 5 + 1;
c = y[c1];
y[c1] = 0;
d1 = rand() % 5 + 1;
while (y[d1] == 0)
d1 = rand() % 5 + 1;
d = y[d1];
y[d1] = 0;
e1 = rand() % 5 + 1;
while (y[e1] == 0)
e1 = rand() % 5 + 1;
e = y[e1];
cout << "第二轮对阵:" << endl;
cout << a << "班对阵" << b << "班" << endl;
cout << c << "班对阵" << d << "班" << endl;
cout << e << "班轮空" << endl;
a = whowin(a, b);
b = whowin(c, d);
c = e;
if (a != 4 && b != 4 && c != 4)
{
secondroundout++;
thirdroundout--;
fourthroundout--;
}
cout << "对阵结果:" << endl;
cout << a << "班获胜" << endl;
cout << b << "班获胜" << endl;
int a2, b2, c2;
int x[4] = { 0,a,b,c };
a2 = rand() % 3 + 1;
a = x[a2];
x[a2] = 0;
b2 = rand() % 3 + 1;
while (x[b2] == 0)
b2 = rand() % 3 + 1;
b = x[b2];
x[b2] = 0;
c2 = rand() % 3 + 1;
while (x[c2] == 0)
c2 = rand() % 3 + 1;
c = x[c2];
cout << "第三轮对阵:" << endl;
cout << a << "班对阵" << b << "班" << endl;
cout << c << "班轮空" << endl;
a = whowin(a, b);
if (a != 4 && c != 4)
{
thirdroundout++;
fourthroundout--;
}
cout << "对阵结果:" << endl;
cout << a << "班获胜" << endl;
cout << "决赛对阵:" << endl;
cout << a << "对阵" << c << "班" << endl;
a = whowin(a, c);
if (a != 4)
fourthroundout++;
else
champion++;
cout << "对阵结果:" << endl;
cout << a << "班获胜" << endl;
cout << a << "班获得冠军" << endl;
if (secondroundout < 0)
secondroundout = 0;
if (thirdroundout < 0)
thirdroundout = 0;
if (fourthroundout < 0)
fourthroundout = 0;
if (a == 1)
win1++;
else if (a == 2)
win2++;
else if (a == 3)
win3++;
else if (a == 4)
win4++;
else if (a == 5)
win5++;
else if (a == 6)
win6++;
else if (a == 7)
win7++;
else if (a == 8)
win8++;
else
win9++;
ro1 += firstroundout;
ro2 += secondroundout;
ro3 += thirdroundout;
ro4 += fourthroundout;
nro += champion;
Sleep(1 * 1000);
}
int champ;
if (max9(win1, win2, win3, win4, win5, win6, win7, win8, win9) == win1)
champ = 1;
else if (max9(win1, win2, win3, win4, win5, win6, win7, win8, win9) == win2)
champ = 2;
else if (max9(win1, win2, win3, win4, win5, win6, win7, win8, win9) == win3)
champ = 3;
else if (max9(win1, win2, win3, win4, win5, win6, win7, win8, win9) == win4)
champ = 4;
else if (max9(win1, win2, win3, win4, win5, win6, win7, win8, win9) == win5)
champ = 5;
else if (max9(win1, win2, win3, win4, win5, win6, win7, win8, win9) == win6)
champ = 6;
else if (max9(win1, win2, win3, win4, win5, win6, win7, win8, win9) == win7)
champ = 7;
else if (max9(win1, win2, win3, win4, win5, win6, win7, win8, win9) == win8)
champ = 8;
else
champ = 9;
cout << "经过10次模拟后,模拟冠军次数最多的班级为:" << champ << "班" << endl;
cout << "四班各轮晋级次数:" << endl;
cout << "第一轮被淘汰:" << ro1 << "次" << endl;
cout << "第二轮被淘汰:" << ro2 << "次" << endl;
cout << "第三轮被淘汰:" << ro3 << "次" << endl;
cout << "获得亚军:" << ro4 << "次" << endl;
cout << "获得冠军:" << nro << "次" << endl;
system("pause");
return 0;
}