这不是程序问题。这样的测验有什么暗示吗? 我正在考虑关注两个随机的R1,R2,它们都在范围(0,1)内。并假设R2> R1 然后实现两个等式:
R1 + (1 - R2) > R2 - R1 // two sticks sum longer then the rest one
|R1 - (1 - R2)| < R2 - R1 // the difference of these two should be shorter the rest one
但我无法继续前进......
答案 0 :(得分:3)
将(r1,r2)视为单位平方中的一个点。
r2>允许单位平方的哪一部分; R1
哪部分可以形成三个可以形成三角形的长度?
答案 1 :(得分:2)
答案是1/4。 这是解释。
设x是最左边的棍子的长度,y是最右边的棍子的长度。 如果原始棒的长度为n,那么中间棒的长度为n-x-y。
x,y的可能值是:
在平面Oxy中,这相当于说点(x,y)位于具有顶点(0,0),(n,0),(0,n)的三角形内。
现在这三个数字(x,y,n-x-y)形成一个三角形,如果满足所有这三个数字:
再次在Oxy平面中,当点(x,y)位于具有顶点(0,n / 2),(n / 2,n / 2),(n / 2,0)的三角形内时,这些是满足的
这个三角形的面积是(0,0),(n,0),(0,n)三角形面积的四分之一,因为它是'中间'三角形(其顶点是中点)更大的一个。
这是一个简单的C#程序来验证答案:
Random r = new Random();
int count = 0, total = 0, tries = 1000000;
double x, y;
for (int i = 0; i < tries; i++)
{
x = r.NextDouble();
y = r.NextDouble();
if (x + y > 0.5 && x < 0.5 && y < 0.5) ++count;
if (x + y < 1.0) ++total;
}
Console.WriteLine((double)count / total);
答案 2 :(得分:0)
我刚刚制作了一个程序来验证它,我发现它是1/4:
class Program
{
static void Main(string[] args)
{
int nIsTriangle = 0;
Random ran = new Random(0);
int nTry = 1000000;
for (int i = 0; i < nTry; i++)
{
double r1 = ran.NextDouble();
double r2 = ran.NextDouble();
if (Check(r1, r2)) nIsTriangle++;
}
Console.WriteLine((double)nIsTriangle / (double)nTry);
Console.ReadKey();
}
static bool Check(double r1, double r2)
{
double first = Math.Min(r1, r2);
double second = Math.Abs(r1 - r2);
double third = 1 - Math.Max(r1, r2);
bool conditionA = (first + second) > third;
bool conditionB = Math.Abs(first - second) < third;
return conditionA && conditionB;
}
}