Today, I wrote the last article to end this series. We know a lot about it.AlgorithmThe steps for solving the problem are fixed, and the probability algorithm selects random values at each step,
In some fields, problems are usually less time-efficient than the optimal choice, which greatly improves the efficiency of the algorithm and reduces the complexity.
I. Thoughts
Here we will mainly talk about the "numerical probability algorithm". This algorithm is often used to solve the numerical calculation problem and can only obtain the approximate solution of the problem. The same problem is the same probability algorithm.
The possible results obtained after two solutions are very different, but it doesn't matter. This "Approximate Solution" approaches the solution of the problem as time increases.
Ii. Features
In real life, there are a lot of questions that we don't actually get the correct answer. We can only get the approximate solution, for example, "throwing a coin" to find the probability of positive upward, "throwing a dice" appears 1 point
Probability, for example, finding the value of "irrational π" and calculating "fixed points. In this case, it is better to use the probability algorithm to solve the problem.
Iii. Example
In the numerical probability, the most typical question is "computing definite points". Set f (x) = 1-x2 to calculate the definite point: I = 1000001 (1-x2) dx value.
Analysis: Step 1: plot the Coordinate Map of the function f (x) = 1-x2 in:
Step 2: If we randomly place a vertex into the rectangle, the probability of falling into the "shadow" area is
P projection point = s shadow/s square = 000001 (1-x2) dx/000001 (1) dx = 000001 (1-x2) dx,
So the problem evolved into: finding the probability that a random point falls into the shadow area is the approximate value of the fixed point 201701 (1-x2) dx.
For example, we add N points to a square. If M points fall into the shadow area, the probability P = M/N;
Last: UpCode
1 Using System;
2 Using System. Collections. Generic;
3 Using System. LINQ;
4 Using System. text;
5
6 Namespace Gailv
7 {
8 Public Class Program
9 {
10 Static Void Main (String [] ARGs)
11 {
12 While ( True )
13 {
14 Console. writeline ( " The projection probability of the shadow area is: " + Darts ( 10000 ));
15 }
16 }
17
18 Static Double Darts ( Int N)
19 {
20 Int Count = 0 ;
21
22 For (Int I = 0 ; I <n; I ++)
23 {
24 Double X = New Random (). Next ( 0 , 100 )/ 100.0 ;
25
26 Double Y = New Random (). Next ( 0 , 100 )/ 100.0 ;
27
28 If (Y <= 1 -Math. Pow (X, 2 ))
29 Count ++;
30 }
31 Return (Double ) Count/N;
32 }
33 }
34 }