#include <iostream>
#include <math.h>
#define M 12 // set original number of units in team A
int main()
{
std::cout << "Assume team A has more units than team B. " << std::endl;
std::cout << "The following 3 colomns give the original number of team B, the final number of team A, " <<
"and the final number according to the prediction from XD=love's formula." << std::endl;
for (int n = M; n != 0; --n) {
float m[n];
m[0] = M;
for(int i=0; i != n; ++i) {
m(i+1) = m(i) - ( n - i ) / m(i);
}
std::cout << n << '\t' << m[n] << '\t' << '\t' << sqrt ( M * M - n * n ) << std::endl;
}
return 0;
}
此程序同时计算了在一定A对数量的情况下,不同的B队初始数量造成的A队剩余结果。另外,还直接运用了大师的公式计算来比较两种算法的差异。
其中A队的初始数量假设为12个(在开头的#define M 中定义,可随意更改),程序运行结果如下:
(第一列是不同的B队初始值,第二列是相应的A队剩余数量,第三列是由大师的公式直接得到的结果)
Assume team A has more units than team B.
The following 3 colomns give the original number of team B, the final number of team A, and the final number according to the prediction from XD=love's formula.
12 0 0
11 4.24037 4.79583
10 6.15489 6.63325
9 7.52279 7.93725
8 8.58614 8.94427
7 9.44015 9.74679
6 10.1338 10.3923
5 10.6961 10.9087
4 11.1452 11.3137
3 11.4934 11.619
2 11.7488 11.8322
1 11.9167 11.9583
The following 3 colomns give the original number of team B, the final number of team A, and the final number according to the prediction from XD=love's formula.
12 7.86227 0
11 8.6775 4.79583
10 9.32456 6.63325
9 9.9314 7.93725
8 10.4127 8.94427
7 10.784 9.74679
6 11.1433 10.3923
5 11.4064 10.9087
4 11.6637 11.3137
3 11.8328 11.619
2 11.9167 11.8322
1 12 11.9583
可见在B队 也有12个情况下,A队打赢之后还可以剩下7个左右。
当然实际情况中双方攻防不会差距这么大,比较多的是落后一级,例如A的3攻3防 vs B的2攻2防,此时a1=25+9-5=29,a2=25+6-6=25
结果如下:
The following 3 colomns give the original number of team B, the final number of team A, and the final number according to the prediction from XD=love's formula.
12 5.16354 0
11 6.7186 4.79583
10 7.88375 6.63325
9 8.80226 7.93725
8 9.54011 8.94427
7 10.1338 9.74679
6 10.6961 10.3923
5 11.1452 10.9087
4 11.4934 11.3137
3 11.7488 11.619
2 11.9167 11.8322
1 12 11.9583
我看了一下wiki上对Lanchester's Square Law的解释,不过好像没有讲原因,所以有可能是数据拟合出来的经验公式。而且后面还有
In modern warfare, to take into account that to some extent both linear and the square apply often a factor of 1.5 is used.
那就不太符合星际的情况了。
这是兰切斯特平方率的实际应用,适用于远程兵种交锋,不过在公式中还要考虑武器质量,这个就复杂多了
兰切斯特法则:
假设某一次交手的时候我方投入的人数是 M 人,敌方 N 人。并假设我方平均每个人在单位时间内可以使敌方 p 人丧失战斗力,敌方平均每个人在单位时间内可以使我方 q 人丧失战斗力。
假定在 t 时刻,我方剩下的人数是 m(t) 人,敌方剩下 n(t) 人,那么在这个时刻,敌方被我方杀伤的人数必定是我方此时的总人数乘以我方单兵作战能力,即
$$\frac{{\rm d}n(t)}{{\rm d}t}=-pm(t),--(方程1)$$
$$\frac{{\rm d}m(t)}{{\rm d}t}=-qn(t).--(方程2)$$
$$n_0=N,m_0=M--(初值)$$
n = 1;//n为需要的数量的变量
float q = M;
while (q > 0)
{
q = M;
i = n;
while (q > 0 && i > 0)
{
q = q - i * StrToFloat(Edit1->Text) / (q * StrToFloat(Edit2->Text)); //参考m(i+1) = m - ( n - i ) / m得到
i = i - 1;
}
n = n + 1;
}
ShowMessage(n - 1);
以上代码在C++Builder 2007上测试通过。