The geometric Summary of High School probability is also called a question, but the output is really pitfall.
Question:
A rectangle consisting of n * m square with a side length of T. I threw a coin with a diameter of C on the rectangle and asked what is the probability of covering 1, 2, and 4 Rectangles?
Solution:
It is calculated that the center of the coin can be located in the area of the circle that covers 1, 2, and 3 rectangles. Then we can find the probability ~
The following code is used:
# Include <set> # include <map> # include <queue> # include <math. h> # include <vector> # include <string> # include <stdio. h> # include <string. h> # include <stdlib. h >#include <iostream> # include <algorithm> # define EPS 1e-6 # define PI ACOs (-1.0) # define INF 107374182 # define inf64 1152921504606846976 # define LC l, m, tr <1 # define RC m + 1, R, TR <1 | 1 # define iabs (x)> 0? (X):-(x) # define clear1 (A, X, size) memset (A, X, sizeof (A [0]) * (size )) # define clearall (A, x) memset (A, X, sizeof (A) # define memcopy1 (A, X, size) memcpy (A, X, sizeof (X [0]) * (size) # define memcopyall (A, x) memcpy (A, X, sizeof (x) # define max (x, y) (x)> (y ))? (X): (y) # define min (x, y) (x) <(y ))? (X): (y) using namespace STD; int main () {int T, case1 = 1; double n, m, T, C, ANS [4]; scanf ("% d", & T); While (t --) {scanf ("% lf", & N, & M, & T, & C); ans [0] = (t-C/2) * (t-C/2) * 4 + (t-c) * (t-C/2) * (2 * m + 2 * n-8) + (t-c) * (n-2) * (m-2 ); // when a square is covered, the circle center of the coin can be in the location ans [2] = (C * C-Pi * (C/2) * (C/2) * (n-1) * (m-1); ans [3] = pI * (C/2) * (C/2) * (n-1) * m-1 ); ans [1] = N * m * T * t-ans [0]-ans [2]-ans [3]; printf ("case % d: \ n ", case1 ++); printf ("probability of covering 1 tile = %. 4f % \ n ", ANS [0] * 100.0/(n * m * T * t); For (INT I = 1; I <4; I ++) {printf ("probability of covering % d tiles = %. 4f % \ n ", I + 1, ANS [I] * 100.0/(n * m * T * t);} puts ("");} return 0 ;}